version 1.10, 2007/09/14 12:06:55
|
version 1.22, 2008/06/27 17:46:45
|
Line 135 class extVersionedFileFolder(Folder,ECHO
|
Line 135 class extVersionedFileFolder(Folder,ECHO
|
{'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':'Import Folder','action':'importFolderForm'}, |
{'label':'Import directory','action':'importFolderForm'}, |
{'label':'Export Folder','action':'exportFolder'}, |
{'label':'Export as file','action':'exportFolder'}, |
|
{'label':'Import versionedFileFolder','action':'importVersionedFileFolderForm'}, |
{'label':'Position of version number','action':'changeHistoryFileNamesForm'}, |
{'label':'Position of version number','action':'changeHistoryFileNamesForm'}, |
) |
) |
|
|
Line 217 class extVersionedFileFolder(Folder,ECHO
|
Line 218 class extVersionedFileFolder(Folder,ECHO
|
|
|
for (vfn, vf) in vff.getVersionedFiles(): |
for (vfn, vf) in vff.getVersionedFiles(): |
if vf.meta_type == 'versionedFile': |
if vf.meta_type == 'versionedFile': |
|
logging.error("importvff: importing %s of type %s!"%(vfn,vf.meta_type)) |
title = vf.title |
title = vf.title |
author = vf.author |
fob = vf.getLastVersion() |
vc = getattr(vf.comment, "") |
author = fob.getLastEditor() |
|
vc = fob.getVersionComment() |
# save file to filesystem |
# save file to filesystem |
savePath=os.path.join(tmpPath,title) |
savePath=os.path.join(tmpPath,title) |
fh=file(savePath,"w") |
fh=file(savePath,"w") |
fh.write(lastV.getData()) |
data = vf.getLastVersion().data |
|
if isinstance(data, str): |
|
# simple data object |
|
fh.write(data) |
|
else: |
|
# chained data objects |
|
while data is not None: |
|
fh.write(data.data) |
|
data = data.next |
fh.close() |
fh.close() |
# and read in again |
# and read in again |
fh = file(savePath) |
fh = file(savePath) |
|
logging.error("importvff: comment=%s author=%s!"%(vc,author)) |
self.addFile(vC=vc, file=fh, author=author) |
self.addFile(vC=vc, file=fh, author=author) |
|
# copy more fields |
|
newfob = getattr(self, vfn).getContentObject() |
|
newfob.vComment = fob.vComment |
|
newfob.time = fob.time |
|
logging.error("importvff: vc=%s time=%s of %s!"%(fob.vComment,fob.time,fob.getId())) |
|
|
else: |
else: |
logging.error("importvff: unable to import %s of type %s!"%(vfn,vf.meta_type)) |
logging.error("importvff: unable to import %s of type %s!"%(vfn,vf.meta_type)) |
Line 492 class extVersionedFileFolder(Folder,ECHO
|
Line 509 class extVersionedFileFolder(Folder,ECHO
|
else: |
else: |
id=newName |
id=newName |
|
|
if not vC: |
if vC is None: |
vC=self.REQUEST.form['vC'] |
vC=self.REQUEST.form['vC'] |
|
|
# get new extVersionedFile |
# get new extVersionedFile |
vf = self._newVersionedFile(id,title=id) |
vf = self._newVersionedFile(id,title=id) |
#if (getattr(self,'commentNonEmpty',0)==1) and vC.strip()=="": |
logging.debug("addFile id=%s vf=%s of %s"%(repr(id),repr(vf),repr(self))) |
# add file to this folder |
# 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) |
self._setObject(id,vf) |
self._setObject(id,vf) |
# add its content |
|
logging.info("ADD: %s"%repr(vf)) |
|
obj=vf.addContentObject(id,vC,author=author,file=file,content_type=content_type,from_tmp=isRealFile) |
|
|
|
|
try: |
self.REQUEST.SESSION['objID']=vf.getId() |
self.REQUEST.SESSION['objID']=vf.getId() |
self.REQUEST.SESSION['objID_parent']=None |
self.REQUEST.SESSION['objID_parent']=None |
|
except: |
|
pass |
|
|
if obj.getSize()==0: |
if obj.getSize()==0: |
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','errorUploadFile')).__of__(self) |
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','errorUploadFile')).__of__(self) |
Line 538 class extVersionedFileFolder(Folder,ECHO
|
Line 557 class extVersionedFileFolder(Folder,ECHO
|
"""fix last version number of all files""" |
"""fix last version number of all files""" |
for (id,vf) in self.getVersionedFiles(): |
for (id,vf) in self.getVersionedFiles(): |
vf.fixVersionNumbers() |
vf.fixVersionNumbers() |
|
# recursively |
|
for (id,vf) in self.objectItems(self.meta_type): |
|
vf.fixVersionNumbers() |
|
|
|
|
manage_addextVersionedFileFolderForm=DTMLFile('dtml/extfolderAdd', globals()) |
manage_addextVersionedFileFolderForm=DTMLFile('dtml/extfolderAdd', globals()) |
Line 591 class extVersionedFileObject(ExtFile):
|
Line 613 class extVersionedFileObject(ExtFile):
|
self.time = time |
self.time = time |
self.author = author |
self.author = author |
|
|
|
security.declareProtected('manage','changeObject') |
|
def changeObject(self,**args): |
|
"""modify object""" |
|
for arg in args: |
|
if hasattr(self, arg): |
|
logging.debug("changeObject arg:%s = %s"%(arg,args[arg])) |
|
setattr(self, arg, args[arg]) |
|
|
security.declarePublic('getTitle') |
security.declarePublic('getTitle') |
def getTitle(self): |
def getTitle(self): |
Line 670 class extVersionedFileObject(ExtFile):
|
Line 699 class extVersionedFileObject(ExtFile):
|
|
|
#self.REQUEST.close() |
#self.REQUEST.close() |
|
|
|
view = download |
|
|
security.declareProtected('AUTHENTICATED_USER','downloadLocked') |
security.declareProtected('AUTHENTICATED_USER','downloadLocked') |
def downloadLocked(self): |
def downloadLocked(self): |
"""download and lock""" |
"""download and lock""" |
Line 753 class extVersionedFile(CatalogAware,Fold
|
Line 784 class extVersionedFile(CatalogAware,Fold
|
meta_type = 'extVersionedFile' |
meta_type = 'extVersionedFile' |
# meta_type of contained objects |
# meta_type of contained objects |
content_meta_type = ['extVersionedFileObject'] |
content_meta_type = ['extVersionedFileObject'] |
|
# default catalog for extVersionedFile objects |
default_catalog = 'fileCatalog' |
default_catalog = 'fileCatalog' |
|
|
|
manage_options = Folder.manage_options+({'label':'Main Config','action':'changeVersionedFileForm'},) |
|
|
|
|
security=ClassSecurityInfo() |
security=ClassSecurityInfo() |
|
|
def __init__(self, id, title, lockedBy,author): |
def __init__(self, id, title, lockedBy,author): |
Line 848 class extVersionedFile(CatalogAware,Fold
|
Line 883 class extVersionedFile(CatalogAware,Fold
|
def getLastChangeDate(self): |
def getLastChangeDate(self): |
"""get last change date""" |
"""get last change date""" |
lv=self.getContentObject() |
lv=self.getContentObject() |
|
if lv: |
time=lv.getTime() |
time=lv.getTime() |
return time |
return time |
|
return None |
|
|
def getLastEditor(self): |
def getLastEditor(self): |
"""get last change date""" |
"""get last change date""" |
Line 901 class extVersionedFile(CatalogAware,Fold
|
Line 938 class extVersionedFile(CatalogAware,Fold
|
|
|
def getContentObject(self): |
def getContentObject(self): |
"""returns the last version object""" |
"""returns the last version object""" |
if not self.lastVersionId: |
if not getattr(self, 'lastVersionId', None): |
|
# find last version and save it |
lv = self.findLastVersion() |
lv = self.findLastVersion() |
if lv is None: |
if lv is None: |
return None |
return None |
self.lastVersionNumber = lv.getVersionNumber() |
self.lastVersionNumber = lv.getVersionNumber() |
self.lastVersionId = lv.getId() |
self.lastVersionId = lv.getId() |
|
|
return getattr(self, self.lastVersionId) |
return getattr(self, self.lastVersionId, None) |
|
|
security.declarePublic('getData') |
security.declarePublic('getData') |
def getData(self): |
def getData(self): |
Line 919 class extVersionedFile(CatalogAware,Fold
|
Line 957 class extVersionedFile(CatalogAware,Fold
|
else: |
else: |
return None |
return None |
|
|
|
security.declarePublic('view') |
|
def view(self,REQUEST=None,RESPONSE=None): |
|
"""Returns the last version's view""" |
|
ob = self.getContentObject() |
|
if ob is not None: |
|
return ob.view(REQUEST=REQUEST,RESPONSE=RESPONSE) |
|
else: |
|
return None |
|
|
def diff(self,data): |
def diff(self,data): |
"""differenz between lastversion and data""" |
"""differenz between lastversion and data""" |
d=Differ() |
d=Differ() |
Line 978 class extVersionedFile(CatalogAware,Fold
|
Line 1025 class extVersionedFile(CatalogAware,Fold
|
ret.sort(sortv) |
ret.sort(sortv) |
return ret |
return ret |
|
|
|
def getVersionList(self): |
|
"""get a list of dicts with author, comment, filename, etc, of all versions""" |
|
vl = [] |
|
for v in self.objectValues(self.content_meta_type): |
|
vl.append({'versionNumber':getattr(v,'versionNumber',0), |
|
'title':v.getTitle(), |
|
'id':v.getId(), |
|
'date':v.getTime(), |
|
'author':getattr(v,'author',''), |
|
'comment':getattr(v,'versionComment','') |
|
}) |
|
return vl |
|
|
security.declareProtected('AUTHENTICATED_USER','forceunlock') |
security.declareProtected('AUTHENTICATED_USER','forceunlock') |
def forceunlock(self,RESPONSE=None): |
def forceunlock(self,RESPONSE=None): |
"""unlock""" |
"""unlock""" |
Line 1004 class extVersionedFile(CatalogAware,Fold
|
Line 1064 class extVersionedFile(CatalogAware,Fold
|
return extVersionedFileObject(id,title,versionNumber=versionNumber,versionComment=versionComment,time=time,author=author) |
return extVersionedFileObject(id,title,versionNumber=versionNumber,versionComment=versionComment,time=time,author=author) |
|
|
|
|
def addContentObject(self,id,vC,author=None,file=None,title='',changeName='no',newName='',from_tmp=False, |
def addContentObject(self,id,vC,author=None,file=None,title='',changeName='no',newName='',from_tmp=False,index=True, |
precondition='', content_type=''): |
precondition='', content_type=''): |
"""add""" |
"""add""" |
|
|
Line 1053 class extVersionedFile(CatalogAware,Fold
|
Line 1113 class extVersionedFile(CatalogAware,Fold
|
self.lastVersionId = id |
self.lastVersionId = id |
|
|
#logging.debug("addcontentobject: lastversion=%s"%self.getData()) |
#logging.debug("addcontentobject: lastversion=%s"%self.getData()) |
|
#logging.debug("addcontentobject: fob_data=%s"%fob.getData()) |
|
if index and self.default_catalog: |
logging.debug("reindex1: %s in %s"%(repr(self),repr(self.default_catalog))) |
logging.debug("reindex1: %s in %s"%(repr(self),repr(self.default_catalog))) |
self.reindex_object() |
self.reindex_object() |
#logging.debug("addcontentobject: fob_data=%s"%fob.getData()) |
|
|
|
return fob |
return fob |
|
|
Line 1098 class extVersionedFile(CatalogAware,Fold
|
Line 1159 class extVersionedFile(CatalogAware,Fold
|
return pt() |
return pt() |
|
|
else: |
else: |
RESPONSE.redirect(self.REQUEST['URL2']) |
RESPONSE.redirect(self.absolute_url()+'/history') |
else: |
else: |
return ob |
return ob |
|
|
|
|
|
changeVersionedFileForm = PageTemplateFile('zpt/changeVersionedFile', globals()) |
|
|
|
def manage_changeVersionedFile(self,title,vC,author,comment,RESPONSE=None): |
|
"""Change VersionedFile metadata""" |
|
self.title = title |
|
self.author = author |
|
cob = self.getContentObject() |
|
if cob: |
|
if vC: |
|
cob.vComment=vC |
|
|
|
if comment=='': |
|
cob.versionComment=None |
|
else: |
|
cob.versionComment=comment |
|
|
|
if RESPONSE: |
|
RESPONSE.redirect('manage_main') |
|
|
|
|
def download(self): |
def download(self): |
"""download and lock""" |
"""download""" |
self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getContentObject().getId()) |
self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getContentObject().getId()) |
self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") |
self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") |
self.content_type="application/octet-stream" |
self.content_type="application/octet-stream" |
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'/'+self.getId()+'/'+self.getContentObject().getId()) |
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'/'+self.getId()+'/'+self.getContentObject().getId()) |
|
|
|
|
security.declareProtected('AUTHENTICATED_USER','downloadLocked') |
security.declareProtected('AUTHENTICATED_USER','downloadLocked') |
def downloadLocked(self): |
def downloadLocked(self): |
"""download and lock""" |
"""download and lock""" |