Re: [ZPT] Re: calling ZPT from script python - problem
On Wednesday 22 Jun 2005 8:19 am, Kenneth Gonsalves wrote: > i solved it like this: > > python:request.set('compname',options['compname']) > and then accessed it as > request['compname'] > > from what i can see, the end script called is a recursive script > and for some reason, it only works if the variable comes from > 'request' and not from 'options'. I am going to make the simplest > example of a recursive script and see if this hypothesis is > correct. will revert sorry about this red herring - the problem was that i had inadvertently chose 'redirect_to' instead of 'traverse_to' in my controller page template, which of course, zapped the options. 20 hours of programming time wasted! -- regards kg http://www.livejournal.com/users/lawgon tally ho! http://avsap.org.in ಇಂಡ್ಲಿನಕ್ಸ வாழ்க! ___ ZPT mailing list ZPT@zope.org http://mail.zope.org/mailman/listinfo/zpt
Re: [ZPT] Re: calling ZPT from script python - problem
On Tuesday 21 Jun 2005 11:27 pm, Dieter Maurer wrote: > Kenneth Gonsalves wrote at 2005-6-21 09:08 +0530: > > ... > >the variable in question is 'compname' which is either > >request['compname'] or options['compname'] depending on how the > > ZPT is called (from web it goes to 'request' and from script in > > goes to 'options') > > Thus, you normalize like this > > ... tal:define=" > ... > compname options/compname | request/compname > ... > " > > and then use "compname"... i solved it like this: python:request.set('compname',options['compname']) and then accessed it as request['compname'] from what i can see, the end script called is a recursive script and for some reason, it only works if the variable comes from 'request' and not from 'options'. I am going to make the simplest example of a recursive script and see if this hypothesis is correct. will revert -- regards kg http://www.livejournal.com/users/lawgon tally ho! http://avsap.org.in ಇಂಡ್ಲಿನಕ್ಸ வாழ்க! ___ ZPT mailing list ZPT@zope.org http://mail.zope.org/mailman/listinfo/zpt
Re: [ZPT] Re: calling ZPT from script python - problem
Kenneth Gonsalves wrote at 2005-6-21 09:08 +0530: > ... >the variable in question is 'compname' which is either >request['compname'] or options['compname'] depending on how the ZPT >is called (from web it goes to 'request' and from script in goes to >'options') Thus, you normalize like this ... tal:define=" ... compname options/compname | request/compname ... " and then use "compname"... -- Dieter ___ ZPT mailing list ZPT@zope.org http://mail.zope.org/mailman/listinfo/zpt
[ZPT] Re: calling ZPT from script python - problem
Kenneth Gonsalves schrieb: On Monday 20 Jun 2005 5:26 pm, Tonico Strasser wrote: Kenneth Gonsalves schrieb: hi i am having a very weird experience. I have a page template called manageheads. This requires a parameter called 'companyname' to be passed to it. I access this option as: python:somefunction(companyname=options['companyname']) when i call the ZPT from the web like so: http://.../manageheads?companyname=nameofcompany it works Are you shure this works? Did you redefine 'options' somewhere? but if i call it from a python script like so: return manageheads(companyname=nameofcompany) it complains saying key error 'companyname' It should simply work. The weird thing is that i have several similar ZPTs where this call from python scripts work perfectly in the same zope instance. So why not in this one? any clues? Maybe you did redefine 'options' in your template. options has not been redefined anywhere. The problem appears to be in the way to call a particular python script this is a bit long, but interesting nevertheless -:) the variable in question is 'compname' which is either request['compname'] or options['compname'] depending on how the ZPT is called (from web it goes to 'request' and from script in goes to 'options') This is the script: callheadtree.py parameter list: compname theads=context.getheadleafs() heads=[] for k in theads: heads.append(k['id']) htree=context.getheadtree(compname=compname,id=1,name='chart',ret=[],heads=heads) headtree=[] for k in htree: headtree.append({'name':k}) return headtree when tested using the test tab it works when the originating ZPT is called from the web using '?' notation it works when called from the following script: onetest.py names=callheadtree(compname='testcompany') return names it gives a Keyerror 'compname' when the originating ZPT is called from a script: it gives a Keyerror 'compname' Ok, you've got a KeyError, but where? Traceback? Tonico ___ ZPT mailing list ZPT@zope.org http://mail.zope.org/mailman/listinfo/zpt
Re: [ZPT] Re: calling ZPT from script python - problem
On Monday 20 Jun 2005 5:26 pm, Tonico Strasser wrote: > Kenneth Gonsalves schrieb: > > hi > > i am having a very weird experience. I have a page template > > called manageheads. This requires a parameter called > > 'companyname' to be passed to it. I access this option as: > > python:somefunction(companyname=options['companyname']) > > when i call the ZPT from the web like so: > > http://.../manageheads?companyname=nameofcompany > > it works > > Are you shure this works? Did you redefine 'options' somewhere? > > > but if i call it from a python script like so: > > return manageheads(companyname=nameofcompany) > > it complains saying > > key error 'companyname' > > It should simply work. > > > The weird thing is that i have several similar ZPTs where this > > call from python scripts work perfectly in the same zope > > instance. So why not in this one? any clues? > > Maybe you did redefine 'options' in your template. options has not been redefined anywhere. The problem appears to be in the way to call a particular python script this is a bit long, but interesting nevertheless -:) the variable in question is 'compname' which is either request['compname'] or options['compname'] depending on how the ZPT is called (from web it goes to 'request' and from script in goes to 'options') This is the script: callheadtree.py parameter list: compname theads=context.getheadleafs() heads=[] for k in theads: heads.append(k['id']) htree=context.getheadtree(compname=compname,id=1,name='chart',ret=[],heads=heads) headtree=[] for k in htree: headtree.append({'name':k}) return headtree when tested using the test tab it works when the originating ZPT is called from the web using '?' notation it works when called from the following script: onetest.py names=callheadtree(compname='testcompany') return names it gives a Keyerror 'compname' when the originating ZPT is called from a script: it gives a Keyerror 'compname' -- regards kg http://www.livejournal.com/users/lawgon tally ho! http://avsap.org.in ಇಂಡ್ಲಿನಕ್ಸ வாழ்க! ___ ZPT mailing list ZPT@zope.org http://mail.zope.org/mailman/listinfo/zpt
[ZPT] Re: calling ZPT from script python - problem
Kenneth Gonsalves schrieb: hi i am having a very weird experience. I have a page template called manageheads. This requires a parameter called 'companyname' to be passed to it. I access this option as: python:somefunction(companyname=options['companyname']) when i call the ZPT from the web like so: http://.../manageheads?companyname=nameofcompany it works Are you shure this works? Did you redefine 'options' somewhere? but if i call it from a python script like so: return manageheads(companyname=nameofcompany) it complains saying key error 'companyname' It should simply work. The weird thing is that i have several similar ZPTs where this call from python scripts work perfectly in the same zope instance. So why not in this one? any clues? Maybe you did redefine 'options' in your template. Tonico ___ ZPT mailing list ZPT@zope.org http://mail.zope.org/mailman/listinfo/zpt