[Zope] Call PageTemplateFile class instances
Peter Bengtsson
peter at fry-it.com
Thu Nov 13 12:10:11 EST 2008
I've kind of work it out. The trick is to write some boiler plate in
the class definition like this::
from zope import traversing, component, interface
from zope.interface import implements
from zope.traversing.interfaces import ITraversable
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
class MyProduct(Folder):
implements(ITraversable)
component.provideAdapter(
traversing.adapters.DefaultTraversable,
(interface.Interface,),ITraversable)
meta_type = "bla"
page = PageTemplateFile('zpt/foo.pt', globals())
def render_page(self):
html = self.page(self.REQUEST) # ERROR!!
I don't understand how it works and I wish there was a way to apply
these settings from a function instead of having to copy and paste it
into every instance creating class.
2008/11/13 Peter Bengtsson <peter at fry-it.com>:
> This used to work in zope 2.8 but not now in zope 2.10 (actually zope
> 2.10.7 to be exact)
>
> from Products.PageTemplates.PageTemplateFile import PageTemplateFile
> class MyProduct(Folder):
> meta_type = "bla"
> page = PageTemplateFile('zpt/foo.pt', globals())
>
> def render_page(self):
> html = self.page(self.REQUEST) # ERROR!!
>
> The error is ridiculously large so I've truncated it:
>
>
> Error in test test_foo
> (Products.MoneyVillage2.tests.test_creditconfusion.TestCreditCheck)
> Traceback (most recent call last):
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/Testing/ZopeTestCase/profiler.py",
> line 98, in __call__
> testMethod()
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/Products/MoneyVillage2/tests/test_creditconfusion.py",
> line 20, in test_foo
> print cc.advice2(self.app.REQUEST)
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/Shared/DC/Scripts/Bindings.py",
> line 313, in __call__
> return self._bindAndExec(args, kw, None)
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/Shared/DC/Scripts/Bindings.py",
> line 350, in _bindAndExec
> return self._exec(bound_data, args, kw)
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/Products/PageTemplates/PageTemplateFile.py",
> line 129, in _exec
> return self.pt_render(extra_context=bound_names)
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/Products/PageTemplates/PageTemplate.py",
> line 98, in pt_render
> showtal=showtal)
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/zope/pagetemplate/pagetemplate.py",
> line 117, in pt_render
> strictinsert=0, sourceAnnotations=sourceAnnotations)()
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/zope/tal/talinterpreter.py",
> line 271, in __call__
> self.interpret(self.program)
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/zope/tal/talinterpreter.py",
> line 346, in interpret
> handlers[opcode](self, args)
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/zope/tal/talinterpreter.py",
> line 870, in do_useMacro
> macro = self.engine.evaluateMacro(macroExpr)
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/zope/tales/tales.py",
> line 696, in evaluate
> return expression(self)
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/zope/tales/expressions.py",
> line 217, in __call__
> return self._eval(econtext)
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/Products/PageTemplates/Expressions.py",
> line 153, in _eval
> ob = self._subexprs[-1](econtext)
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/zope/tales/expressions.py",
> line 124, in _eval
> ob = self._traverser(ob, element, econtext)
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/Products/PageTemplates/Expressions.py",
> line 83, in boboAwareZopeTraverse
> request=request)
> File "/home/peterbe/virtualenvzope/MoneyVillage2/zope2107/lib/python/zope/traversing/adapters.py",
> line 161, in traversePathElement
> raise TraversalError('No traversable adapter found', obj)
> TraversalError: ('No traversable adapter found', {'master':
> [('version', '1.6'), ('mode', 'html'), ('setPosition', (1, 0)),
> ('setSourceFile', 'main_template'), ('beginScope', {'define-macro':
> 'master'}), ('optTag', ('metal:block', None, 'metal', 0, [('startTag',
> ('metal:block', [('define-macro', 'master', 'metal')]))], [('rawtextCo
> ...........................MANY MANY MORE
> LINES..................................
>
>
>
> --
> Peter Bengtsson,
> work www.fry-it.com
> home www.peterbe.com
> hobby www.issuetrackerproduct.com
>
--
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com
More information about the Zope
mailing list