--- versionedFile/extVersionedFile.py 2007/09/10 17:40:37 1.8 +++ versionedFile/extVersionedFile.py 2007/09/10 19:27:55 1.9 @@ -29,6 +29,7 @@ import os.path import urllib import time import logging +import types try: from Products.ECHO_content.ECHO_collection import ECHO_basis @@ -433,8 +434,16 @@ class extVersionedFileFolder(Folder,ECHO def addFile(self,vC,file,author='',newName='',content_type='',RESPONSE=None): """ add a new file""" + # is file is a real file or a zope download object? + isRealFile = type(file) is types.FileType + if newName=='': - filename=file.filename + logging.debug("fileobject: %s real:%s"%(repr(file),repr(isRealFile))) + if isRealFile: + filename = file.name + else: + filename=file.filename + id=filename[max(filename.rfind('/'), filename.rfind('\\'), filename.rfind(':'), @@ -443,17 +452,17 @@ class extVersionedFileFolder(Folder,ECHO else: id=newName - vC=self.REQUEST.form['vC'] + if not vC: + vC=self.REQUEST.form['vC'] # get new extVersionedFile vf = self._newVersionedFile(id,title=id) #if (getattr(self,'commentNonEmpty',0)==1) and vC.strip()=="": # add file to this folder self._setObject(id,vf) - file2=file # add its content logging.info("ADD: %s"%repr(vf)) - obj=vf.addContentObject(id,vC,author=author,file=file2,content_type=content_type) + obj=vf.addContentObject(id,vC,author=author,file=file,content_type=content_type,from_tmp=isRealFile) self.REQUEST.SESSION['objID']=vf.getId() self.REQUEST.SESSION['objID_parent']=None @@ -462,7 +471,8 @@ class extVersionedFileFolder(Folder,ECHO pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','errorUploadFile')).__of__(self) return pt() - RESPONSE.redirect(self.REQUEST['URL1']) + if RESPONSE is not None: + RESPONSE.redirect(self.REQUEST['URL1']) def _newVersionedFile(self, id, title='', lockedBy=None, author=None): @@ -1002,10 +1012,10 @@ class extVersionedFile(CatalogAware,Fold self.lastVersionNumber = versNum self.lastVersionId = id - logging.debug("addcontentobject: lastversion=%s"%self.getData()) + #logging.debug("addcontentobject: lastversion=%s"%self.getData()) logging.debug("reindex1: %s in %s"%(repr(self),repr(self.default_catalog))) self.reindex_object() - logging.debug("addcontentobject: fob_data=%s"%fob.getData()) + #logging.debug("addcontentobject: fob_data=%s"%fob.getData()) return fob