[Zope] arrgghhh syntactical hell!!

Jacob Singh jacob@prisonbooks.org
Tue, 20 Nov 2001 12:49:30 -0500


So here is my tragedy:
I have an SQL query which pulls a record from a database.  One of the
fields is called file1.  It contains a path to a file (i.e.
media/inline/asdasd.jpeg).  This file is accessible through LocalFS.
LocalFS requires a syntax like media['inline']['asdasd.jpg'], so I wrote
a script to convert the Unix style path to something LocalFS can
understand.  This works fine.  Here is the code I use in my DTML doc to
render asdasd.jpg:

<dtml-call expr="REQUEST.set('imgpath',makeLocalFSPath(file1))">
<dtml-var "_.getitem(imgpath,1)" null="_[media['none.gif']]">

The first line calls the pythinon script that will make the LocalFS
path.  The second one endeavors to render the image using DTML's built
in MIME to HTML technology which is necessary because using <IMG
src=.....  would not give me the with and height and is bad practice
anyway.  The null tag is just to shove that empty image marker in in
case there is nothing in the field.  When I call the page it gets a key
error 
Error Type: KeyError
Error Value: media['inline']['asdasd.jpeg']

But if I put <dtml-var "media['inline']['asdasd.jpeg']"> in any document
in renders just fine.  So basically the variable value gets rendered,
but since It's not a variable but an expression, Zope doesn't know what
to do.  Oh and I tried putting double quotes on imgpath via the
makeLocalFSPath function to no avail.

Thank you for your help
Jacob