Re: [Zope] Call PageTemplateFile class instances
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 [EMAIL PROTECTED]: 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 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
Re: [Zope] Call PageTemplateFile class instances
+---[ Peter Bengtsson ]-- | 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!! why do you do this double shuffle anyway, when you can directly call page and protect it if necessary... I certainly don't have the issue you're describing and I don't need to do all that implements garbage either. Are you sure you don't have some Product installed that's messing with it? -- Andrew Milton [EMAIL PROTECTED] ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Call PageTemplateFile class instances
On 13.11.2008 17:53 Uhr, Peter Bengtsson wrote: 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!! Are you sure that you don't have to pass the REQUEST as a keyword parameter? -aj begin:vcard fn:Andreas Jung n:Jung;Andreas org:ZOPYX Ltd. Co. KG adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany email;internet:[EMAIL PROTECTED] title:CEO tel;work:+49-7071-793376 tel;fax:+49-7071-7936840 tel;home:+49-7071-793257 x-mozilla-html:FALSE url:www.zopyx.com version:2.1 end:vcard ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Call PageTemplateFile class instances
2008/11/13 Andrew Milton [EMAIL PROTECTED]: +---[ Peter Bengtsson ]-- | 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!! why do you do this double shuffle anyway, when you can directly call page and protect it if necessary... I certainly don't have the issue you're describing and I don't need to do all that implements garbage either. Are you sure you don't have some Product installed that's messing with it? No I'm not sure. Truth is that my product is more complicated than that but so I took a risk thinking it'll be the same as the pseudo product code I wrote. -- Andrew Milton [EMAIL PROTECTED] ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Call PageTemplateFile class instances
2008/11/13 Andreas Jung [EMAIL PROTECTED]: On 13.11.2008 17:53 Uhr, Peter Bengtsson wrote: 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!! Are you sure that you don't have to pass the REQUEST as a keyword parameter? No difference if I pass REQUEST or not. :( -aj ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Call PageTemplateFile class instances
+---[ Peter Bengtsson ]-- | I've kind of work it out. The trick is to write some boiler plate in | the class definition like this:: Does it work when you talk to it through Zope proper instead of trying to call it via the test harness? -- Andrew Milton [EMAIL PROTECTED] ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )