[Zope] Python Script & file.filename

Peter Bengtsson mail@peterbe.com
Thu, 07 Mar 2002 09:44:49 +0100


Try this instead:

Python Script "ad_save" (parameters id,ad,url):
if hasattr(ad, 'filename'):
   try:
      context.manage_delObjects([id])
   except:
      pass
   context.manage_addImage(id=id, file=ad, title=url)
return


At 20:33 2002-03-06 +0100, Milos Prudek wrote:
>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
>
>
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://lists.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists - http://lists.zope.org/mailman/listinfo/zope-announce
>http://lists.zope.org/mailman/listinfo/zope-dev )