arrgghhh syntactical hell!!
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
Jacob Singh writes:
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']]"> You will not believe how often I have already answered questions like yours:
Use "restrictedTraverse"! Dieter
I tried restrictedTraverse but I get authentication issues, it requires a loggin. -----Original Message----- From: Dieter Maurer [mailto:dieter@handshake.de] Sent: Wednesday, November 21, 2001 5:42 PM To: Jacob Singh Cc: zope@zope.org Subject: Re: [Zope] arrgghhh syntactical hell!! Jacob Singh writes:
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']]"> You will not believe how often I have already answered questions like yours:
Use "restrictedTraverse"! Dieter
Jacob Singh writes:
I tried restrictedTraverse but I get authentication issues, it requires a loggin. It should do that only if one of the traversed objects is protected by a role not assigned to the current user in the current context.
Dieter
participants (2)
-
Dieter Maurer -
Jacob Singh