[Zope] Python Script & file.filename

Milos Prudek milos.prudek@tiscali.cz
Wed, 06 Mar 2002 20:33:57 +0100


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)">


Python Script "ad_save" (parameters id,ad,url):
if 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?



The only solution I can imagine is modifying "ads_save" to have three lines:
<dtml-if "ad_title.filename">
   <dtml-var "ad_save('ad_title',ad_title,ad_title_url)">
</dtml-if>

But that's not exactly "putting logic to python and presentation to 
DTML... :-(


-- 
Milos Prudek