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 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')
def test_pagetemplate(self): from Products.PageTemplates.PageTemplate import PageTemplate template = PageTemplate() # test rendering engine template.write(open(os.path.join(path, "simple.pt")).read()) self.assertTrue('world' in template()) # test arguments template.write(open(os.path.join(path, "options.pt")).read()) self.assertTrue('Hello world' in template(greeting='Hello world'))
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
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 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)
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
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,