Re: [Zope] Passing args to PageTemplateFile instances
2005/9/23, Anders Bruun Olsen [EMAIL PROTECTED]: On Fri, Sep 23, 2005 at 12:39:31PM +0100, Peter Bengtsson wrote: RESULT: --- Welcome to testprod {'args': (TestProd at /test/testprod used for /test/testprod, HTTPRequest, URL=http://localhost:8080/test/testprod/test_testprod), 'something': 'blah'} 0 /test/testprod http://www.peterbe.com/test/TestProd.tgz So it works just fine in Zope 2.8.0 I suspect that the code you paste was idented wrong because the def testit() function looked like it was part of the __init__ function. Yes, the paste was wrong, but there was more than that, I had my editor slightly misconfigured, which meant that the testit method was done with tab-indention and the rest of the file with space-indention. After I fixed that, it worked correctly and something shows up in options. I am absolutely stumped by why an indention problem can cause such a weird bug. I would have expected Zope/python to spew out an error telling me that indention was fucked up. To just silently make things not work is definitely not nice. Anyway, thank you so much for your help! I'm still not convinced. The tabbing should either have led to a SyntaxError or to testit() becoming a nested method. If it was a nested method you wouldn't be able to reach it via the web like http://localhost:8080/testprod/testit But let's drop this now :) If you're struggling with getting your editor to only use spaces correctly you can ask the list for advise since there are many different python progammers here with the same experience. -- 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] Passing args to PageTemplateFile instances
manage_main = PageTemplateFile(templates/mainTestProd, globals()) index_html = PageTemplateFile(templates/indexTestProd, globals()) test = PageTemplateFile(templates/test, globals()) def __init__(self, id, title): self.id = id self.title = title def testit(self, REQUEST=None): return self.test.__of__(self)(something=blah) In the template I should now be able to access options/something according to previous posts, but this: span tal:replace=options/something/ Why the extra self-wrapping. Do it this way: def testit(self, REQUEST=None): return self.test(self, self.REQUEST, something=blah) Then you'll be able to use: span tal:replace=options/something/ -- 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] Passing args to PageTemplateFile instances
2005/9/23, Anders Bruun Olsen [EMAIL PROTECTED]: Why the extra self-wrapping. Do it this way: def testit(self, REQUEST=None): return self.test(self, self.REQUEST, something=blah) Then you'll be able to use: span tal:replace=options/something/ Thanks, I have now tried that, but it still does not work. I still get: Error Type: KeyError Error Value: 'something' Please press Reply-All and not just to me. That is the correct way of calling PageTemplateFile objects in python code. I've got it working in many places. The error must be either a new zope bug or something else being wrong. Is your setup as simple as you've described in the email? What happens when you in that TAL do something like: br tal:replace=python:str(options) / Do the other namespaces work in the page template? Eg. br tal:replace=python:len(request.form.keys()) / or br tal:replace=python:context.absolute_url_path() / -- 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] Passing args to PageTemplateFile instances
On Fri, Sep 23, 2005 at 12:06:00PM +0100, Peter Bengtsson wrote: Please press Reply-All and not just to me. Sorry about that. That is the correct way of calling PageTemplateFile objects in python code. I've got it working in many places. The error must be either a new zope bug or something else being wrong. Is your setup as simple as you've described in the email? Yes. This is the class I am using: class TestProd(SimpleItem): A TestProd object meta_type = TestProd manage_options = ( {label: Edit, action: manage_main}, {label: View, action: index_html}) manage_main = PageTemplateFile(templates/mainTestProd, globals()) index_html = PageTemplateFile(templates/indexTestProd, globals()) test = PageTemplateFile(templates/test, globals()) def __init__(self, id, title): self.id = id self.title = title def testit(self, REQUEST=None): return self.test(self, self.REQUEST, something=blah) And the test template: !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd; html head meta http-equiv=content-type content=text/html;charset=ISO-8859-1 / meta name=copyright content=copy; 2004 amp; Anders Bruun Olsen lt;anders(AT)bruun-olsen(DOT)net / link rel=stylesheet type=text/css href=css / title tal:content=container/title_or_idTITLE/title /head body div pWelcome to tal:block tal:replace=container/title_or_id//p p tal:content=python:str(options)/ p tal:content=python:len(request.form.keys())/ p tal:content=python:context.absolute_url_path()/ /div /body /html I have added it to the rootfolder in ZMI with the ID testing. What happens when you in that TAL do something like: br tal:replace=python:str(options) / Gives: {'args': ()} Do the other namespaces work in the page template? Eg. br tal:replace=python:len(request.form.keys()) / or br Gives: 0 tal:replace=python:context.absolute_url_path() / Gives: /testing -- Anders -BEGIN GEEK CODE BLOCK- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? --END GEEK CODE BLOCK-- PGPKey: http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=getsearch=0xD4DEFED0 ___ 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] Passing args to PageTemplateFile instances
RESULT: --- Welcome to testprod {'args': (TestProd at /test/testprod used for /test/testprod, HTTPRequest, URL=http://localhost:8080/test/testprod/test_testprod), 'something': 'blah'} 0 /test/testprod http://www.peterbe.com/test/TestProd.tgz So it works just fine in Zope 2.8.0 I suspect that the code you paste was idented wrong because the def testit() function looked like it was part of the __init__ function. 2005/9/23, Anders Bruun Olsen [EMAIL PROTECTED]: On Fri, Sep 23, 2005 at 12:06:00PM +0100, Peter Bengtsson wrote: Please press Reply-All and not just to me. Sorry about that. That is the correct way of calling PageTemplateFile objects in python code. I've got it working in many places. The error must be either a new zope bug or something else being wrong. Is your setup as simple as you've described in the email? Yes. This is the class I am using: class TestProd(SimpleItem): A TestProd object meta_type = TestProd manage_options = ( {label: Edit, action: manage_main}, {label: View, action: index_html}) manage_main = PageTemplateFile(templates/mainTestProd, globals()) index_html = PageTemplateFile(templates/indexTestProd, globals()) test = PageTemplateFile(templates/test, globals()) def __init__(self, id, title): self.id = id self.title = title def testit(self, REQUEST=None): return self.test(self, self.REQUEST, something=blah) And the test template: !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd; html head meta http-equiv=content-type content=text/html;charset=ISO-8859-1 / meta name=copyright content=copy; 2004 amp; Anders Bruun Olsen lt;anders(AT)bruun-olsen(DOT)net / link rel=stylesheet type=text/css href=css / title tal:content=container/title_or_idTITLE/title /head body div pWelcome to tal:block tal:replace=container/title_or_id//p p tal:content=python:str(options)/ p tal:content=python:len(request.form.keys())/ p tal:content=python:context.absolute_url_path()/ /div /body /html I have added it to the rootfolder in ZMI with the ID testing. What happens when you in that TAL do something like: br tal:replace=python:str(options) / Gives: {'args': ()} Do the other namespaces work in the page template? Eg. br tal:replace=python:len(request.form.keys()) / or br Gives: 0 tal:replace=python:context.absolute_url_path() / Gives: /testing -- Anders -BEGIN GEEK CODE BLOCK- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? --END GEEK CODE BLOCK-- PGPKey: http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=getsearch=0xD4DEFED0 -- 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] Passing args to PageTemplateFile instances
On Fri, Sep 23, 2005 at 12:39:31PM +0100, Peter Bengtsson wrote: RESULT: --- Welcome to testprod {'args': (TestProd at /test/testprod used for /test/testprod, HTTPRequest, URL=http://localhost:8080/test/testprod/test_testprod), 'something': 'blah'} 0 /test/testprod http://www.peterbe.com/test/TestProd.tgz So it works just fine in Zope 2.8.0 I suspect that the code you paste was idented wrong because the def testit() function looked like it was part of the __init__ function. Yes, the paste was wrong, but there was more than that, I had my editor slightly misconfigured, which meant that the testit method was done with tab-indention and the rest of the file with space-indention. After I fixed that, it worked correctly and something shows up in options. I am absolutely stumped by why an indention problem can cause such a weird bug. I would have expected Zope/python to spew out an error telling me that indention was fucked up. To just silently make things not work is definitely not nice. Anyway, thank you so much for your help! -- Anders -BEGIN GEEK CODE BLOCK- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? --END GEEK CODE BLOCK-- PGPKey: http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=getsearch=0xD4DEFED0 ___ 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 )
[Zope] Passing args to PageTemplateFile instances
Hi, I have read some posts about this before, but the solutions given there does not seem to work for me. The deal is that I would like to make a product where amongst other things there needs to be a search feature. I then make a method that takes input from a form with searchwords but then I get stuck. How do I get the search results handed over to a ZPT that will display them? I would like to just pass the results as an argument to it, and have made a simple test-product to test how this would work. class TestProd(SimpleItem): A TestProd object meta_type = TestProd manage_options = ( {label: Edit, action: manage_main}, {label: View, action: index_html}) manage_main = PageTemplateFile(templates/mainTestProd, globals()) index_html = PageTemplateFile(templates/indexTestProd, globals()) test = PageTemplateFile(templates/test, globals()) def __init__(self, id, title): self.id = id self.title = title def testit(self, REQUEST=None): return self.test.__of__(self)(something=blah) In the template I should now be able to access options/something according to previous posts, but this: span tal:replace=options/something/ results in: Error Type: KeyError Error Value: 'something' I am using Zope 2.8.0. Am I doing it wrong? How can it be done correctly? -- Anders -BEGIN GEEK CODE BLOCK- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? --END GEEK CODE BLOCK-- PGPKey: http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=getsearch=0xD4DEFED0 ___ 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 )