RE: [Zope] Replace files in a specific directory using pythonscri pt
Hi Heimo, Problem solved. Thanks for the directions. (I was looking for a source file named "File.py" not "Image.py". ) For those who are interested in the sollution: the source tells me: .... def manage_edit(self, title, content_type, precondition='', filedata=None, REQUEST=None): """ Changes the title and content type attributes of the File or Image. """ .... def manage_upload(self,file='',REQUEST=None): """ Replaces the current contents of the File or Image object with file. The file or images contents are replaced with the contents of 'file'. """ ... so for my problem I needed "manage_upload". Using "manage_upload" I could successfully edit the content of the object, but I couldn't upload the file-content I wanted. Untill I looked at my form header-tag and realized I forgot to include "enctype="multipart/form-data". Stupid me! So a simple "context.objectname.manage_upload(file)" (with file being the name of the file-object to upload, and objectname being the name of the zope file-object) did the trick. Ria
-----Original Message----- From: Heimo Laukkanen [mailto:huima@fountainpark.org] Sent: donderdag 7 november 2002 20:46 To: zope@zope.org Cc: marinus@cs.utwente.nl Subject: [Zope] Replace files in a specific directory using pythonscript
I know it is possible to upload a new file replacing the file for a certain ID because in the zope management interface this is done by editing >the FileObject with the specified ID. I read in the bugcollector that the method "updata_data" cannot be >used, instead "manage_upload" should be used. ... Can anyone provide me with a sample python script that uses (or clues how to use) manage_upload to upload this file to the correct ID?
I don't have a sample script, but some clues to help you on. First of all, learn to check and search help from the Zope Books API section and/or the help in your Zope server. These files give you some idea atleast.
And then the best source for help is the source code. If you see something done in the Zope interfaces etc. you can try to look for those sources too, for some help.
But now for the real help:
With the form - listing all the files in the directory, you can get a good idea from the Examples that come with Zope. There is the FileLibrary example that shows you a lot.
For File object, the update function is manage_edit. So in your script you will call this function for the object you want to update.
Below is how it is defined in the source ( lib/python/OFS/Image.py ):
def manage_edit(self, title, content_type, precondition='', filedata=None, REQUEST=None):
Hope this helps.
-huima
participants (1)
-
Ria Marinussen