def test_right_macro(self):
        # fixes #8016
        class MyField:
            __name__ = 'the field'
            required = True
            default = u'the value'
            missing_value = None
            title = ""
            description = ""

        # Let's add a custom editor using our own widget html:
        from zope.pagetemplate.pagetemplatefile import PageTemplate
        template = PageTemplate()
        template.pt_edit(BODY, 'text/html')

        self.skins.custom.cool_editor_wysiwyg_support = template

        # The wysiwyg widget depends on the used editor.
        # Let's change it to `cool_editor`.
        pm = self.pm
        member = pm.getAuthenticatedMember()
        member.setMemberProperties({'wysiwyg_editor': 'cool_editor'})

        w = WYSIWYGWidget(MyField(), self.request)
        # The test is partially that this call does not give an error:
        html = w()
        # This is true for standard Plone as well:
        self.assertIn(
            '<textarea name="field.the field" rows="25" id="field.the field">'
            'the value</textarea>', html)
        # Only our cool editor has this:
        self.assertIn('Cool Editor Box', html)
Example #2
0
    def test_right_macro(self):
        # fixes #8016
        class MyField:
            __name__ = 'the field'
            required = True
            default = u'the value'
            missing_value = None
            title = ""
            description = ""

        # Let's add a custom editor using our own widget html:
        from zope.pagetemplate.pagetemplatefile import PageTemplate
        template = PageTemplate()
        template.pt_edit(BODY, 'text/html')
        site = getSite()
        site.portal_skins.custom.cool_editor_wysiwyg_support = template

        # The wysiwyg widget depends on the used editor.
        # Let's change it to `cool_editor`.
        pm = getToolByName(self.portal, 'portal_membership')
        member = pm.getAuthenticatedMember()
        member.setMemberProperties({'wysiwyg_editor': 'cool_editor'})

        w = WYSIWYGWidget(MyField(), TestRequest())
        # The test is partially that this call does not give an error:
        html = w()
        # This is true for standard Plone as well:
        self.assertTrue(
            '<textarea name="field.the field" rows="25" id="field.the field">'
            'the value</textarea>' in html)
        # Only our cool editor has this:
        self.assertTrue('Cool Editor Box' in html)
Example #3
0
    def render(self, soup, headings, pub_date, mod_date):
        try:
            settings = getUtility(IRegistry).forInterface(ISettings)
        except BaseException:
            settings = None

        # XXX: This seems very complicated and brittle!
        persistent = queryUtility(IResourceDirectory, name="persistent")
        if persistent is not None:
            try:
                templates = persistent[RESOURCE_PATH]
                source = templates[settings.template.decode('utf-8')]
            except NotFound:
                try:
                    name = "++%s++%s" % tuple(RESOURCE_PATH.split('/')[:2])
                    templates = getUtility(IResourceDirectory, name=name)
                    source = templates[settings.template]
                except NotFound:
                    raise InternalError(
                        "Template not found: %r." % settings.template
                    )


        try:
            body = source.lastModifiedTimestamp
        except AttributeError:
            body = str(source)

        cache_key = hash((source, body))
        template, cached_key = getattr(
            self.context, "_v_render_template", None
        ) or (None, cache_key)

        if template is None or cached_key != cache_key:
            try:
                path = source.path
            except AttributeError:
                template = PageTemplate()
                template.pt_edit(str(source), 'text/xml')
            else:
                template = PageTemplateFile(path)

            logger.info("compiling template %r (with class %r)" % (
                settings.template, template.__class__.__name__,
            ))

            # Always use the Zope 2 expression engine.
            template.pt_getEngine = lambda: self.engine

            # Pass options directly into the template namespace.
            template.pt_getContext = lambda args=(), options=None, **_: options

            # We need to cook the template again to make sure the
            # above settings are applied (double work!)
            template._cook()

            # Cache template on context.
            self.context._v_render_template = (template, cache_key)

        namespace = dict(
            context=aq_inner(self.context),
            request=self.request,
            macros=template.macros,
            soup=soup,
            headings=headings,
            inline=LoadBase64(templates),
            publication_date=pub_date,
            modification_date=mod_date,
        )

        namespace.update(self.namespace)
        html = template(**namespace)

        soup = BeautifulSoup(html)
        portal = self.context.portal_url.getPortalObject()
        portal_url = portal.absolute_url()

        # Write out external links.
        for link in soup.findAll("a"):
            self.transformLink(portal_url, link)

        return unicode(soup)
Example #4
0
 def _zope(body):
     from zope.pagetemplate.pagetemplatefile import PageTemplate
     template = PageTemplate()
     template.pt_edit(body, 'text/xhtml')
     return template
 def _zope(body):
     from zope.pagetemplate.pagetemplatefile import PageTemplate
     template = PageTemplate()
     template.pt_edit(body, 'text/xhtml')
     return template