[newbie with a lot of questions - thanks] Hello, On a site I want to allow users to add files. I created a simple form that has <input type="file"> on it. This form calls a python script with : context.manage_addProduct['OFSP'].manage_addFile(file) This doesn't work : it needs two arguments instead of one. It works when I give an id. What I'd like is to have the id generated based on the given filename. This is how the file product works. How can I "generate" this id ? After this, how can I redirect the user to another form that would let him add some metadata to his file? I need to know the id of the object I just created (does manage_addFile() return something?), and append something like /MyEditForm to the url to be redirected. How can I do this in the python script? Another question : what would be the best option to choose wether to create an image or a file object? Based on content type submited by the browser, or file extensions? I feel a bit like reinventing the wheel, but I guess it's the only way to give the user customized management screens (or did I miss something?). Anyway thanks in advance ! Philippe Jadin
On Sat, 9 Jun 2001, Philippe Jadin wrote:
On a site I want to allow users to add files. I created a simple form that has <input type="file"> on it. This form calls a python script with :
context.manage_addProduct['OFSP'].manage_addFile(file)
This doesn't work : it needs two arguments instead of one. It works when I give an id. What I'd like is to have the id generated based on the given filename.
<untested> id = file.filename # not sure about this filename context.manage_addProduct['OFSP'].manage_addFile(id, file=file.read(), title='XYZ', content_type='text/plain') </untested> Oleg. ---- Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
<untested> id = file.filename # not sure about this filename context.manage_addProduct['OFSP'].manage_addFile(id, file=file.read(), title='XYZ', content_type='text/plain') </untested>
Thanks, it worked almost with this. [answering myself] What I finally did is: ----------------- import string # create the document id from the filename filename=file.filename id=filename[max(string.rfind(filename, '/'), string.rfind(filename, '\\'), string.rfind(filename, ':'), )+1:] # create the file object context.manage_addProduct['OFSP'].manage_addFile(id,file) ------------------ My leitmotiv now : look at the sources... Thanks again ! Philippe
On Sat, 9 Jun 2001, Philippe Jadin wrote:
My leitmotiv now : look at the sources...
Exactly! That why opensource is much, much better! Oleg. ---- Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
participants (2)
-
Oleg Broytmann -
Philippe Jadin