[Zope] dtml-in over python script

Dieter Maurer dieter@handshake.de
Sun, 7 Jul 2002 22:17:48 +0200


Charlie Reiman writes:
 > I have a SQL query that I need to wrap in a Python script. Fine and dandy.
 > I'd like the results of the python call to be accessable with dtml-in but
 > with custom field/attribute names.
 > 
 > I other words, I want to be able to do this:
 > 
 > --- dtml ---
 > <dtml-in MyPythonScript>
 > <dtml-var favorite_food>
 > <dtml-var favorite_color>
 > </dtml-in>
 > 
 > And this:
 > 
 > --- MyPythonScript ---
 > rawresults = context.query_favorites()
 > results = []
 > for rawitem in rawresults:
 >   food, color = results[0].bigfield.split(',')
 >   results.append(???)
You may use a dictionary: " {'food':food, 'color':color}".

You can access the result with

    <dtml-in ... mapping>


Dieter