change manage_addFile
I copied the code from manage_addFileFolder so that we can upload files into the filesystem but I'd like to amend it so that we can specify the target folder rather than just having the file uploaded to the folder in which the form resides. How would I do that? I've looked through the code in OFS that handles this but am not sure how to add the folder as a variable.... (I;ve tried a couple of things unsuccessfully) manage_addFileForm=HTMLFile('dtml/imageAdd', globals(),Kind='File',kind='file') def manage_addFile(self,id,file='',title='',precondition='', content_type='', REQUEST=None): """Add a new File object. Creates a new File object 'id' with the contents of 'file'""" id=str(id) title=str(title) content_type=str(content_type) precondition=str(precondition) id, title = cookId(id, title, file) self=self.this() # First, we create the file without data: self._setObject(id, File(id,title,'',content_type, precondition)) # Now we "upload" the data. By doing this in two steps, we # can use a database trick to make the upload more efficient. self._getOb(id).manage_upload(file) if content_type: self._getOb(id).content_type=content_type if REQUEST is not None: REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main') Katie
I copied the code from manage_addFileFolder so that we can upload files into the filesystem but I'd like to amend it so that we can specify the target folder rather than just having the file uploaded to the folder in which the form resides. So how do you want to specify the folder to create File object into?
How would I do that? I've looked through the code in OFS that handles this but am not sure how to add the folder as a variable.... (I;ve tried a couple of things unsuccessfully) You can simply get reference to existing folder and call _setObject on it like:
a = self.folder1.folder2.folder3 a._setObject(id, File(id,title,'',content_type, precondition)) Or if you want to have web form where you can specify target folder with path like expressions: '/folder1/folder2/folder3' you may want to use: a = '/folder1/folder2/folder3' self.restrictedTraverse(a)._setObject... If you want to create a form with a list of folders then look at plope.org on Zope Book at API Reference. There are functions like objectItems: self.objectItems( 'Folder' ) or objectItems( 'Foldered (Ordered)' ) -- Maciej Wisniowski
Kate Legere wrote at 2006-12-20 11:46 -0500:
I copied the code from manage_addFileFolder ^^^^^^^^^^^^^^^^^^^^
What is that? I do not know of a "FileFolder". Please be *VERY* careful when you write your messages. The better your message, the better can be the answers you get....
... How would I do that? I've looked through the code in OFS that handles this but am not sure how to add the folder as a variable.... (I;ve tried a couple of things unsuccessfully)
You would not use "manage_addFile" as the form action but your own action, say "myFancyAddFileAction". "myFancyAddFileAction" would use the additional destination variable (you provide via your "myFancyAddFileForm") to obtain the real destination (probably by means of "restrictedTraverse") and then call "manage_addFile" on this destination. -- Dieter
participants (3)
-
Dieter Maurer -
Kate Legere -
Maciej Wisniowski