当前位置: 首页>>代码示例>>Python>>正文


Python ZopePageTemplate.pt_render方法代码示例

本文整理汇总了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)
开发者ID:zmijunkie,项目名称:Products.CMFPlone,代码行数:61,代码来源:test_safe_formatter.py

示例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>&lt;application at &gt;</p>')
开发者ID:zopefoundation,项目名称:Zope,代码行数:10,代码来源:test_safe_formatter.py

示例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>&lt;plonesite at plone&gt;</p>')
开发者ID:zmijunkie,项目名称:Products.CMFPlone,代码行数:10,代码来源:test_safe_formatter.py

示例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>&lt;plonesite at plone&gt;</p>')
开发者ID:zmijunkie,项目名称:Products.CMFPlone,代码行数:10,代码来源:test_safe_formatter.py

示例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: &lt;Folder at test_folder_1_&gt;</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))
开发者ID:zopefoundation,项目名称:Zope,代码行数:15,代码来源:test_safe_formatter.py

示例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))
开发者ID:zopefoundation,项目名称:Zope,代码行数:17,代码来源:test_safe_formatter.py

示例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))
开发者ID:zopefoundation,项目名称:Zope,代码行数:17,代码来源:test_safe_formatter.py

示例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 &lt;PloneSite at plone&gt; is Plone site</p>')
开发者ID:zmijunkie,项目名称:Products.CMFPlone,代码行数:9,代码来源:test_safe_formatter.py

示例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
开发者ID:hvelarde,项目名称:collective.easyform,代码行数:62,代码来源:actions.py

示例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 &lt;Application at &gt; is Zope</p>')
开发者ID:zopefoundation,项目名称:Zope,代码行数:9,代码来源:test_safe_formatter.py

示例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
开发者ID:MarkTang,项目名称:erp5,代码行数:28,代码来源:PDFTemplate.py

示例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
开发者ID:smetsjp,项目名称:erp5,代码行数:30,代码来源:PDFTemplate.py

示例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)
开发者ID:zopefoundation,项目名称:Zope,代码行数:19,代码来源:test_safe_formatter.py

示例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: &lt;Document at secret&gt;</p>')
     logout()
     self.assertRaises(Unauthorized, pt.pt_render)
开发者ID:zmijunkie,项目名称:Products.CMFPlone,代码行数:13,代码来源:test_safe_formatter.py

示例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: &lt;Document at secret&gt;</p>')
     logout()
     self.assertRaises(Unauthorized, pt.pt_render)
开发者ID:zmijunkie,项目名称:Products.CMFPlone,代码行数:14,代码来源:test_safe_formatter.py


注:本文中的Products.PageTemplates.ZopePageTemplate.ZopePageTemplate.pt_render方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。