--- versionedFile/versionedFile.py 2005/03/03 13:09:30 1.29 +++ versionedFile/versionedFile.py 2005/03/31 16:44:23 1.34 @@ -15,8 +15,8 @@ try: except: print "ECHO Elements not imported" class ECHO_basis: - """leer""" - manage_options=() + """leer""" + manage_options=() def sortv(x,y): @@ -87,6 +87,9 @@ class versionedFileFolder(Folder,ECHO_ba if RESPONSE is not None: RESPONSE.redirect('manage_main') + + + def getVersionedFiles(self,sortField='title'): """get all versioned files""" @@ -96,9 +99,40 @@ class versionedFileFolder(Folder,ECHO_ba def sortDate(x,y): return cmp(y[1].getLastVersion().getTime(),x[1].getLastVersion().getTime()) + + def sortComment(x,y): + + + + try: + xc=getattr(x[1],'comment','ZZZZZZZZZZZZZ').lower() + except: + xc='ZZZZZZZZZZZZZ'.lower() + try: + yc=getattr(y[1],'comment','ZZZZZZZZZZZZZ').lower() + except: + yc='ZZZZZZZZZZZZZ'.lower() + + + if (xc=='') or (xc=='ZZZZZZZZZZZZZ'.lower()): + + try: + xc=x[1].getLastVersion().getVComment().lower() + except: + xc='ZZZZZZZZZZZZZ'.lower() + + if (yc=='') or (yc=='ZZZZZZZZZZZZZ'.lower()): + try: + yc=y[1].getLastVersion().getVComment().lower() + except: + yc='ZZZZZZZZZZZZZ'.lower() + + + return cmp(xc,yc) + def sortAuthor(x,y): - return cmp(x[1].getLastVersion().lastEditor(),y[1].getLastVersion().lastEditor()) + return cmp(x[1].getLastVersion().lastEditor().lower(),y[1].getLastVersion().lastEditor().lower()) versionedFiles=self.ZopeFind(self,obj_metatypes=['versionedFile']) @@ -108,6 +142,8 @@ class versionedFileFolder(Folder,ECHO_ba versionedFiles.sort(sortDate) elif sortField=='author': versionedFiles.sort(sortAuthor) + elif sortField=='comment': + versionedFiles.sort(sortComment) return versionedFiles @@ -228,6 +264,41 @@ class versionedFileObject(File): Kind='File',kind='file') manage_editForm._setName('manage_editForm') + def getVComment(self): + """get the comment of this file""" + if not hasattr(self,'vComment') or (not self.vComment) or (self.vComment.lstrip()==""): + return "Add comment" + + else: + return self.vComment + + def manageVCommentForm(self): + """add a comment""" + + self.REQUEST.SESSION['refer']=self.REQUEST['HTTP_REFERER'] + + + + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addVComment')).__of__(self) + return pt() + + def manageVComment(self,text,comment_author,submit,REQUEST=None): + """manage comments""" + if submit =='change': + if text=='': + self.vComment=None + else: + self.vComment=text + self.vComment_author=comment_author + + self.vComment_date=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()) + + if self.REQUEST.SESSION.has_key('refer'): + + return REQUEST.RESPONSE.redirect(self.REQUEST.SESSION['refer']) + return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url()+"/history") + + def getTime(self): """getTime""" #return self.bobobase_modification_time().ISO() @@ -246,9 +317,14 @@ class versionedFileObject(File): def download(self): """download and lock""" - + self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getId()) + self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") + self.content_type="application/octet-stream" - self.REQUEST.RESPONSE.redirect(self.absolute_url()) + #self.REQUEST.RESPONSE.redirect(self.absolute_url()) + self.REQUEST.RESPONSE.write(self.index_html()) + #self.REQUEST.RESPONSE.write("bl") + self.REQUEST.close() def downloadLocked(self): """download and lock""" @@ -271,10 +347,15 @@ class versionedFileObject(File): """get version""" return self.versionNumber + + def lastEditor(self): """last Editor""" if hasattr(self,'author'): - return self.author + ret=self.author.replace("-","\n") + ret=ret.replace("\r","\n") + return ret + else: jar=self._p_jar oid=self._p_oid @@ -332,7 +413,15 @@ class versionedFile(Folder): self.title=title self.lockedBy=lockedBy self.author=author - + + def getComment(self): + """get the comment of this file""" + if not hasattr(self,'comment') or (not self.comment) or (self.comment.lstrip()==""): + return "Add comment" + + else: + return self.comment + meta_type="versionedFile" @@ -475,8 +564,17 @@ class versionedFile(Folder): def download(self): """download and lock""" - self.getLastVersion().content_type="application/octet-stream" - self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'/'+self.getId()+'/'+self.getLastVersion().getId()) + + self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getLastVersion().getId()) + self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") + + self.content_type="application/octet-stream" + #self.REQUEST.RESPONSE.write("bl") + self.REQUEST.RESPONSE.write(self.getLastVersion().index_html()) + self.REQUEST.close() + + #self.getLastVersion().content_type="application/octet-stream" + #self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'/'+self.getId()+'/'+self.getLastVersion().getId()) def downloadLocked(self): """download and lock"""