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 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)
def pt_render(self, source=False, extra_context={}): result = PageTemplate.pt_render(self, source, extra_context) assert isinstance(result, unicode) return result
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
# 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)