Hello friends, i have a form which uploads a file. and it calls a method which pass parameter to a python script. this python script creates a 'file object'. Now the python script creates a 'file object' even if file is not uploaded in the form. so in the script i want to have a condition, if picture: container.foldername.manage_addImage(id=id, file=picture) but still even if the file is not uploaded the 'file object' is created. what is the problem ?? i have to use the python script and not only DTML method because i am doing some other calcuations too. Please help !!! Thanks, Sanju __________________________________________________ Do You Yahoo!? Buy the perfect holiday gifts at Yahoo! Shopping. http://shopping.yahoo.com
On Wed, Dec 05, 2001 at 08:16:10AM -0800, sanjeev c s wrote:
Hello friends, i have a form which uploads a file. and it calls a method which pass parameter to a python script. this python script creates a 'file object'.
Now the python script creates a 'file object' even if file is not uploaded in the form. so in the script i want to have a condition,
if picture: container.foldername.manage_addImage(id=id, file=picture)
but still even if the file is not uploaded the 'file object' is created. what is the problem ??
When you submit an upload form, you always get the file object, even if it's empty. But if the user didn't give a filename in the form, you can test for that like so: if picture.filename: container.foldername.manage_addImage(id=id, file=picture) This works because picture.filename will be an empty string if they didn't provide a name. -- paul winkler home: http://www.slinkp.com music: http://www.reacharms.com calendars: http://www.calendargalaxy.com
sanjeev c s writes:
i have a form which uploads a file. and it calls a method which pass parameter to a python script. this python script creates a 'file object'. .... if picture: container.foldername.manage_addImage(id=id, file=picture)
but still even if the file is not uploaded the 'file object' is created. what is the problem ?? The reason is easy:
Even if no file is uploaded, you get a "FileUpload" object. Unfortunately, the "FileUpload" class does not define senseful "__len__" or "__nonzero__" methods (this is a bug --> <http:collector.zope.org>) and therefore, all such objects are considered Python true values. Your options: * Fix "ZPublisher.HTTPRequest.FileUpload" such that it defines a "__nonzero__" method. Post your patch to the collector (see above). This way, you help improve Zope * Work around the problem in your application code. You can use: "if picture.filename:" in place of "if picture:" Dieter
Dieter, this could answer a former question of mine. Is this the reason why in CMF Metadata and Fileupload is always separated? Robert ----- Original Message ----- From: "Dieter Maurer" <dieter@handshake.de> To: "sanjeev c s" <sanju22_us@yahoo.com> Cc: <zope@zope.org> Sent: Wednesday, December 05, 2001 11:04 PM Subject: Re: [Zope] small python problem
sanjeev c s writes:
i have a form which uploads a file. and it calls a method which pass parameter to a python script. this python script creates a 'file object'. .... if picture: container.foldername.manage_addImage(id=id, file=picture)
but still even if the file is not uploaded the 'file object' is created. what is the problem ?? The reason is easy:
Even if no file is uploaded, you get a "FileUpload" object.
Unfortunately, the "FileUpload" class does not define senseful "__len__" or "__nonzero__" methods (this is a bug --> <http:collector.zope.org>) and therefore, all such objects are considered Python true values.
Your options:
* Fix "ZPublisher.HTTPRequest.FileUpload" such that it defines a "__nonzero__" method. Post your patch to the collector (see above). This way, you help improve Zope
* Work around the problem in your application code. You can use:
"if picture.filename:" in place of "if picture:"
Dieter
_______________________________________________ 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 )
Robert Rottermann writes:
this could answer a former question of mine. Is this the reason why in CMF Metadata and Fileupload is always separated? I do not understand your question...
Nevertheless, I think I can answer "no": There is an easy workaround for the described "FileUpload" bug: check "file.filename" instead of "file". Thus, there is no reason for separation (of anything) when you do not want to separate (for other reasons). Dieter
participants (4)
-
Dieter Maurer -
Paul Winkler -
Robert Rottermann -
sanjeev c s