def attachFile(self, file, id='', title='', precondition='', content_type='', REQUEST=None): """ Attach a new File object. Creates a new File object 'id' with the contents of 'file' """ title = str(title) id = str(id) content_type=str(content_type) precondition=str(precondition) # Extract id and title from file # Code below is actually a rip-off from Image.py :)) if not id and hasattr(file,'filename'): filename=file.filename title=title or filename id=filename[max(filename.rfind('/'), filename.rfind('\\'), filename.rfind(':'),)+1:] # First, we re-create the file without data: self.attachedDocument = img.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. if file: self.attachedDocument.manage_upload(file) if content_type: self.attachedDocument.content_type=content_type # tell to Zope mechanism that CCRazpis object has changed self._p_changed = True # append file to fileList self.fileList.append(self.attachedDocument) return self.manage_editCCRazpisForm(self, REQUEST)