version 1.52, 2005/11/21 20:03:31
|
version 1.61, 2006/06/15 22:01:59
|
Line 7 from AccessControl import getSecurityMan
|
Line 7 from AccessControl import getSecurityMan
|
from Products.PageTemplates.PageTemplate import PageTemplate |
from Products.PageTemplates.PageTemplate import PageTemplate |
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
from AccessControl import ClassSecurityInfo |
from AccessControl import ClassSecurityInfo |
|
from difflib import Differ |
|
from pprint import pprint |
|
|
from Products.ZCatalog.CatalogPathAwareness import CatalogAware |
from Products.ZCatalog.CatalogPathAwareness import CatalogAware |
|
|
Line 169 class versionedFileFolder(Folder,ECHO_ba
|
Line 170 class versionedFileFolder(Folder,ECHO_ba
|
else: |
else: |
id=tmp[0]+"_"+version[1].getId().split("_")[0] |
id=tmp[0]+"_"+version[1].getId().split("_")[0] |
|
|
print version[0],id |
|
|
|
version[1].aq_parent.manage_renameObjects(ids=[version[1].getId()],new_ids=[id]) |
version[1].aq_parent.manage_renameObjects(ids=[version[1].getId()],new_ids=[id]) |
version[1].title=id |
version[1].title=id |
Line 298 class versionedFileFolder(Folder,ECHO_ba
|
Line 299 class versionedFileFolder(Folder,ECHO_ba
|
if RESPONSE is not None: |
if RESPONSE is not None: |
RESPONSE.redirect('manage_main') |
RESPONSE.redirect('manage_main') |
|
|
|
|
|
def generateAddFileForm(self,RESPONSE=None): |
|
"""lege standard addfileform an""" |
|
#TODO: write generateaddfileform only a dummy at them moment |
|
|
|
if not self.ZopeFind(self,obj_ids=['addFileForm.dtml']): |
|
zt=ZopePageTemplate('index.html') |
|
self._setObject('index.html',zt) |
|
default_content_fn = os.path.join(package_home(globals()), |
|
'zpt/versionFileFolderMain.zpt') |
|
text = open(default_content_fn).read() |
|
zt.pt_edit(text, 'text/html') |
|
|
|
else: |
|
return "already exists!" |
|
|
|
if RESPONSE is not None: |
|
RESPONSE.redirect('manage_main') |
|
|
|
|
def generateIndexHTML(self,RESPONSE=None): |
def generateIndexHTML(self,RESPONSE=None): |
"""lege standard index.html an""" |
"""lege standard index.html an""" |
|
|
Line 418 class versionedFileFolder(Folder,ECHO_ba
|
Line 439 class versionedFileFolder(Folder,ECHO_ba
|
return pt() |
return pt() |
|
|
|
|
|
|
def addFileForm(self): |
def addFileForm(self): |
"""add a file""" |
"""add a file""" |
ext=self.ZopeFind(self,obj_ids=["addFileForm.dtml"]) |
ext=self.ZopeFind(self,obj_ids=["addFileForm.dtml"]) |
Line 517 class versionedFileObject(File):
|
Line 539 class versionedFileObject(File):
|
manage_editForm._setName('manage_editForm') |
manage_editForm._setName('manage_editForm') |
|
|
|
|
security.declarePublic('getVComment') |
security.declarePublic('getTitle') |
|
|
|
def getTitle(self): |
|
"""get title""" |
|
return self.title |
|
|
|
security.declarePublic('getVComment') |
def getVComment(self): |
def getVComment(self): |
"""get the comment of this file""" |
"""get the comment of this file""" |
if not hasattr(self,'vComment') or (not self.vComment) or (self.vComment.lstrip()==""): |
if not hasattr(self,'vComment') or (not self.vComment) or (self.vComment.lstrip()==""): |
Line 596 class versionedFileObject(File):
|
Line 623 class versionedFileObject(File):
|
|
|
#self.REQUEST.close() |
#self.REQUEST.close() |
|
|
|
security.declareProtected('AUTHENTICATED_USER','downloadLocked') |
def downloadLocked(self): |
def downloadLocked(self): |
"""download and lock""" |
"""download and lock""" |
|
|
|
|
if self.REQUEST['AUTHENTICATED_USER']=='Anonymous User': |
if repr(self.REQUEST['AUTHENTICATED_USER'])=='Anonymous User': |
return "please login first" |
return "please login first" |
if not self.aq_parent.lockedBy=="": |
if not self.aq_parent.lockedBy=="": |
return "cannot be locked because is already locked by %s"%self.lockedBy |
return "cannot be locked because is already locked by %s"%self.lockedBy |
Line 632 class versionedFileObject(File):
|
Line 660 class versionedFileObject(File):
|
def lastEditor(self): |
def lastEditor(self): |
"""last Editor""" |
"""last Editor""" |
if hasattr(self,'author'): |
if hasattr(self,'author'): |
|
try: |
ret=self.author.replace("-","\n") |
ret=self.author.replace("-","\n") |
|
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") |
ret=ret.replace("\r","\n") |
return ret |
return ret |
|
|
Line 689 class versionedFile(CatalogAware,Folder)
|
Line 720 class versionedFile(CatalogAware,Folder)
|
|
|
default_catalog='fileCatalog' |
default_catalog='fileCatalog' |
|
|
|
security= ClassSecurityInfo() |
|
|
|
security.declarePublic('getTitle') |
|
def getTitle(self): |
|
"""get title""" |
|
return self.title |
|
|
def PrincipiaSearchSource(self): |
def PrincipiaSearchSource(self): |
"""Return cataloguable key for ourselves.""" |
"""Return cataloguable key for ourselves.""" |
return str(self) |
return str(self) |
Line 749 class versionedFile(CatalogAware,Folder)
|
Line 787 class versionedFile(CatalogAware,Folder)
|
else: |
else: |
return images |
return images |
|
|
|
security.declarePublic('getComment') |
def getComment(self): |
def getComment(self): |
"""get the comment of this file""" |
"""get the comment of this file""" |
if not hasattr(self,'comment') or (not self.comment) or (self.comment.lstrip()==""): |
if not hasattr(self,'comment') or (not self.comment) or (self.comment.lstrip()==""): |
Line 779 class versionedFile(CatalogAware,Folder)
|
Line 817 class versionedFile(CatalogAware,Folder)
|
|
|
return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url()) |
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 |
|
|
|
|
|
|
|
security.declarePublic('getLastVersion') |
def getLastVersion(self): |
def getLastVersion(self): |
"""Last Version""" |
"""Last Version""" |
tmp=0 |
tmp=0 |
Line 797 class versionedFile(CatalogAware,Folder)
|
Line 852 class versionedFile(CatalogAware,Folder)
|
lastVersion.versionNumber=1 |
lastVersion.versionNumber=1 |
return lastVersion |
return lastVersion |
|
|
|
|
|
def diff(self,data): |
|
"""differenz between lastversion and data""" |
|
d=Differ() |
|
tmp=self.getLastVersion().data |
|
#print "XX",data,tmp |
|
l=list(d.compare(data.splitlines(1),tmp.splitlines(1))) |
|
|
|
plus=0 |
|
minus=0 |
|
for a in l: |
|
if a[0]=='+': |
|
plus+=1 |
|
if a[0]=='-': |
|
minus+=1 |
|
|
|
|
|
return max([plus,minus]),l |
|
security.declarePublic('index_html') |
def index_html(self): |
def index_html(self): |
"""main view""" |
"""main view""" |
lastVersion=self.getLastVersion() |
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:"+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()) |
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') |
security.declarePublic('getVersion') |
def getVersion(self): |
def getVersion(self): |
tmp=0 |
tmp=0 |
Line 846 class versionedFile(CatalogAware,Folder)
|
Line 922 class versionedFile(CatalogAware,Folder)
|
"""unlock""" |
"""unlock""" |
if str(self.lockedBy) in [str(self.REQUEST['AUTHENTICATED_USER'])]: |
if str(self.lockedBy) in [str(self.REQUEST['AUTHENTICATED_USER'])]: |
self.lockedBy='' |
self.lockedBy='' |
RESPONSE.redirect(self.REQUEST['URL2']) |
RESPONSE.redirect(self.REQUEST['HTTP_REFERER']) |
else: |
else: |
return "Sorry, not locked by you! (%s,%s)"%(self.lockedBy,self.REQUEST['AUTHENTICATED_USER']) |
return "Sorry, not locked by you! (%s,%s)"%(self.lockedBy,self.REQUEST['AUTHENTICATED_USER']) |
|
|
Line 860 class versionedFile(CatalogAware,Folder)
|
Line 936 class versionedFile(CatalogAware,Folder)
|
if str(self.REQUEST['AUTHENTICATED_USER']) in ["Anonymous User"]: |
if str(self.REQUEST['AUTHENTICATED_USER']) in ["Anonymous User"]: |
return "please login first" |
return "please login first" |
if (self.lockedBy==self.REQUEST['AUTHENTICATED_USER']) or (self.lockedBy==''): |
if (self.lockedBy==self.REQUEST['AUTHENTICATED_USER']) or (self.lockedBy==''): |
|
ext=self.ZopeFind(self.aq_parent,obj_ids=["addNewVersion.dtml"]) |
|
if ext: |
|
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) |
out=DTMLFile('dtml/fileAdd', globals(),Kind='VersionedFileObject',kind='versionedFileObject',version=self.getVersion()).__of__(self) |
return out() |
return out() |
else: |
else: |
Line 905 class versionedFile(CatalogAware,Folder)
|
Line 985 class versionedFile(CatalogAware,Folder)
|
objs=self.ZopeFind(self,obj_ids=[id])[0][1].setVersionNumber(int(self.getVersion())) |
objs=self.ZopeFind(self,obj_ids=[id])[0][1].setVersionNumber(int(self.getVersion())) |
self.REQUEST.SESSION['objID_parent']=self.getId() |
self.REQUEST.SESSION['objID_parent']=self.getId() |
|
|
|
if getattr(self,'defaultFileCatalog',None): |
|
|
|
self.reindex_object() |
|
|
if RESPONSE: |
if RESPONSE: |
obj=self.ZopeFind(self,obj_ids=[id])[0][1] |
obj=self.ZopeFind(self,obj_ids=[id])[0][1] |
if obj.getSize()==0: |
if obj.getSize()==0: |
Line 941 class versionedFile(CatalogAware,Folder)
|
Line 1025 class versionedFile(CatalogAware,Folder)
|
#self.getLastVersion().content_type="application/octet-stream" |
#self.getLastVersion().content_type="application/octet-stream" |
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'/'+self.getId()+'/'+self.getLastVersion().getId()) |
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'/'+self.getId()+'/'+self.getLastVersion().getId()) |
|
|
|
security.declareProtected('AUTHENTICATED_USER','downloadLocked') |
def downloadLocked(self): |
def downloadLocked(self): |
"""download and lock""" |
"""download and lock""" |
if self.REQUEST['AUTHENTICATED_USER']=='Anonymous User': |
|
|
if repr(self.REQUEST['AUTHENTICATED_USER'])=='Anonymous User': |
return "please login first" |
return "please login first" |
if not self.lockedBy=="": |
if not self.lockedBy=="": |
return "cannot be locked because is already locked by %s"%self.lockedBy |
return "cannot be locked because is already locked by %s"%self.lockedBy |