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

Kevin Jones ktmi at earthlink.net
Sat Mar 27 16:53:39 EST 2004


Thanks, Karl-

I think you and Dieter are right.  I like the idea of moving 
images over to files.

And thanks for the code examples!  I've got the full 
path-filenames working for now.

Cheers-

kj

Horak, Karl wrote:
> 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