[Zope] dtml-in over python script
David Loeffler
dl267@hermes.cam.ac.uk
Fri, 5 Jul 2002 23:26:53 +0100 (BST)
Charlie,
What you want is a Pluggable Brain. Have a look in the Zope Book chapter
on relational database integration: there are some examples. Create a file
in your Extensions folder:
--- file "somefile.py" ---
import string
class MyBrain:
def fav_food(self):
return string.split(self.bigfield, ',')[0]
def fav_color(self):
return string.split(self.bigfield, ',')[1]
Then in the Advanced tab of your SQL query, enter the filename and the
name of the class in the box where it asks what class to bind to the
results.
Now in the DTML you can write:
<dtml-in query_favourites>
<dtml-var fav_food>
<dtml-var fav_color>
<dtml-in>
and it should work. To be honest my DTML is rusty - I use ZPT more often
these days - but I think this should work, modulo typos/brainos (I haven't
tested any of this code.)
David