[ZPT] Repeat over dict with options

David Pratt fairwinds at eastlink.ca
Tue Jun 1 23:48:11 EDT 2004


Hi all.  I am having some trouble with the predefined options variable  
and passing a dictionary from a Script Python and then repeating over  
the dictionary to extract the values passed.  I am doing this because I  
want user input in a slot but results are large and want them to  
display in a full page.

I am using the  ZTUtils function make_query to create the query string  
passed to the page from the Script Python.

ie.

from ZTUtils import make_query

     query = make_query(results = {'foo':'bar','foo2':'bar2'})

     return RESPONSE.redirect('test_results?%s' % query)


This produces a url   
http://blah.com/ 
test_results?results.foo:record=bar&results.foo2:record=bar2

If am not getting anything using a repeat with options/results.  How  
should I construct the zpt to get the values of foo and foo2?

I have been trying iterations of something like this:

      <span tal:repeat="value  options/results">
       <p>
          <span tal:define="foo python: value['foo']" tal:content="foo">  
bar</span>
       </p>
       <p>
          <span tal:define="foo python: value['foo2']"  
tal:content="foo2"> bar2</span>
       </p>
     </span>

To make things more difficult, I need to pass a dictionary of this type  
to a page that adds a level of complexity to the original example

results = {1:{'foo':'bar','foo2':'bar2'},
                   2:{'foo':'barnone','foo2':'barnone2'}}

using the make_query function as above I get a url like this:

http://blah.com/test_results?results.1:record=  
{'foo':'bar','foo2':'bar2'}& results.2:record=  
{'foo':'barnone','foo2':'barnone2'}
(except encoded)

I noticed that the request object contains the dictionary I am passing  
and I can do a repeat with the values but I can't seem to go any  
further since it
wants to interpret value as a string and not as a dictionary.

      <span tal:repeat="value python: request.results.values()">
       <p>
          <span tal:define="foo python: value['foo']"  
tal:content="foo">should be bar</span>
       </p>
     </span>

Help much appreciated since I can't seem to get any further with this  
in the meantime.

Regards,
DAve







More information about the ZPT mailing list