[Zope] <dtml-elif> problem
Paul Winkler
pw_lists@slinkp.com
Fri, 2 Aug 2002 13:32:06 -0400
On Fri, Aug 02, 2002 at 01:28:45PM -0300, Tom Germaine wrote:
> Hi All:
>
> I am trying to download files (with standardized filenames) to
> specific subdirectories with a form that calls a dtml document for
> processing, but the code breaks at the dtml-elif phrase:
> --------
> <dtml-var standard_html_header>
>
> <h2><dtml-var title></h2>
>
> <dtml-let fname="_.string.split(myfile.filename,'\\')[-1]">
> <dtml-let filename="_.string.split(fname,'.html')[0]">
>
> <dtml-if expr="filename[3:6]=='do_'"><dtml-let dir="do_">
Stop right there. <dtml-let> must be closed before you
can go into another logical block such as <dtml-elif>.
It seems weird, I know, but that's the way it works.
Your first instinct might be to get around this problem by
duplicating your <dtml-call> code in each part of the if/elif/else.
But I wouldn't do that - duplicated code is a sign that
there must be a better way. Instead, get rid of the dtml-if entirely
and try something like this: (untested)
<dtml-with avc>
<dtml-call expr="_.addMyDoc(REQUEST, _.getitem('mytitle)')">
</dtml-with>
Now write a script (python) called addMyDoc in the same folder
as this dtml code. On the parameter list in the management
interface, add: REQUEST=None, mytitle=""
In the body of the script, write something like this (untested):
# note: I'm not sure about mytitle - it's not clear to me
# in your code where it comes from.
# If it's in the request, then uncomment the next line, and
# remove the second parameter from the dtml-call expression:
# mytitle = REQUEST['mytitle']
filename = REQUEST['filename']
if filename[3:6] == 'do_':
dir = getattr(container, 'do_')
elif filename[3:6] == 'aa_':
dir = getattr(container, 'aa_')
else:
dir = getattr(container, 'vth')
dir.manage_addProduct['OFSP'].manage_addDTMLDocument(mytitle, filename)
return ""
# end of script.
--
Paul Winkler
home: http://www.slinkp.com
"Muppet Labs, where the future is made - today!"