--- versionedFile/versionedFile.py 2006/05/21 17:40:38 1.58 +++ versionedFile/versionedFile.py 2006/10/04 07:35:27 1.68 @@ -9,7 +9,6 @@ from Products.PageTemplates.ZopePageTemp from AccessControl import ClassSecurityInfo from difflib import Differ from pprint import pprint - from Products.ZCatalog.CatalogPathAwareness import CatalogAware try: @@ -136,6 +135,7 @@ class versionedFileFolder(Folder,ECHO_ba {'label':'Position of version number','action':'changeHistoryFileNamesForm'}, ) + def changeHistoryFileNamesForm(self): """change position of version num""" pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeHistoryFileNamesForm.zpt')).__of__(self) @@ -539,6 +539,8 @@ class versionedFileObject(File): manage_editForm._setName('manage_editForm') + + security.declarePublic('getTitle') def getTitle(self): @@ -665,7 +667,7 @@ class versionedFileObject(File): except:#old version of versionded file sometimes stored the user object and not only the name the following corrects this ret=str(self.author).replace("-","\n") ret=ret.replace("\r","\n") - return ret + return ret.lstrip().rstrip() else: jar=self._p_jar @@ -720,6 +722,9 @@ class versionedFile(CatalogAware,Folder) default_catalog='fileCatalog' + security= ClassSecurityInfo() + + security.declarePublic('getTitle') def getTitle(self): """get title""" return self.title @@ -784,7 +789,7 @@ class versionedFile(CatalogAware,Folder) else: return images - + security.declarePublic('getComment') def getComment(self): """get the comment of this file""" if not hasattr(self,'comment') or (not self.comment) or (self.comment.lstrip()==""): @@ -813,7 +818,26 @@ class versionedFile(CatalogAware,Folder) self.comment_date=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()) return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url()) + + security.declarePublic('getLastChangeDate') + def getLastChangeDate(self): + """get last change date""" + lv=self.getLastVersion() + time=lv.getTime() + return time + + def getLastEditor(self): + """get last change date""" + lv=self.getLastVersion() + le=lv.lastEditor() + return le + + def getLockedBy(self): + """get locked by""" + return str(self.lockedBy) + + security.declarePublic('getLastVersion') def getLastVersion(self): """Last Version""" tmp=0 @@ -836,12 +860,24 @@ class versionedFile(CatalogAware,Folder) def diff(self,data): """differenz between lastversion and data""" d=Differ() - tmp=self.getLastVersion().data + data=data.rstrip() + try: + tmp=self.getLastVersion().data.rstrip() + except: + tmp=str(self.getLastVersion().data).rstrip() #print "XX",data,tmp - l=list(d.compare(data.splitlines(1),tmp.splitlines(1))) - + + try: + l=list(d.compare(data.splitlines(1),tmp.splitlines(1))) + except: + try: + l=list(d.compare(repr(data).splitlines(1),tmp.splitlines(1))) + except: + return 9999,[] + plus=0 minus=0 + for a in l: if a[0]=='+': plus+=1 @@ -850,13 +886,13 @@ class versionedFile(CatalogAware,Folder) return max([plus,minus]),l - + security.declarePublic('index_html') def index_html(self): """main view""" lastVersion=self.getLastVersion() #return "File:"+self.title+" Version:%i"%lastVersion.versionNumber," modified:",lastVersion.bobobase_modification_time()," size:",lastVersion.getSize(),"modified by:",lastVersion.lastEditor() return "File: %s Version:%i modified:%s size:%s modified by:%s"%(self.title,lastVersion.versionNumber,lastVersion.getTime(),lastVersion.getSize(),lastVersion.lastEditor()) - security= ClassSecurityInfo() + security.declarePublic('getVersion') @@ -893,9 +929,15 @@ class versionedFile(CatalogAware,Folder) return ret security.declareProtected('AUTHENTICATED_USER','forceunlock') - def forceunlock(self,RESPONSE): + def forceunlock(self,RESPONSE=None): """unlock""" + #safe who had the lock + if self.lockedBy: + self.brokenLock=str(self.lockedBy) + else: + self.brokenLock="" self.lockedBy='' + return self.brokenLock security.declareProtected('AUTHENTICATED_USER','unlock') def unlock(self,RESPONSE): @@ -916,9 +958,9 @@ class versionedFile(CatalogAware,Folder) if str(self.REQUEST['AUTHENTICATED_USER']) in ["Anonymous User"]: return "please login first" if (self.lockedBy==self.REQUEST['AUTHENTICATED_USER']) or (self.lockedBy==''): - ext=self.ZopeFind(self,obj_ids=["addNewVersion.dtml"]) + ext=self.ZopeFind(self.aq_parent,obj_ids=["addNewVersion.dtml"]) if ext: - return ext[0][1]('',globals(),version='1',AUTHENTICATED_USER=self.REQUEST.AUTHENTICATED_USER) + return ext[0][1]('',globals(),version=self.getVersion(),lastComment=self.getLastVersion().getVersionComment(),AUTHENTICATED_USER=self.REQUEST.AUTHENTICATED_USER) else: out=DTMLFile('dtml/fileAdd', globals(),Kind='VersionedFileObject',kind='versionedFileObject',version=self.getVersion()).__of__(self) return out() @@ -965,6 +1007,10 @@ class versionedFile(CatalogAware,Folder) objs=self.ZopeFind(self,obj_ids=[id])[0][1].setVersionNumber(int(self.getVersion())) self.REQUEST.SESSION['objID_parent']=self.getId() + if getattr(self,'defaultFileCatalog',None): + + self.reindex_object() + if RESPONSE: obj=self.ZopeFind(self,obj_ids=[id])[0][1] if obj.getSize()==0: @@ -1028,4 +1074,4 @@ def manage_addVersionedFile(self,id,titl InitializeClass(versionedFile) -InitializeClass(versionedFileFolder) +InitializeClass(versionedFileFolder) \ No newline at end of file