version 1.55, 2005/12/08 17:12:21
|
version 1.74, 2010/05/12 10:58:21
|
Line 1
|
Line 1
|
from OFS.Folder import Folder |
from OFS.Folder import Folder |
from OFS.Image import File |
from OFS.Image import File |
from OFS.Image import cookId |
from OFS.Image import cookId |
|
from OFS.DTMLDocument import DTMLDocument |
from Globals import DTMLFile, InitializeClass,package_home |
from Globals import DTMLFile, InitializeClass,package_home |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
from AccessControl import getSecurityManager |
from AccessControl import getSecurityManager |
Line 9 from Products.PageTemplates.ZopePageTemp
|
Line 10 from Products.PageTemplates.ZopePageTemp
|
from AccessControl import ClassSecurityInfo |
from AccessControl import ClassSecurityInfo |
from difflib import Differ |
from difflib import Differ |
from pprint import pprint |
from pprint import pprint |
|
|
from Products.ZCatalog.CatalogPathAwareness import CatalogAware |
from Products.ZCatalog.CatalogPathAwareness import CatalogAware |
|
|
try: |
try: |
Line 23 import shutil
|
Line 23 import shutil
|
import tempfile |
import tempfile |
import os.path |
import os.path |
import urllib |
import urllib |
|
import logging |
import time |
import time |
try: |
try: |
from Products.ECHO_content.ECHO_collection import ECHO_basis |
from Products.ECHO_content.ECHO_collection import ECHO_basis |
Line 36 except:
|
Line 36 except:
|
|
|
def sortv(x,y): |
def sortv(x,y): |
return cmp(x[0],y[0]) |
return cmp(x[0],y[0]) |
|
|
tdir = "/tmp/downloadVersionedFiles" |
tdir = "/tmp/downloadVersionedFiles" |
|
|
class generateDownloadZip: |
class generateDownloadZip: |
Line 63 class generateDownloadZip:
|
Line 64 class generateDownloadZip:
|
if not os.path.exists(tmpPath): |
if not os.path.exists(tmpPath): |
os.mkdir(tmpPath) |
os.mkdir(tmpPath) |
|
|
|
tempfile.tempdir=storeTempDir |
self.response="<h3>1. step: getting the files</h3>" |
self.response="<h3>1. step: getting the files</h3>" |
|
|
for files in self.folder.ZopeFind(self.folder,obj_metatypes=['versionedFile']): |
for files in self.folder.ZopeFind(self.folder,obj_metatypes=['versionedFile']): |
Line 71 class generateDownloadZip:
|
Line 73 class generateDownloadZip:
|
|
|
savePath=os.path.join(tmpPath,lastV.title) |
savePath=os.path.join(tmpPath,lastV.title) |
fh=file(savePath,"w") |
fh=file(savePath,"w") |
fh.write(lastV.data) |
logging.debug("writing file %1 data in %s"%(lastV.title,savePath)) |
|
# loop to get OFS.Image.File data |
|
data=lastV.data |
|
if isinstance(data, str): |
|
fh.write(data) |
|
else: |
|
while data is not None: |
|
fh.write(data.data) |
|
data=data.next |
|
|
fh.close() |
fh.close() |
|
|
self.response+="<h3>2. step: creating the downloadable file</h3>" |
self.response+="<h3>2. step: creating the downloadable file</h3>" |
Line 131 class versionedFileFolder(Folder,ECHO_ba
|
Line 142 class versionedFileFolder(Folder,ECHO_ba
|
{'label':'Generate Index.html','action':'generateIndexHTML'}, |
{'label':'Generate Index.html','action':'generateIndexHTML'}, |
{'label':'Generate Image Index.html','action':'generateIndexHTML_image'}, |
{'label':'Generate Image Index.html','action':'generateIndexHTML_image'}, |
{'label':'Generate history_template.html','action':'generateHistoryHTML'}, |
{'label':'Generate history_template.html','action':'generateHistoryHTML'}, |
|
{'label':'Generate addFileForm','action':'generateAddFileForm'}, |
{'label':'Import Folder','action':'importFolderForm'}, |
{'label':'Import Folder','action':'importFolderForm'}, |
{'label':'Export Folder','action':'exportFolder'}, |
{'label':'Export Folder','action':'exportFolder'}, |
{'label':'Position of version number','action':'changeHistoryFileNamesForm'}, |
{'label':'Position of version number','action':'changeHistoryFileNamesForm'}, |
) |
) |
|
|
|
|
def changeHistoryFileNamesForm(self): |
def changeHistoryFileNamesForm(self): |
"""change position of version num""" |
"""change position of version num""" |
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeHistoryFileNamesForm.zpt')).__of__(self) |
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeHistoryFileNamesForm.zpt')).__of__(self) |
Line 299 class versionedFileFolder(Folder,ECHO_ba
|
Line 312 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.html']): |
|
zt=ZopePageTemplate('addFileForm.html') |
|
self._setObject('addFileForm.html',zt) |
|
default_content_fn = os.path.join(package_home(globals()), |
|
'zpt/fileAdd_template.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 400 class versionedFileFolder(Folder,ECHO_ba
|
Line 433 class versionedFileFolder(Folder,ECHO_ba
|
|
|
|
|
def header_html(self): |
def header_html(self): |
"""zusätzlicher header""" |
"""zusaetzlicher header""" |
ext=self.ZopeFind(self,obj_ids=["header.html"]) |
ext=self.ZopeFind(self,obj_ids=["header.html"]) |
if ext: |
if ext: |
return ext[0][1]() |
return ext[0][1]() |
Line 419 class versionedFileFolder(Folder,ECHO_ba
|
Line 452 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=getattr(self,'addFileForm.html',None) |
|
logging.error("Found %s"%ext) |
if ext: |
if ext: |
return ext[0][1]('',globals(),version='1',AUTHENTICATED_USER=self.REQUEST.AUTHENTICATED_USER) |
out=ext |
|
else: |
|
|
out=DTMLFile('dtml/newFileAdd', globals(),Kind='VersionedFileObject',kind='versionedFileObject',version='1').__of__(self) |
out=DTMLFile('dtml/newFileAdd', globals(),Kind='VersionedFileObject',kind='versionedFileObject',version='1').__of__(self) |
return out() |
return out() |
Line 518 class versionedFileObject(File):
|
Line 554 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 597 class versionedFileObject(File):
|
Line 640 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 621 class versionedFileObject(File):
|
Line 665 class versionedFileObject(File):
|
"""get version""" |
"""get version""" |
return self.versionNumber |
return self.versionNumber |
|
|
security.declarePublic('getVersionComment') |
|
def getVersionComment(self): |
|
"""get version""" |
|
return self.versionComment |
|
|
|
|
|
|
|
Line 638 class versionedFileObject(File):
|
Line 678 class versionedFileObject(File):
|
except:#old version of versionded file sometimes stored the user object and not only the name the following corrects this |
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=str(self.author).replace("-","\n") |
ret=ret.replace("\r","\n") |
ret=ret.replace("\r","\n") |
return ret |
return ret.lstrip().rstrip() |
|
|
else: |
else: |
jar=self._p_jar |
jar=self._p_jar |
Line 693 class versionedFile(CatalogAware,Folder)
|
Line 733 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 753 class versionedFile(CatalogAware,Folder)
|
Line 800 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 783 class versionedFile(CatalogAware,Folder)
|
Line 830 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 |
|
|
|
def getLockedBy(self): |
|
"""get locked by""" |
|
return str(self.lockedBy) |
|
|
|
security.declarePublic('getLastVersion') |
def getLastVersion(self): |
def getLastVersion(self): |
"""Last Version""" |
"""Last Version""" |
tmp=0 |
tmp=0 |
Line 801 class versionedFile(CatalogAware,Folder)
|
Line 867 class versionedFile(CatalogAware,Folder)
|
lastVersion.versionNumber=1 |
lastVersion.versionNumber=1 |
return lastVersion |
return lastVersion |
|
|
|
def getVersionNr(self,nr): |
|
"""Last Version""" |
|
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 |
def diff(self,data): |
def diff(self,data): |
"""differenz between lastversion and data""" |
"""differenz between lastversion and data""" |
d=Differ() |
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 |
#print "XX",data,tmp |
|
|
|
try: |
l=list(d.compare(data.splitlines(1),tmp.splitlines(1))) |
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 |
plus=0 |
minus=0 |
minus=0 |
|
|
for a in l: |
for a in l: |
if a[0]=='+': |
if a[0]=='+': |
plus+=1 |
plus+=1 |
Line 819 class versionedFile(CatalogAware,Folder)
|
Line 910 class versionedFile(CatalogAware,Folder)
|
|
|
|
|
return max([plus,minus]),l |
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 860 class versionedFile(CatalogAware,Folder)
|
Line 953 class versionedFile(CatalogAware,Folder)
|
return ret |
return ret |
|
|
security.declareProtected('AUTHENTICATED_USER','forceunlock') |
security.declareProtected('AUTHENTICATED_USER','forceunlock') |
def forceunlock(self,RESPONSE): |
def forceunlock(self,RESPONSE=None): |
"""unlock""" |
"""unlock""" |
|
#safe who had the lock |
|
if self.lockedBy: |
|
self.brokenLock=str(self.lockedBy) |
|
else: |
|
self.brokenLock="" |
self.lockedBy='' |
self.lockedBy='' |
|
return self.brokenLock |
|
|
security.declareProtected('AUTHENTICATED_USER','unlock') |
security.declareProtected('AUTHENTICATED_USER','unlock') |
def unlock(self,RESPONSE): |
def unlock(self,RESPONSE): |
"""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 882 class versionedFile(CatalogAware,Folder)
|
Line 981 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=='') or (self.lockedBy==None): |
|
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 928 class versionedFile(CatalogAware,Folder)
|
Line 1031 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 964 class versionedFile(CatalogAware,Folder)
|
Line 1071 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 |