[Zope] Python Script & file.filename

Thomas B. Passin tpassin@mitretek.org
Wed, 6 Mar 2002 15:24:17 -0500


[Milos Prudek]

> I run across inexplicable behaviour:
>
> DTML method "ads_save" has a file type from previous method's <input
> type=file>, and it calls Python Script. This Python script should check
> if that file is already present, delete it, and save the new file. This
> works fine if the file is not present. But if it is present, Python
> script throws up with Attribute Error: filename at the line number 1.
>
>
> DTML Method "index_html":
> <form name=form1 action="ads_save" method="post"
> enctype="multipart/form-data">
> <input type="file" name="ad_title"> URL: <input name="ad_title_url"
> type=text>
> ...
>
>
>
> DTML Method "ads_save":
> <dtml-var "ad_save('ad_title',ad_title,ad_title_url)">
>

Here it looks like you send the value of ad_title to the script as the
second parameter

>
> Python Script "ad_save" (parameters id,ad,url):

# Here the parameter called "ad" gets the value of ad_title
> if ad.filename:
#It's a string, not an object, so if ad exists, there is no ad.filename

>    try:
>       context.manage_delObjects([id])
>    except:
>       pass
>    context.manage_addImage(id=id, file=ad, title=url)
> return
>
>
> This is difficult to comprehend, because the offending line "if
> ad.filename" is testing a REQUEST form variable (a parameter to Python
> script, strictly speaking). It is not testing a ZODB file. Or is it?
>
A REQUEST variable which is a string, not an object, as best as I can see.

Cheers,

Tom P