--- versionedFile/versionedFile.py 2005/06/21 08:56:04 1.36
+++ versionedFile/versionedFile.py 2005/11/21 20:05:29 1.53
@@ -8,10 +8,20 @@ from Products.PageTemplates.PageTemplate
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
from AccessControl import ClassSecurityInfo
+
+from Products.ZCatalog.CatalogPathAwareness import CatalogAware
+
+try:
+ from Products.ImageArchive.ImageArchive import manage_AddImageZogiLib
+except:
+ print "no images"
+
+
from threading import Thread
import shutil
import tempfile
import os.path
+import urllib
import time
try:
@@ -25,7 +35,7 @@ except:
def sortv(x,y):
return cmp(x[0],y[0])
-tdir = "/tmp/testia"
+tdir = "/tmp/downloadVersionedFiles"
class generateDownloadZip:
"""generateDownloadSet"""
@@ -52,7 +62,7 @@ class generateDownloadZip:
if not os.path.exists(tmpPath):
os.mkdir(tmpPath)
- self.response="
1. step: gettung the files
"
+ self.response="1. step: getting the files
"
for files in self.folder.ZopeFind(self.folder,obj_metatypes=['versionedFile']):
lastV=files[1].getLastVersion()
@@ -110,7 +120,7 @@ class versionedFileFolder(Folder,ECHO_ba
security= ClassSecurityInfo()
security.declareProtected('AUTHENTICATED_USER','addFileForm')
-
+ filesMetaType=['versionedFile']
if ECHO_basis:
optTMP= Folder.manage_options+ECHO_basis.manage_options
else:
@@ -118,11 +128,59 @@ class versionedFileFolder(Folder,ECHO_ba
manage_options =optTMP+(
{'label':'Generate Index.html','action':'generateIndexHTML'},
+ {'label':'Generate Image Index.html','action':'generateIndexHTML_image'},
{'label':'Generate history_template.html','action':'generateHistoryHTML'},
{'label':'Import Folder','action':'importFolderForm'},
{'label':'Export Folder','action':'exportFolder'},
+ {'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)
+ return pt()
+
+
+ def changeHistoryFileNames(self,positionVersionNum="front",RESPONSE=None):
+ """change position of version num"""
+
+
+
+ versions=self.ZopeFind(self,obj_metatypes=['versionedFileObject'],search_sub=1)
+
+ if not (getattr(self,'positionVersionNum','front')==positionVersionNum):
+
+ for version in versions:
+
+ if positionVersionNum=="front":
+
+ titleTmp=os.path.splitext(version[1].title)
+ titleTmp2="_".join(titleTmp[0].split("_")[0:-1])
+ if len(titleTmp)>1:
+ id=titleTmp[0].split("_")[-1]+"_"+titleTmp2+"."+titleTmp[1]
+ else:
+ id=titleTmp[0].split("_")[-1]+"_"+titleTmp2
+
+ else:
+ titleTmp="_".join(version[1].getId().split("_")[1:])
+ tmp=os.path.splitext(titleTmp)
+ if len(tmp)>1:
+ id=tmp[0]+"_"+version[1].getId().split("_")[0]+tmp[1]
+ else:
+ id=tmp[0]+"_"+version[1].getId().split("_")[0]
+
+
+
+ version[1].aq_parent.manage_renameObjects(ids=[version[1].getId()],new_ids=[id])
+ version[1].title=id
+
+
+ self.positionVersionNum=positionVersionNum
+ if RESPONSE:
+ RESPONSE.redirect("manage_main")
+
+
+
def importFolderForm(self):
"""form fuer folder import"""
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','importFolderForm.zpt')).__of__(self)
@@ -156,55 +214,57 @@ class versionedFileFolder(Folder,ECHO_ba
"""exportiert alle akutellen files des folders"""
threadName=repeat
-
- if not threadName or threadName=="":
- threadStart=generateDownloadZip(self,self.absolute_url())
- thread=Thread(target=threadStart)
+ downloadZip=generateDownloadZip(self,self.absolute_url())
+ downloadZip()
+ return downloadZip.getResult()
+ ## if not threadName or threadName=="":
+## threadStart=generateDownloadZip(self,self.absolute_url())
+## thread=Thread(target=threadStart)
- thread.start()
+## thread.start()
- self.zipThreads[thread.getName()[0:]]=threadStart
- self.zipThreads2[thread.getName()[0:]]=thread
- self.REQUEST.SESSION['threadName']=thread.getName()[0:]
- wait_template=self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['zip_wait_template'])
- if wait_template:
- return wait_template[0][1]()
- pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_wait.zpt')).__of__(self)
- return pt()
+## self.zipThreads[thread.getName()[0:]]=threadStart
+## self.zipThreads2[thread.getName()[0:]]=thread
+## self.REQUEST.SESSION['threadName']=thread.getName()[0:]
+## wait_template=self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['zip_wait_template'])
+## if wait_template:
+## return wait_template[0][1]()
+## pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_wait.zpt')).__of__(self)
+## return pt()
- else:
- self.REQUEST.SESSION['threadName']=threadName
+## else:
+## self.REQUEST.SESSION['threadName']=threadName
- if (self.zipThreads[threadName].getResult()==None):
+## if (self.zipThreads[threadName].getResult()==None):
- wait_template=self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['wait_template'])
- if wait_template:
- return wait_template[0][1]()
-
- pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_wait.zpt')).__of__(self)
- return pt()
- else:
- if self.zipThreads[threadName].isDone():
- self.REQUEST.SESSION['result']=self.zipThreads[threadName].getResult()
- self.zipThreads2[threadName].join()
- del(self.zipThreads2[threadName])
- del(self.zipThreads[threadName])
- pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_result.zpt')).__of__(self)
- return pt()
-
- else:
- self.REQUEST.SESSION['result']=self.zipThreads[threadName].getResult()
- self.REQUEST.SESSION['threadName']=threadName
- pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_wait_result.zpt')).__of__(self)
- return pt()
+## wait_template=self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['wait_template'])
+## if wait_template:
+## return wait_template[0][1]()
+
+## pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_wait.zpt')).__of__(self)
+## return pt()
+## else:
+## if self.zipThreads[threadName].isDone():
+## self.REQUEST.SESSION['result']=self.zipThreads[threadName].getResult()
+## self.zipThreads2[threadName].join()
+## del(self.zipThreads2[threadName])
+## del(self.zipThreads[threadName])
+## pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_result.zpt')).__of__(self)
+## return pt()
+
+## else:
+## self.REQUEST.SESSION['result']=self.zipThreads[threadName].getResult()
+## self.REQUEST.SESSION['threadName']=threadName
+## pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_wait_result.zpt')).__of__(self)
+## return pt()
def downloadSet(self,fn):
"""download prepared set"""
filename=os.path.join(tdir,fn)
- self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename="%s" """%"donloadFileFolder.tgz")
+ self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename="%s" """%"downloadFileFolder.tgz")
self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream")
len=os.stat(filename)[6]
self.REQUEST.RESPONSE.setHeader("Content-Length",len)
@@ -220,6 +280,24 @@ class versionedFileFolder(Folder,ECHO_ba
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','helpDownload')).__of__(self)
return pt()
+ def generateIndexHTML_image(self,RESPONSE=None):
+ """lege standard index.html an"""
+
+
+ if not self.ZopeFind(self,obj_ids=['index.html']):
+ zt=ZopePageTemplate('index.html')
+ self._setObject('index.html',zt)
+ default_content_fn = os.path.join(package_home(globals()),
+ 'zpt/versionFileFolderMain_image.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):
"""lege standard index.html an"""
@@ -305,8 +383,9 @@ class versionedFileFolder(Folder,ECHO_ba
return cmp(x[1].getLastVersion().lastEditor().lower(),y[1].getLastVersion().lastEditor().lower())
- versionedFiles=self.ZopeFind(self,obj_metatypes=['versionedFile'])
-
+ versionedFiles=self.ZopeFind(self,obj_metatypes=self.filesMetaType)
+
+
if sortField=='title':
versionedFiles.sort(sortName)
elif sortField=='date':
@@ -326,7 +405,9 @@ class versionedFileFolder(Folder,ECHO_ba
return ext[0][1]()
else:
return ""
-
+
+
+ security.declareProtected('View','index_html')
def index_html(self):
"""main"""
ext=self.ZopeFind(self,obj_ids=["index.html"])
@@ -428,13 +509,16 @@ def manage_addVersionedFileFolder(self,
class versionedFileObject(File):
"""File Object im Folder"""
-
+ security= ClassSecurityInfo()
meta_type = "versionedFileObject"
manage_editForm =DTMLFile('dtml/fileEdit',globals(),
Kind='File',kind='file')
manage_editForm._setName('manage_editForm')
+
+ security.declarePublic('getVComment')
+
def getVComment(self):
"""get the comment of this file"""
if not hasattr(self,'vComment') or (not self.vComment) or (self.vComment.lstrip()==""):
@@ -470,6 +554,13 @@ class versionedFileObject(File):
return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url()+"/history")
+ security.declarePublic('getVersionComment')
+ def getVersionComment(self):
+ """getversioncomment"""
+ return self.versionComment
+
+ security.declarePublic('getTime')
+
def getTime(self):
"""getTime"""
#return self.bobobase_modification_time().ISO()
@@ -485,17 +576,25 @@ class versionedFileObject(File):
- def download(self):
+ def download(self,REQUEST=None,RESPONSE=None):
"""download and lock"""
self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getId())
- self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream")
-
+ self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream")
+ #try:
+ # txt=self.index_html()
+ #except:
+ # txt=self.index_html(REQUEST,RESPONSE)
+ #
+ #self.REQUEST.RESPONSE.setHeader("Content-Length","str(len(txt)+1000)")
+
self.content_type="application/octet-stream"
- #self.REQUEST.RESPONSE.redirect(self.absolute_url())
- self.REQUEST.RESPONSE.write(self.index_html())
- #self.REQUEST.RESPONSE.write("bl")
- self.REQUEST.close()
+ self.REQUEST.RESPONSE.redirect(self.absolute_url())
+ #txt=urllib.urlopen(self.absolute_url()).read()
+ #self.REQUEST.RESPONSE.write(txt)
+
+
+ #self.REQUEST.close()
def downloadLocked(self):
"""download and lock"""
@@ -514,12 +613,22 @@ class versionedFileObject(File):
"""set version"""
self.versionNumber=versionNumber
+
+ security.declarePublic('getVersionNumber')
+
def getVersionNumber(self):
"""get version"""
return self.versionNumber
+ security.declarePublic('getVersionComment')
+ def getVersionComment(self):
+ """get version"""
+ return self.versionComment
+
-
+
+ security.declarePublic('lastEditor')
+
def lastEditor(self):
"""last Editor"""
if hasattr(self,'author'):
@@ -575,9 +684,15 @@ def manage_addVersionedFileObject(self,i
-class versionedFile(Folder):
+class versionedFile(CatalogAware,Folder):
"""Versioniertes File"""
+ default_catalog='fileCatalog'
+
+ def PrincipiaSearchSource(self):
+ """Return cataloguable key for ourselves."""
+ return str(self)
+
def __init__(self, id, title, lockedBy,author):
"""init"""
self.id=id
@@ -585,6 +700,56 @@ class versionedFile(Folder):
self.lockedBy=lockedBy
self.author=author
+ def manageImagesForm(self):
+ """manage Images attached to the file"""
+
+ self.REQUEST.SESSION['refer']=self.REQUEST['HTTP_REFERER']
+
+ pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','manageImage')).__of__(self)
+ return pt()
+
+ def manageImages(self,imageUrl=None,caption=None,REQUEST=None):
+ """manage URL"""
+ if imageUrl and (not imageUrl==""):
+ manage_AddImageZogiLib(self,libPath=imageUrl,caption=caption)
+
+ if self.REQUEST.SESSION.has_key('refer'):
+
+ return REQUEST.RESPONSE.redirect(self.REQUEST.SESSION['refer'])
+ return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url())
+
+
+
+ def changeImages(self,caption=None,submit=None,id=None,REQUEST=None):
+ """manage URL"""
+ if submit=="change caption":
+ image=self.ZopeFind(self,obj_ids=[id])
+ if image:
+ image[0][1].caption=caption[0:]
+
+ elif submit=="delete":
+ image=self.ZopeFind(self,obj_ids=[id])
+ if image:
+ self.manage_delObjects([image[0][1].getId()])
+
+
+ if self.REQUEST.SESSION.has_key('refer'):
+
+ return REQUEST.RESPONSE.redirect(self.REQUEST.SESSION['refer'])
+ return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url())
+
+
+
+
+ def getImages(self):
+ """get Images"""
+ images=self.ZopeFind(self,obj_metatypes=["ImageZogiLib"])
+ if not images:
+ return None
+ else:
+ return images
+
+
def getComment(self):
"""get the comment of this file"""
if not hasattr(self,'comment') or (not self.comment) or (self.comment.lstrip()==""):
@@ -619,6 +784,7 @@ class versionedFile(Folder):
tmp=0
lastVersion=None
+
for version in self.ZopeFind(self):
if hasattr(version[1],'versionNumber'):
@@ -626,6 +792,9 @@ class versionedFile(Folder):
if int(version[1].versionNumber) > tmp:
tmp=int(version[1].versionNumber,)
lastVersion=version[1]
+ if lastVersion==None:
+ lastVersion=version[1]
+ lastVersion.versionNumber=1
return lastVersion
def index_html(self):
@@ -633,7 +802,8 @@ class versionedFile(Folder):
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')
def getVersion(self):
tmp=0
for version in self.ZopeFind(self):
@@ -644,7 +814,7 @@ class versionedFile(Folder):
tmp=int(version[1].versionNumber,)
return tmp+1
- security= ClassSecurityInfo()
+
security.declareProtected('AUTHENTICATED_USER','unlock')
def history(self):
@@ -714,11 +884,24 @@ class versionedFile(Folder):
if not newName=='':
self.title=newName[0:]
- print self.title
- id="V%i"%self.getVersion()+"_"+self.title
- manage_addVersionedFileObject(self,id,vC,author,file,"V%i"%self.getVersion()+"_"+self.title,precondition, content_type)
+
+
+
+ positionVersionNum=getattr(self,'positionVersionNum','front')
+
+ if positionVersionNum=='front':
+ id="V%i"%self.getVersion()+"_"+self.title
+ else:
+ tmp=os.path.splitext(self.title)
+ if len(tmp)>1:
+ id=tmp[0]+"_V%i"%self.getVersion()+tmp[1]
+ else:
+ id=tmp[0]+"_V%i"%self.getVersion()
+
+
+ manage_addVersionedFileObject(self,id,vC,author,file,id,precondition, content_type)
objs=self.ZopeFind(self,obj_ids=[id])[0][1].setVersionNumber(int(self.getVersion()))
self.REQUEST.SESSION['objID_parent']=self.getId()
@@ -741,15 +924,22 @@ class versionedFile(Folder):
"""download and lock"""
self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getLastVersion().getId())
- self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream")
+ self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream")
+ #try:
+ # txt=self.getLastVersion.index_html()
+ #except:
+ # txt=self.getLastVersion.index_html(REQUEST,RESPONSE)
+
+ #self.REQUEST.RESPONSE.setHeader("Content-Length","str(len(txt)+1000)")
+
self.content_type="application/octet-stream"
#self.REQUEST.RESPONSE.write("bl")
- self.REQUEST.RESPONSE.write(self.getLastVersion().index_html())
- self.REQUEST.close()
+ #self.REQUEST.RESPONSE.write(txt)
+ #self.REQUEST.close()
#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())
def downloadLocked(self):
"""download and lock"""