--- versionedFile/extVersionedFile.py 2007/09/14 15:08:02 1.12 +++ versionedFile/extVersionedFile.py 2008/06/27 18:20:40 1.24 @@ -514,15 +514,17 @@ class extVersionedFileFolder(Folder,ECHO # get new extVersionedFile vf = self._newVersionedFile(id,title=id) - #if (getattr(self,'commentNonEmpty',0)==1) and vC.strip()=="": - # add file to this folder + logging.debug("addFile id=%s vf=%s of %s"%(repr(id),repr(vf),repr(self))) + # add its content (and don't index) + obj=vf.addContentObject(id,vC,author=author,file=file,content_type=content_type,from_tmp=isRealFile,index=False) + # add file to this folder (this should do the indexing) self._setObject(id,vf) - # add its content - logging.info("ADD: %s"%repr(vf)) - 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 + try: + self.REQUEST.SESSION['objID']=vf.getId() + self.REQUEST.SESSION['objID_parent']=None + except: + pass if obj.getSize()==0: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','errorUploadFile')).__of__(self) @@ -555,6 +557,9 @@ class extVersionedFileFolder(Folder,ECHO """fix last version number of all files""" for (id,vf) in self.getVersionedFiles(): vf.fixVersionNumbers() + # recursively + for (id,vf) in self.objectItems(self.meta_type): + vf.fixVersionNumbers() manage_addextVersionedFileFolderForm=DTMLFile('dtml/extfolderAdd', globals()) @@ -608,6 +613,13 @@ class extVersionedFileObject(ExtFile): self.time = time self.author = author + security.declareProtected('manage','changeObject') + def changeObject(self,**args): + """modify any of the objects attributes""" + for arg in args: + if hasattr(self, arg): + logging.debug("changeObject %s: %s=%s"%(repr(self),arg,args[arg])) + setattr(self, arg, args[arg]) security.declarePublic('getTitle') def getTitle(self): @@ -687,6 +699,8 @@ class extVersionedFileObject(ExtFile): #self.REQUEST.close() + view = download + security.declareProtected('AUTHENTICATED_USER','downloadLocked') def downloadLocked(self): """download and lock""" @@ -770,8 +784,12 @@ class extVersionedFile(CatalogAware,Fold meta_type = 'extVersionedFile' # meta_type of contained objects content_meta_type = ['extVersionedFileObject'] + # default catalog for extVersionedFile objects default_catalog = 'fileCatalog' + manage_options = Folder.manage_options+({'label':'Main Config','action':'changeVersionedFileForm'},) + + security=ClassSecurityInfo() def __init__(self, id, title, lockedBy,author): @@ -865,8 +883,10 @@ class extVersionedFile(CatalogAware,Fold def getLastChangeDate(self): """get last change date""" lv=self.getContentObject() - time=lv.getTime() - return time + if lv: + time=lv.getTime() + return time + return None def getLastEditor(self): """get last change date""" @@ -918,14 +938,15 @@ class extVersionedFile(CatalogAware,Fold def getContentObject(self): """returns the last version object""" - if not self.lastVersionId: + if not getattr(self, 'lastVersionId', None): + # find last version and save it lv = self.findLastVersion() if lv is None: return None self.lastVersionNumber = lv.getVersionNumber() self.lastVersionId = lv.getId() - return getattr(self, self.lastVersionId) + return getattr(self, self.lastVersionId, None) security.declarePublic('getData') def getData(self): @@ -936,6 +957,15 @@ class extVersionedFile(CatalogAware,Fold else: return None + security.declarePublic('view') + def view(self,REQUEST=None,RESPONSE=None): + """Returns the last version's view""" + ob = self.getContentObject() + if ob is not None: + return ob.view(REQUEST=REQUEST,RESPONSE=RESPONSE) + else: + return None + def diff(self,data): """differenz between lastversion and data""" d=Differ() @@ -995,6 +1025,19 @@ class extVersionedFile(CatalogAware,Fold ret.sort(sortv) return ret + def getVersionList(self): + """get a list of dicts with author, comment, filename, etc, of all versions""" + vl = [] + for v in self.objectValues(self.content_meta_type): + vl.append({'versionNumber':getattr(v,'versionNumber',0), + 'title':v.getTitle(), + 'id':v.getId(), + 'date':v.getTime(), + 'author':getattr(v,'author',''), + 'comment':getattr(v,'versionComment','') + }) + return vl + security.declareProtected('AUTHENTICATED_USER','forceunlock') def forceunlock(self,RESPONSE=None): """unlock""" @@ -1021,7 +1064,7 @@ class extVersionedFile(CatalogAware,Fold return extVersionedFileObject(id,title,versionNumber=versionNumber,versionComment=versionComment,time=time,author=author) - def addContentObject(self,id,vC,author=None,file=None,title='',changeName='no',newName='',from_tmp=False, + def addContentObject(self,id,vC,author=None,file=None,title='',changeName='no',newName='',from_tmp=False,index=True, precondition='', content_type=''): """add""" @@ -1070,9 +1113,10 @@ class extVersionedFile(CatalogAware,Fold self.lastVersionId = id #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()) + if index and self.default_catalog: + logging.debug("reindex1: %s in %s"%(repr(self),repr(self.default_catalog))) + self.reindex_object() return fob @@ -1115,17 +1159,38 @@ class extVersionedFile(CatalogAware,Fold return pt() else: - RESPONSE.redirect(self.REQUEST['URL2']) + RESPONSE.redirect(self.absolute_url()+'/history') else: return ob + + changeVersionedFileForm = PageTemplateFile('zpt/changeVersionedFile', globals()) + + def manage_changeVersionedFile(self,title,vC,author,comment,RESPONSE=None): + """Change VersionedFile metadata""" + self.title = title + self.author = author + cob = self.getContentObject() + if cob: + if vC: + cob.vComment=vC + + if comment=='': + cob.versionComment=None + else: + cob.versionComment=comment + + if RESPONSE: + RESPONSE.redirect('manage_main') + def download(self): - """download and lock""" + """download""" self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getContentObject().getId()) self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") self.content_type="application/octet-stream" self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'/'+self.getId()+'/'+self.getContentObject().getId()) + security.declareProtected('AUTHENTICATED_USER','downloadLocked') def downloadLocked(self):