[Zope] iteration through list with dtml-tags

John Hunter jdhunter at ace.bsd.uchicago.edu
Wed Aug 7 11:09:52 EDT 2002


>>>>> "Axel" == Axel Bock <news-and-lists at the-me.de> writes:

    Axel> To submit queries I do the following:

    Axel> DB = self.dbc() 

If you can't use the DictCursor I suggested above (and it may be
difficult since it looks like you are inheriting the connection but
someone else may be able to help you here), then you can either

1) use the tuple indexing I posted earlier

2) Make a list dictionary in your python product and return it to
   dtml; this will make the dtml more readable.

results = DB.query("select first,last,pid,email from wobba")
resultDicts = []
for result in results:
  resultDicts.append( {'first' : result[0], 'last' : result[1], 
                      {'pid' : result[2], 'email' : result[3]} )

Now return resultDicts, which is a list of dictionaries.

In dtml, you can call the method like this; note the 'mapping' keyword is
critical here:

<dtml-in get_result_dicts mapping>
  <dtml-var first> <dtml-var last> <dtml-var pid> <dtml-var email>
</dtml-in>

Good luck!
John Hunter




More information about the Python-list mailing list