Re: How to pass arbitrary objects to a ZPT from Script(Python)
My problem is this: How can I, from a python script, pass a result set which has been returned from a ZSQL method, on to a ZPT
How about this... # script (python) aaa = context.aaa # a zpt foo = [1, 2, 3, 4, 5] # could be sql result req = context.REQUEST req.set('foo', foo) return aaa(REQUEST=req) ### Then in the zpt: <span tal:replace="request/foo">foo goes here</span> _________________________________________________________________ Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail
That doesn't half complicate what is a really simple thing. # script python context.aaa(a=1,b=2) # zpt <span tal:replace="options/a"/> <span tal:replace="options/b"/> Bottom line is that any 'parameters' to a zpt are put into the options dictionary. Simple eh? Phil --On 08 November 2003 22:45 +0000 Lee Harr <missive@hotmail.com> wrote:
My problem is this: How can I, from a python script, pass a result set which has been returned from a ZSQL method, on to a ZPT
How about this...
# script (python) aaa = context.aaa # a zpt
foo = [1, 2, 3, 4, 5] # could be sql result
req = context.REQUEST req.set('foo', foo)
return aaa(REQUEST=req) ###
Then in the zpt:
<span tal:replace="request/foo">foo goes here</span>
_________________________________________________________________ Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail
_______________________________________________ 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 )
Ok. Time to eat crow here. The problem was a de-referencing problem. Here is the proper way to de-reference the result-set so that I have a single record in a variable: <span tal:define="global result python:options['results'][0]" tal:omit-tag=""/> In other words, by passing a result set with a single record via the options dictionary, I had to unwrap a dictionary contained in a list contained in a dictionary. Does anyone know why it is not possible to reference a list element by number, using a simple TAL path statement? It would sure be nice to write a statement like this: <span tal-define="result options/records/0 | nothing"/> In this case, if there were no records value, the statement would default to nothing. Otherwise, result would receive the first element of the list stored in records. Martin Diers Future zope guru. Now if I can only figure out this browser thingy.
That doesn't half complicate what is a really simple thing.
# script python
context.aaa(a=1,b=2)
# zpt
<span tal:replace="options/a"/> <span tal:replace="options/b"/>
On Sun, Nov 09, 2003 at 04:25:04PM -0600, Martin Diers wrote:
Does anyone know why it is not possible to reference a list element by number, using a simple TAL path statement? It would sure be nice to write a statement like this:
<span tal-define="result options/records/0 | nothing"/>
There have been related proposals. A long, somewhat contentious, and inconclusive thread is here: http://mail.zope.org/pipermail/zope-dev/2003-July/thread.html#20115 warning, i posted a lot of whiney messages in that thread. There is an experimental implementation of one of the proposals, here: http://mail.zope.org/pipermail/zope-dev/2003-July/020199.html If nothing else, the discussion shows that it is very hard to meet everybody's needs. -- Paul Winkler http://www.slinkp.com Look! Up in the sky! It's FUZZY YOKEL PENIS! (random hero from isometric.spaceninja.com)
participants (4)
-
Lee Harr -
Martin Diers -
Paul Winkler -
Phil Harris