Esempio n. 1
0
def render_macro(context, template_name, macro, **kw):
    """ Render just a part of the macro """
    from Products.PageTemplates.PageTemplate import PageTemplate
    template = PageTemplate()
    template.write("<metal:block\
        use-macro=\"python: here.getFormsTool().getForm('%s').macros['%s']\"\
        />" % (template_name, macro))
    kw.update({'here': context, 'context': context})
    return template.pt_render(extra_context=kw)
Esempio n. 2
0
def profile_zpt(fn, count, profiler):
    from Products.PageTemplates.PageTemplate import PageTemplate
    pt = PageTemplate()
    pt.write(open(fn).read())
    for i in range(4):
        pt.pt_render(extra_context=data)
    r = [None] * count
    for i in r:
        profiler.runcall(pt.pt_render, 0, data)
    def test_image_captioning_uses_kupu_captioned_image_template(self):
        # for backwards compatibility, a custom captioned image template
        # can be supplied with a name of 'kupu_captioned_image'
        from Products.PageTemplates.PageTemplate import PageTemplate
        template = PageTemplate()
        template.write('foo')
        self.portal._setOb('kupu_captioned_image', template)

        text_in = """<img class="captioned" src="image.jpg"/>"""
        self._assertTransformsTo(text_in, 'foo')
Esempio n. 4
0
    def __call__(self, value, *args, **kwargs):
        if not isinstance(value, PageTemplate):
            pt = PageTemplate()
            pt.write(value)
            value = pt

        errors = value.pt_errors()
        if errors:
            return '<br/>\n'.join(errors)
        else:
            return 1
    class TranslationsToolWrapperNaayaTest(NaayaTestCase):

        def setUp(self):
            # step 1: fix request patch, for Localizer
            try:
                # needed for some Localizer Patching:
                from thread import get_ident
                from Products.Localizer.patches import _requests
                _requests[get_ident()] = self.portal.REQUEST
            except:
                pass

            # step 2: add language in site and catalog
            self.portal.gl_add_site_language('de')
            try:
                # for old code, we also need to add language in trans. catalog
                self.portal.getPortalTranslations().add_language('de')
            except:
                pass

            # step 3: force negotiation to de, regardless of negotiator
            self.portal.REQUEST['EDW_SelectedLanguage'] = {('en', 'de'): 'de'}
            self.portal.REQUEST['TraversalRequestNameStack'] = ['de']

        def test_translate(self):
            # add message and translation
            self.portal.getPortalTranslations().gettext('${count} dogs', 'en')
            try:
                self.portal.getPortalTranslations().message_edit('${count} dogs', 'de', '${count} Hunde', '')
            except AttributeError:
                self.portal.getPortalTranslations().edit_message('${count} dogs', 'de', '${count} Hunde')

            # and test!
            in_de = self.portal.getPortalTranslations().trans('${count} dogs',
                                                              count='3')
            self.assertEqual(in_de, '3 Hunde')

        def test_template_translation(self):
            self.tmpl = PageTemplate(id='test_tmpl')
            self.tmpl.pt_edit('<p i18n:translate="">Home for'
                              ' <span i18n:name="hours">3</span> hours</p>',
                              'text/html')

            self.assertEqual(self.tmpl.__of__(self.portal)(),
                             '<p>Home for <span>3</span> hours</p>')
            self.portal.getLocalizer().edit_message('Home for ${hours} hours', 'en',
                                                    'Home für ${hours} Stunden')
            self.assertEqual(self.tmpl.__of__(self.portal)(),
                             '<p>Home für <span>${hours}</span> Stunden</p>')
Esempio n. 6
0
    def test_pagetemplate(self):
        from Products.PageTemplates.PageTemplate import PageTemplate
        template = PageTemplate()

        # test rendering engine
        with open(os.path.join(path, "simple.pt")) as fd:
            data = fd.read()
        template.write(data)
        self.assertTrue('world' in template())

        # test arguments
        with open(os.path.join(path, "options.pt")) as fd:
            data = fd.read()
        template.write(data)
        self.assertTrue('Hello world' in template(greeting='Hello world'))
        def test_template_translation(self):
            self.tmpl = PageTemplate(id='test_tmpl')
            self.tmpl.pt_edit('<p i18n:translate="">Home for'
                              ' <span i18n:name="hours">3</span> hours</p>',
                              'text/html')

            self.assertEqual(self.tmpl.__of__(self.portal)(),
                             '<p>Home for <span>3</span> hours</p>')
            self.portal.getLocalizer().edit_message('Home for ${hours} hours', 'en',
                                                    'Home für ${hours} Stunden')
            self.assertEqual(self.tmpl.__of__(self.portal)(),
                             '<p>Home für <span>${hours}</span> Stunden</p>')
Esempio n. 8
0
 def pt_render(self, source=False, extra_context={}):
     result = PageTemplate.pt_render(self, source, extra_context)
     assert isinstance(result, unicode)
     return result
Esempio n. 9
0
def time_zpt(fn, count):
    from Products.PageTemplates.PageTemplate import PageTemplate
    pt = PageTemplate()
    pt.write(open(fn).read())
    return time_apply(pt.pt_render, (), {'extra_context': data}, count)
Esempio n. 10
0
 def pt_macros(self):
     self._cook_check()
     return PageTemplate.pt_macros(self)
Esempio n. 11
0
 def pt_render(self, source=False, extra_context={}):
     # Override to support empty strings
     result = PageTemplate.pt_render(self, source, extra_context) or u''
     assert isinstance(result, unicode)
     return result
Esempio n. 12
0
fileindex = sys.argv[1:2]
if fileindex:
    fileindex = fileindex[0]

top = os.path.join(sys.path[0],'..','skins','fckeditor_base','FCKeditor')
baddies = {}; i=0

# walk the tree looking for bad page templates
for path, dirs, files in os.walk(top):

    for filename in files:
        ext = filename.split('.')[-1]
        if ext == 'pt':
            text = file(os.path.join(path, filename)).read()
            ZPT = PageTemplate(); ZPT.write(text)
            errors = ZPT._v_errors
            warnings = ZPT._v_warnings

            if len(errors) + len(warnings) > 0:
                i += 1
                filepath = os.path.join(path[len(top)+1:], filename)
                if len(errors) > 0: haserrors = 'x'
                else:               haserrors = ' '
                if len(warnings) > 0:   haswarnings = 'x'
                else:                   haswarnings = ' '
                baddies[i] = { 'index'      : str(i).rjust(2)
                             , 'filepath'   : filepath.ljust(64)
                             , 'errors'     : errors
                             , 'haserrors'  : haserrors
                             , 'warnings'   : warnings
Esempio n. 13
0
# Rights Reserved.
#
# Authors:
#
# Alex Morega, Eau de Web

from Products.PageTemplates.PageTemplate import PageTemplate
from Products.PageTemplates.PageTemplateFile import PageTemplateFile

from FormsTool import register_naaya_template

class NaayaPageTemplateFile(PageTemplateFile):
    def __init__(self, filename, _globals, form_id):
        super(NaayaPageTemplateFile, self).__init__(filename, _globals)
        self.form_id = form_id
        register_naaya_template(self, form_id)

    def pt_render(self, *args, **kwargs):
        try:
            site = self.getSite()
        except AttributeError, e:
            # there's no site in our acquisition context
            current_form = self
        else:
            forms_tool = site.getFormsTool()
            current_form = forms_tool._getOb(self.form_id, self)

        current_form = current_form.aq_self.__of__(self.aq_parent)

        return PageTemplate.pt_render(current_form, *args, **kwargs)