[Zope] Add Property to Image with Form & Python?

Horak, Karl KEHORAK at sandia.gov
Sat Mar 27 11:09:11 EST 2004


Kevin,

I'd suggest treating images as files so you can manage their properties, as
pointed our by Dieter.  Then your DTML will look something like:

<dtml-call expr="manage_addFile(id='', file=form_file, title=form_title)">

<dtml-call
expr="_.getitem(getBasename(file.filename),1).manage_addProperty('submitted_
by', form_submitted_by, 'string')">

Form_file, form_title, and form_submittted_by are from your upload form.

getBasename() is an external Python method that takes full path-filenames
passed by IE (/blah/blah/myfile.ext) and trims them down to myfile.ext.
Netscape and Mozilla don't have this problem since they correctly pass just
the simple filename when they say they do.  

# getBasename(filename)

import re

def getBasename(filename):
     return re.split( r"[/|\\]" , filename )[:1]

(The above is from memory but its close--I can check the sourcecode at work
on Monday if its giving you problems. It splits on / or \ depending on the
client op sys and returns the last element in the list.)

Karl




More information about the Zope mailing list