Hi, I must admit I'm relatively new to both python and Zope but have a problem which I can't find the solution to in the (easy-to-reach) documentation. A lot has been written about passing data from dtml to python scripts, but not much in the other direction. I have no problems returning simple lists, e.g. # getResults return (1,2,3,4,5) ...where the results are returned to a dtml method using something like: <dtml-in "getResults()"> <dtml-var sequence-item> </dtml-in> However, I wish to pass a table of results with 'column names' (in layman's terms), such that I can read the returned results something like... <dtml-in "getResults()"> <dtml-var Column1> <dtml-var Column2> <dtml-var Column3> </dtml-in> So, how do I pass named results from python script to dtml? Thanks for your thoughts. Erik.
However, I wish to pass a table of results with 'column names' (in layman's terms), such that I can read the returned results something like... <dtml-in "getResults()"> <dtml-var Column1> <dtml-var Column2> <dtml-var Column3> </dtml-in>
So, how do I pass named results from python script to dtml?
from python, you pass an array of dictionaries: #results() return [{'colum1': 'value1', 'column2': 'value2'}, {'colum1': 'value12', 'column2': 'value22'}, ...] in dtml you do: <dtml-in "results()" mapping> <dtml-var column1>...<dtml-var column2>.... </dtml-in> have fun, Klaus -- Goelz & Schwarz GmbH Waltherstrasse 29, 80337 Muenchen, Germany phone: + 49 - (0)89 / 54 46 70 - 0 fax: +49 - (0)89 / 54 46 70 - 10 e-mail: klaus.herrmann@goelz.com web: http://www.goelz.com
Hi,
I must admit I'm relatively new to both python and Zope but have a problem which I can't find the solution to in the (easy-to-reach) documentation. A lot has been written about passing data from dtml to python scripts, but not much in the other direction.
I have no problems returning simple lists, e.g. # getResults return (1,2,3,4,5)
...where the results are returned to a dtml method using something like: <dtml-in "getResults()"> <dtml-var sequence-item> </dtml-in>
However, I wish to pass a table of results with 'column names' (in layman's terms), such that I can read the returned results something like... <dtml-in "getResults()"> <dtml-var Column1> <dtml-var Column2> <dtml-var Column3> </dtml-in>
So, how do I pass named results from python script to dtml?
Thanks for your thoughts.
Erik, Am I right when I say that you actually want to return a list of dictionaries (tag value pairs)? In that case you should return something like: def getResults(): return [ { 'Column2':'foo1', 'Column3','bar1'}, { 'Column2':'foo2', 'Column3','bar2'} ] although I suppose you need an extra <dtml-with sequence_item> (I'm not very much into DTML) Hope this helps you in any way, Douwe
[Isokangas, Erik HTC/DE/FRA]
However, I wish to pass a table of results with 'column names' (in layman's terms), such that I can read the returned results something like... <dtml-in "getResults()"> <dtml-var Column1> <dtml-var Column2> <dtml-var Column3> </dtml-in>
So, how do I pass named results from python script to dtml?
If you have a set of rows from the table, make the return value to be a list of dictionaries. Then use the keyword "mapping" with dtml-in - getResults() returns, say, [{"Column1":1,"Column2":2}, {"Column1":3,"Column2":4}] <dtml-in "getResults()" mapping> <dtml-var "_['sequence-item']['Column1']"> </dtml-in> Cheers, Tom P
You can use the mapping option for dtml-in, as several people have already mentioned. But you should also look into using a brain to wrap your returned objects. Depending on your needs, a brain may prove more useful (or not). The Zope Book covers both options pretty well.
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Isokangas, Erik HTC/DE/FRA Sent: Thursday, July 25, 2002 6:58 AM To: 'zope@zope.org' Subject: [Zope] Returning lists from python back to dtml
Hi,
I must admit I'm relatively new to both python and Zope but have a problem which I can't find the solution to in the (easy-to-reach) documentation. A lot has been written about passing data from dtml to python scripts, but not much in the other direction.
I have no problems returning simple lists, e.g. # getResults return (1,2,3,4,5)
...where the results are returned to a dtml method using something like: <dtml-in "getResults()"> <dtml-var sequence-item> </dtml-in>
However, I wish to pass a table of results with 'column names' (in layman's terms), such that I can read the returned results something like... <dtml-in "getResults()"> <dtml-var Column1> <dtml-var Column2> <dtml-var Column3> </dtml-in>
So, how do I pass named results from python script to dtml?
Thanks for your thoughts.
Erik.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (5)
-
Charlie Reiman -
douwe@oberon.nl -
Isokangas, Erik HTC/DE/FRA -
Klaus Herrmann -
Thomas B. Passin