--- versionedFile/extVersionedFile.py 2008/06/27 17:49:17 1.23 +++ versionedFile/extVersionedFile.py 2009/06/24 11:24:05 1.33 @@ -3,6 +3,7 @@ using the ExtFile Product, this version DW 11.10.2006 """ +import email from OFS.Folder import Folder from OFS.Image import File from OFS.Image import cookId @@ -142,6 +143,19 @@ class extVersionedFileFolder(Folder,ECHO ) + def redirect(self,RESPONSE,url): + """mache ein redirect mit einem angehaengten time stamp um ein reload zu erzwingen""" + + timeStamp=time.time() + + if url.find("?")>-1: #giebt es schon parameter + addStr="&time=%s" + else: + addStr="?time=%s" + + RESPONSE.setHeader('Last-Modified',email.Utils.formatdate().split("-")[0]+'GMT') + logging.error(email.Utils.formatdate()+' GMT') + RESPONSE.redirect(url+addStr%timeStamp) def changeHistoryFileNamesForm(self): """change position of version num""" pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeHistoryFileNamesForm.zpt')).__of__(self) @@ -514,7 +528,7 @@ class extVersionedFileFolder(Folder,ECHO # get new extVersionedFile vf = self._newVersionedFile(id,title=id) - logging.debug("addFile id=%s vf=%s of %s"%(repr(id),repr(vf),repr(self))) + logging.error("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) @@ -618,7 +632,7 @@ class extVersionedFileObject(ExtFile): """modify any of the objects attributes""" for arg in args: if hasattr(self, arg): - logging.debug("changeObject %s: %s = %s"%(self,arg,args[arg])) + logging.debug("changeObject %s: %s=%s"%(repr(self),arg,args[arg])) setattr(self, arg, args[arg]) security.declarePublic('getTitle') @@ -628,8 +642,28 @@ class extVersionedFileObject(ExtFile): def getData(self): """returns object content (calls ExtFile.index_html)""" - return ExtFile.index_html(self) + #logging.debug("+++++++getData1:"+repr(self.get_filename())) + filename = self.get_filename() + #return ExtFile.index_html(self) + try: + logging.info("readfile:"+filename) + return file(filename).read() + except: + logging.info("cannot readfile:"+filename) + return ExtFile.index_html(self) + + def getFileName(self): + """return filename""" + return self.get_filename() + + def addToFile(self,filehandle): + filehandle.write(self.getData()) + + def addToFile2(self,filename): + str="cat %s > %s"%(self.get_filename(),filename) + os.popen(str) + security.declarePublic('getVComment') def getVComment(self): """get the comment of this file""" @@ -692,7 +726,8 @@ class extVersionedFileObject(ExtFile): #self.REQUEST.RESPONSE.setHeader("Content-Length","str(len(txt)+1000)") self.content_type="application/octet-stream" - self.REQUEST.RESPONSE.redirect(self.absolute_url()) + return self.getData() + #self.REQUEST.RESPONSE.redirect(self.absolute_url()) #txt=urllib.urlopen(self.absolute_url()).read() #self.REQUEST.RESPONSE.write(txt) @@ -797,6 +832,8 @@ class extVersionedFile(CatalogAware,Fold self.id=id self.title=title self.lockedBy=lockedBy + if self.lockedBy is None: + self.lockedBy = '' self.author=author self.lastVersionNumber=0 self.lastVersionId=None @@ -896,6 +933,8 @@ class extVersionedFile(CatalogAware,Fold def getLockedBy(self): """get locked by""" + if self.lockedBy is None: + self.lockedBy = '' return str(self.lockedBy) def getLastVersionNumber(self): @@ -928,12 +967,12 @@ class extVersionedFile(CatalogAware,Fold lv=None for v in self.objectValues(self.content_meta_type): - logging.debug("getlastversion: check %s"%v.getId()) + #logging.debug("getlastversion: check %s"%v.getId()) if v.getVersionNumber() > tmp: tmp=v.getVersionNumber() lv=v - logging.debug("getlastversion: got %s"%lv.getId()) + #ogging.debug("getlastversion: got %s"%lv.getId()) return lv def getContentObject(self): @@ -951,6 +990,7 @@ class extVersionedFile(CatalogAware,Fold security.declarePublic('getData') def getData(self): """Returns the content of the last version""" + logging.debug("+++++++getData2") ob = self.getContentObject() if ob is not None: return ob.getData() @@ -994,7 +1034,20 @@ class extVersionedFile(CatalogAware,Fold #return "File: %s Version:%i modified:%s size:%s modified by:%s"%(self.title,lastVersion.versionNumber,lastVersion.getTime(),lastVersion.getSize(),lastVersion.lastEditor()) return self.history() - + def getVersionNr(self,nr): + """get version with number nr""" + tmp=0 + lastVersion=None + + + for version in self.ZopeFind(self): + + if hasattr(version[1],'versionNumber'): + + if int(version[1].versionNumber) ==nr : + return version[1] + + return None security.declarePublic('getVersion') def getVersion(self): # TODO: this is ugly and it returns the next version number @@ -1039,14 +1092,23 @@ class extVersionedFile(CatalogAware,Fold return vl security.declareProtected('AUTHENTICATED_USER','forceunlock') - def forceunlock(self,RESPONSE=None): + def forceunlock(self,RESPONSE=None,user=None): """unlock""" #safe who had the lock + logging.debug("extVersionFile: (forceunlock)"+str(user)) if self.lockedBy: - self.brokenLock=str(self.lockedBy) + if user is not None: + if str(self.lockedBy)==user: + self.brokenLock=str(self.lockedBy) + self.lockedBy='' + else: + self.brokenLock="" + else: + self.brokenLock=str(self.lockedBy) + self.lockedBy='' else: self.brokenLock="" - self.lockedBy='' + return self.brokenLock security.declareProtected('AUTHENTICATED_USER','unlock') @@ -1059,6 +1121,7 @@ class extVersionedFile(CatalogAware,Fold return "Sorry, not locked by you! (%s,%s)"%(self.lockedBy,self.REQUEST['AUTHENTICATED_USER']) + def _newContentObject(self, id, title='', versionNumber=0, versionComment=None, time=None, author=None): """factory for content objects. to be overridden in derived classes.""" return extVersionedFileObject(id,title,versionNumber=versionNumber,versionComment=versionComment,time=time,author=author) @@ -1186,10 +1249,10 @@ class extVersionedFile(CatalogAware,Fold def download(self): """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()) + + txt=self.REQUEST['URL1']+'/'+self.getId()+'/'+self.getContentObject().getId()+'/download' + + self.REQUEST.RESPONSE.redirect(txt) security.declareProtected('AUTHENTICATED_USER','downloadLocked')