本文整理汇总了Python中Products.PageTemplates.ZopePageTemplate.ZopePageTemplate.pt_render方法的典型用法代码示例。如果您正苦于以下问题:Python ZopePageTemplate.pt_render方法的具体用法?Python ZopePageTemplate.pt_render怎么用?Python ZopePageTemplate.pt_render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products.PageTemplates.ZopePageTemplate.ZopePageTemplate
的用法示例。
在下文中一共展示了ZopePageTemplate.pt_render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_access_to_private_content_not_allowed_via_rich_text
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def test_access_to_private_content_not_allowed_via_rich_text(self):
try:
from plone.app.textfield.value import RichTextValue
except ImportError:
return
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
foobar = create_private_document(self.portal, 'foobar')
login(self.portal, TEST_USER_NAME)
foobar.text = RichTextValue(u'Secret.', 'text/plain', 'text/html')
self.assertEqual(
self.portal.portal_workflow.getInfoFor(foobar, 'review_state'),
'private')
# Check that guarded_getattr is happy for the current user.
self.assertEqual(guarded_getattr(self.portal, 'foobar'), foobar)
self.assertEqual(
guarded_getattr(self.portal.foobar, 'text'), foobar.text)
# Access to text.output may be more restricted than access to the
# text object itself, but this makes no sense, so we switch that
# off in this test.
# self.assertRaises(
# Unauthorized, guarded_getattr, self.portal.foobar.text, 'output')
self.portal.foobar.text.__allow_access_to_unprotected_subobjects__ = 1
self.assertEqual(
guarded_getattr(self.portal.foobar.text, 'output'),
'<p>Secret.</p>')
TEMPLATE = '<p tal:content="structure python:%s" />'
pt = ZopePageTemplate(
'mytemplate', TEMPLATE %
"'access {0.foobar.text.output}'.format(context)")
hack_pt(pt, context=self.portal)
self.assertEqual(pt.pt_render(), '<p>access <p>Secret.</p></p>')
# Check the same for anonymous.
logout()
self.assertRaises(
Unauthorized, guarded_getattr, self.portal, 'foobar')
self.assertRaises(
Unauthorized, guarded_getattr, self.portal.foobar, 'text')
# *If* somehow anonymous can access the text, then we have allowed
# access to the output as well.
self.assertEqual(
guarded_getattr(self.portal.foobar.text, 'output'),
'<p>Secret.</p>')
# But for the template anonymous would need access to everything,
# which rightly fails.
self.assertRaises(Unauthorized, pt.pt_render)
# Test the simpler access without str.format for the current user.
login(self.portal, TEST_USER_NAME)
pt = ZopePageTemplate(
'mytemplate', TEMPLATE %
"context.foobar.text.output")
hack_pt(pt, context=self.portal)
self.assertEqual(pt.pt_render(), '<p><p>Secret.</p></p>')
# and for anonymous
logout()
self.assertRaises(Unauthorized, pt.pt_render)
示例2: test_cook_zope2_page_templates_good_unicode
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def test_cook_zope2_page_templates_good_unicode(self):
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
pt = ZopePageTemplate('mytemplate', GOOD_UNICODE)
hack_pt(pt)
self.assertEqual(pt.pt_render().strip(), '<p>none</p>')
hack_pt(pt, self.app)
self.assertEqual(
pt.pt_render().strip(), '<p><application at ></p>')
示例3: test_cook_zope2_page_templates_good_unicode
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def test_cook_zope2_page_templates_good_unicode(self):
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
pt = ZopePageTemplate('mytemplate', unicode(GOOD_UNICODE))
hack_pt(pt)
self.assertEqual(pt.pt_render().strip(), '<p>none</p>')
hack_pt(pt, self.portal)
self.assertEqual(
pt.pt_render().strip(), '<p><plonesite at plone></p>')
示例4: test_cook_zope2_page_templates_good_str
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def test_cook_zope2_page_templates_good_str(self):
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
pt = ZopePageTemplate('mytemplate', GOOD_STR)
hack_pt(pt)
self.assertEqual(pt.pt_render().strip(), '<p>none</p>')
hack_pt(pt, context=self.portal)
self.assertEqual(
pt.pt_render().strip(), '<p><plonesite at plone></p>')
示例5: test_cook_zope2_page_templates_bad_key_unicode
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def test_cook_zope2_page_templates_bad_key_unicode(self):
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
pt = ZopePageTemplate('mytemplate', BAD_KEY_UNICODE)
hack_pt(pt, self.app)
self.assertEqual(
pt.pt_render(),
'<p>access by key: <Folder at test_folder_1_></p>')
self.app.test_folder_1_.__roles__ = ['Manager']
with self.assertRaises(Unauthorized) as err:
pt.pt_render()
self.assertEqual(
"You are not allowed to access 'test_folder_1_' in this context",
str(err.exception))
示例6: test_cook_zope2_page_templates_bad_attr_unicode
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def test_cook_zope2_page_templates_bad_attr_unicode(self):
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
pt = ZopePageTemplate('mytemplate', BAD_ATTR_UNICODE)
hack_pt(pt)
with self.assertRaises(Unauthorized) as err:
pt.pt_render()
self.assertEqual(
"You are not allowed to access '__class__' in this context",
str(err.exception))
hack_pt(pt, context=self.app)
with self.assertRaises(Unauthorized) as err:
pt.pt_render()
self.assertEqual(
"You are not allowed to access '__class__' in this context",
str(err.exception))
示例7: test_access_to_private_content_not_allowed_via_any_attribute
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def test_access_to_private_content_not_allowed_via_any_attribute(self):
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
# If access to _delObject would be allowed, it would still only say
# something like 'bound method _delObject', without actually deleting
# anything, because methods are not executed in str.format, but there
# may be @properties that give an attacker secret info.
pt = ZopePageTemplate(
'mytemplate',
"""<p tal:content="python:'{0._delObject}'.format(context)" />""")
hack_pt(pt, context=self.app)
with self.assertRaises(Unauthorized) as err:
pt.pt_render()
self.assertEqual(
"You are not allowed to access '_delObject' in this context",
str(err.exception))
示例8: test_cook_zope2_page_templates_good_format_attr_str
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def test_cook_zope2_page_templates_good_format_attr_str(self):
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
pt = ZopePageTemplate('mytemplate', GOOD_FORMAT_ATTR_STR)
hack_pt(pt, self.portal)
self.assertEqual(
pt.pt_render().strip(),
'<p>title of <PloneSite at plone> is Plone site</p>')
示例9: get_mail_body
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def get_mail_body(self, fields, request, context):
"""Returns the mail-body with footer.
"""
schema = get_fields(context)
all_fields = [f for f in fields
# TODO
# if not (f.isLabel() or f.isFileField()) and not (getattr(self,
# 'showAll', True) and f.getServerSide())]
if not (INamedFile.providedBy(fields[f])) and not (getattr(self, 'showAll', True) and IFieldExtender(schema[f]).serverSide)
]
# which fields should we show?
if getattr(self, 'showAll', True):
live_fields = all_fields
else:
live_fields = [
f for f in all_fields if f in getattr(self, 'showFields', ())]
if not getattr(self, 'includeEmpties', True):
all_fields = live_fields
live_fields = [f for f in all_fields if fields[f]]
for f in all_fields:
value = fields[f]
if value:
live_fields.append(f)
#bare_fields = [schema[f] for f in live_fields]
bare_fields = dict([(f, fields[f]) for f in live_fields])
bodyfield = self.body_pt
# pass both the bare_fields (fgFields only) and full fields.
# bare_fields for compatability with older templates,
# full fields to enable access to htmlValue
replacer = DollarVarReplacer(fields).sub
extra = {
'data': bare_fields,
'fields': dict([(i, j.title) for i, j in getFieldsInOrder(schema)]),
'mailer': self,
'body_pre': self.body_pre and replacer(self.body_pre),
'body_post': self.body_post and replacer(self.body_post),
'body_footer': self.body_footer and replacer(self.body_footer),
}
template = ZopePageTemplate(self.__name__)
template.write(bodyfield)
template = template.__of__(context)
body = template.pt_render(extra_context=extra)
# if isinstance(body, unicode):
#body = body.encode("utf-8")
#keyid = getattr(self, 'gpg_keyid', None)
#encryption = gpg and keyid
# if encryption:
#bodygpg = gpg.encrypt(body, keyid)
# if bodygpg.strip():
#body = bodygpg
return body
示例10: test_cook_zope2_page_templates_good_format_attr_unicode
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def test_cook_zope2_page_templates_good_format_attr_unicode(self):
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
pt = ZopePageTemplate('mytemplate', GOOD_FORMAT_ATTR_UNICODE)
hack_pt(pt, self.app)
self.assertEqual(
pt.pt_render().strip(),
'<p>title of <Application at > is Zope</p>')
示例11: pt_render
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def pt_render(self, source=0, extra_context={}):
doc_xml = ZopePageTemplate.pt_render(self, source=source, extra_context=extra_context)
# Unmarshall arguments to __call__ API
args = extra_context.get('options', [])
kwargs = extra_context.copy()
if kwargs.has_key('options'): del kwargs['options']
if kwargs.has_key('context'): del kwargs['context']
batch_mode = extra_context.get('batch_mode', 0)
request = extra_context.get('REQUEST', None)
if not request:
request = get_request()
if request.get('debug',0):
return doc_xml
report_tool = getToolByName(self, 'portal_report')
pdf = report_tool.renderPDF(self.pdf_stylesheet, doc_xml, context=self.pt_getContext()['here'], *args, **kwargs)
if request and not batch_mode:
request.RESPONSE.setHeader('Content-Type','application/pdf')
request.RESPONSE.setHeader('Content-Length',len(pdf))
request.RESPONSE.setHeader('Content-Disposition','inline;filename=%s.pdf' % self.title_or_id())
return pdf
示例12: pt_render
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def pt_render(self, source=0, extra_context={}):
doc_xml = ZopePageTemplate.pt_render(self, source=source, extra_context=extra_context)
# Unmarshall arguments to __call__ API
args = extra_context.get("options", [])
kwargs = extra_context.copy()
if kwargs.has_key("options"):
del kwargs["options"]
if kwargs.has_key("context"):
del kwargs["context"]
batch_mode = extra_context.get("batch_mode", 0)
request = extra_context.get("REQUEST", None)
if not request:
request = get_request()
if request.get("debug", 0):
return doc_xml
report_tool = getToolByName(self, "portal_report")
pdf = report_tool.renderPDF(self.pdf_stylesheet, doc_xml, context=self.pt_getContext()["here"], *args, **kwargs)
if request and not batch_mode:
request.RESPONSE.setHeader("Content-Type", "application/pdf")
request.RESPONSE.setHeader("Content-Length", len(pdf))
request.RESPONSE.setHeader("Content-Disposition", "inline;filename=%s.pdf" % self.title_or_id())
return pdf
示例13: assert_is_checked_via_security_manager
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def assert_is_checked_via_security_manager(self, pt_content):
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
from AccessControl.SecurityManager import setSecurityPolicy
from AccessControl.SecurityManagement import noSecurityManager
from AccessControl.SecurityManagement import getSecurityManager
pt = ZopePageTemplate('mytemplate', pt_content)
noSecurityManager()
old_security_policy = setSecurityPolicy(UnauthorizedSecurityPolicy())
getSecurityManager()
try:
hack_pt(pt, context=self.app)
with self.assertRaises(Unauthorized) as err:
pt.pt_render()
self.assertEqual("Nothing is allowed!", str(err.exception))
finally:
setSecurityPolicy(old_security_policy)
示例14: test_cook_zope2_page_templates_bad_key_unicode
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def test_cook_zope2_page_templates_bad_key_unicode(self):
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
pt = ZopePageTemplate('mytemplate', BAD_KEY_UNICODE)
hack_pt(pt, self.portal)
create_private_document(self.portal, 'secret')
login(self.portal, TEST_USER_NAME)
self.assertEqual(
pt.pt_render().replace('ATDocument', 'Document'),
'<p>access by key: <Document at secret></p>')
logout()
self.assertRaises(Unauthorized, pt.pt_render)
示例15: test_cook_zope2_page_templates_bad_item_str
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_render [as 别名]
def test_cook_zope2_page_templates_bad_item_str(self):
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
secret = create_private_document(self.portal, 'secret')
login(self.portal, TEST_USER_NAME)
self.portal.testlist = [secret]
pt = ZopePageTemplate('mytemplate', BAD_ITEM_STR)
hack_pt(pt, self.portal.testlist)
self.assertEqual(
pt.pt_render().replace('ATDocument', 'Document'),
'<p>access by item: <Document at secret></p>')
logout()
self.assertRaises(Unauthorized, pt.pt_render)