Annotation of versionedFile/extVersionedFile.py, revision 1.33
1.3 dwinter 1: """actual version of the versioned file folder with external filestorage,
2: using the ExtFile Product, this version replaces externaVersionedFile.py
3: DW 11.10.2006
4: """
5:
1.32 dwinter 6: import email
1.1 dwinter 7: from OFS.Folder import Folder
8: from OFS.Image import File
9: from OFS.Image import cookId
10: from Globals import DTMLFile, InitializeClass,package_home
11: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
12: from AccessControl import getSecurityManager
13: from Products.PageTemplates.PageTemplate import PageTemplate
14: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
15: from AccessControl import ClassSecurityInfo
16: from difflib import Differ
17: from pprint import pprint
18: from Products.ExtFile.ExtFile import *
19: from Products.ZCatalog.CatalogPathAwareness import CatalogAware
20:
21: try:
1.6 casties 22: from Products.ImageArchive.ImageArchive import manage_AddImageZogiLib
1.1 dwinter 23: except:
1.6 casties 24: print "no images"
1.1 dwinter 25:
26: from threading import Thread
27: import shutil
28: import tempfile
29: import os.path
30: import urllib
1.5 casties 31: import time
32: import logging
1.9 casties 33: import types
1.1 dwinter 34:
35: try:
36: from Products.ECHO_content.ECHO_collection import ECHO_basis
37: except:
38: print "ECHO Elements not imported"
39: class ECHO_basis:
1.6 casties 40: """leer"""
41: manage_options=()
1.1 dwinter 42:
43:
44: def sortv(x,y):
45: return cmp(x[0],y[0])
1.7 casties 46:
1.1 dwinter 47: tdir = "/tmp/downloadVersionedFiles"
48:
49: class generateDownloadZip:
50: """generateDownloadSet"""
51:
52: def __init__(self,folderObject,url):
53: """init downloadzip"""
54: self.folder=folderObject
55: self.done=None
56: self.response=""
57: self.url=url
58:
59: def __call__(self):
60: """call generate download zip"""
61: storeTempDir=tempfile.tempdir
1.6 casties 62: tempfile.tempdir=tdir
1.1 dwinter 63:
64: tmpPath=tempfile.mktemp()
1.6 casties 65: tmpZip=tempfile.mktemp()+".tgz"
1.1 dwinter 66: tmpFn=os.path.split(tmpZip)[1]
67:
68: if not os.path.exists(tempfile.tempdir):
69: os.mkdir(tempfile.tempdir)
70:
71: if not os.path.exists(tmpPath):
1.6 casties 72: os.mkdir(tmpPath)
1.1 dwinter 73:
1.6 casties 74: self.response="<h3>1. step: getting the files</h3>"
1.1 dwinter 75:
76: for files in self.folder.ZopeFind(self.folder,obj_metatypes=['extVersionedFile']):
1.7 casties 77: lastV=files[1].getContentObject()
1.1 dwinter 78: self.response+=str("<p>Get File: %s<br>\n"%lastV.title)
79:
80: savePath=os.path.join(tmpPath,lastV.title)
81: fh=file(savePath,"w")
1.2 dwinter 82: fh.write(lastV.getData())
1.1 dwinter 83: fh.close()
84:
85: self.response+="<h3>2. step: creating the downloadable file</h3>"
1.6 casties 86: self.response+="<p>Create gtar<br>"
1.1 dwinter 87: self.response+="<p>This can take a while....<br>\n"
88:
89: fh=os.popen2("tar zcvf %s %s/*"%(tmpZip,tmpPath),1)[1]
90: self.response+="<br>"
91: for c in fh.read():
92: self.response+=c
93: if c==")":
94: self.response+="<br>\n"
95:
96: shutil.rmtree(tmpPath)
97:
98: self.response+="<p>finished<br>\n"
99:
100: len=os.stat(tmpZip)[6]
101: downloadUrl=self.url+"/downloadSet"
102: self.response+="""<h1><a href="downloadSet?fn=%s">Click here for download ( %i Byte)</a></h1>\n"""%(tmpFn,len)
103: self.response+="""<p>The file you receive is a tar (gnutar) compressed file, after unpacking you will find a new folder <emph>tmp</emph> where the files are stored in.</p>"""
104: self.response+="""<p>The file will be stored for a while, you can download it later, the URL is:</p>
105: <p><a href="downloadSet?fn=%s">%s?fn=%s</a></h1>\n"""%(tmpFn,downloadUrl,tmpFn)
106:
107: self.done=True
108:
1.6 casties 109:
1.1 dwinter 110: def getResult(self):
111: """get result"""
112: return self.response
113:
114: def isDone(self):
115: if self.done:
116: return True
117: else:
118: return False
119:
120:
121: class extVersionedFileFolder(Folder,ECHO_basis):
122: """Folder with versioned files"""
123: meta_type = "extVersionedFileFolder"
124:
125: security= ClassSecurityInfo()
126: security.declareProtected('AUTHENTICATED_USER','addFileForm')
1.6 casties 127:
1.7 casties 128: file_meta_type=['extVersionedFile']
1.6 casties 129:
1.1 dwinter 130: if ECHO_basis:
131: optTMP= Folder.manage_options+ECHO_basis.manage_options
132: else:
133: optTMP= Folder.manage_options
134:
135: manage_options =optTMP+(
1.6 casties 136: {'label':'Generate Index.html','action':'generateIndexHTML'},
137: {'label':'Generate Image Index.html','action':'generateIndexHTML_image'},
138: {'label':'Generate history_template.html','action':'generateHistoryHTML'},
1.12 casties 139: {'label':'Import directory','action':'importFolderForm'},
140: {'label':'Export as file','action':'exportFolder'},
141: {'label':'Import versionedFileFolder','action':'importVersionedFileFolderForm'},
1.6 casties 142: {'label':'Position of version number','action':'changeHistoryFileNamesForm'},
143: )
1.1 dwinter 144:
1.6 casties 145:
1.32 dwinter 146: def redirect(self,RESPONSE,url):
147: """mache ein redirect mit einem angehaengten time stamp um ein reload zu erzwingen"""
148:
149: timeStamp=time.time()
150:
151: if url.find("?")>-1: #giebt es schon parameter
152: addStr="&time=%s"
153: else:
154: addStr="?time=%s"
155:
156: RESPONSE.setHeader('Last-Modified',email.Utils.formatdate().split("-")[0]+'GMT')
157: logging.error(email.Utils.formatdate()+' GMT')
158: RESPONSE.redirect(url+addStr%timeStamp)
1.1 dwinter 159: def changeHistoryFileNamesForm(self):
160: """change position of version num"""
161: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeHistoryFileNamesForm.zpt')).__of__(self)
162: return pt()
163:
164:
165: def changeHistoryFileNames(self,positionVersionNum="front",RESPONSE=None):
166: """change position of version num"""
167: versions=self.ZopeFind(self,obj_metatypes=['extVersionedFileObject'],search_sub=1)
168:
169: if not (getattr(self,'positionVersionNum','front')==positionVersionNum):
170:
171: for version in versions:
1.6 casties 172:
1.1 dwinter 173: if positionVersionNum=="front":
1.6 casties 174:
1.1 dwinter 175: titleTmp=os.path.splitext(version[1].title)
176: titleTmp2="_".join(titleTmp[0].split("_")[0:-1])
177: if len(titleTmp)>1:
178: id=titleTmp[0].split("_")[-1]+"_"+titleTmp2+"."+titleTmp[1]
179: else:
180: id=titleTmp[0].split("_")[-1]+"_"+titleTmp2
181:
182: else:
183: titleTmp="_".join(version[1].getId().split("_")[1:])
184: tmp=os.path.splitext(titleTmp)
185: if len(tmp)>1:
186: id=tmp[0]+"_"+version[1].getId().split("_")[0]+tmp[1]
187: else:
188: id=tmp[0]+"_"+version[1].getId().split("_")[0]
189:
190: version[1].aq_parent.manage_renameObjects(ids=[version[1].getId()],new_ids=[id])
191: version[1].title=id
192:
193: self.positionVersionNum=positionVersionNum
194: if RESPONSE:
195: RESPONSE.redirect("manage_main")
196:
197:
198:
199: def importFolderForm(self):
200: """form fuer folder import"""
201: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','importFolderForm.zpt')).__of__(self)
202: return pt()
1.6 casties 203:
1.1 dwinter 204: def importFolder(self,path,comment="",author=None,lockedBy=None,RESPONSE=None):
1.8 casties 205: """import contents of a folder on the server"""
1.1 dwinter 206: for fileName in os.listdir(path):
1.8 casties 207: fn = os.path.join(path,fileName)
208: if os.path.isfile(fn):
209: f = file(fn)
210: self.addFile(vC=comment, file=f, author=author)
1.1 dwinter 211:
212: if RESPONSE:
213: RESPONSE.redirect(self.REQUEST['URL1'])
214:
1.10 casties 215: def importVersionedFileFolderForm(self):
216: """form fuer versionedFileFolder import"""
217: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','importVersionedFileFolderForm.zpt')).__of__(self)
218: return pt()
219:
220: def importVersionedFileFolder(self,path,RESPONSE=None):
221: """import contents of a versionedFileFolder on the server"""
222: vff = getattr(self.aq_parent, path, None)
223: if vff is None:
224: return "SORRY, unable to import %s"%path
225:
226: tmpPath=tempfile.mktemp()
227: if not os.path.exists(tempfile.tempdir):
228: os.mkdir(tempfile.tempdir)
229:
230: if not os.path.exists(tmpPath):
231: os.mkdir(tmpPath)
232:
233: for (vfn, vf) in vff.getVersionedFiles():
234: if vf.meta_type == 'versionedFile':
1.11 casties 235: logging.error("importvff: importing %s of type %s!"%(vfn,vf.meta_type))
1.10 casties 236: title = vf.title
1.11 casties 237: fob = vf.getLastVersion()
238: author = fob.getLastEditor()
239: vc = fob.getVersionComment()
1.10 casties 240: # save file to filesystem
241: savePath=os.path.join(tmpPath,title)
242: fh=file(savePath,"w")
1.11 casties 243: data = vf.getLastVersion().data
244: if isinstance(data, str):
245: # simple data object
246: fh.write(data)
247: else:
248: # chained data objects
249: while data is not None:
250: fh.write(data.data)
251: data = data.next
1.10 casties 252: fh.close()
253: # and read in again
254: fh = file(savePath)
1.11 casties 255: logging.error("importvff: comment=%s author=%s!"%(vc,author))
1.10 casties 256: self.addFile(vC=vc, file=fh, author=author)
1.11 casties 257: # copy more fields
258: newfob = getattr(self, vfn).getContentObject()
259: newfob.vComment = fob.vComment
260: newfob.time = fob.time
261: logging.error("importvff: vc=%s time=%s of %s!"%(fob.vComment,fob.time,fob.getId()))
1.10 casties 262:
263: else:
264: logging.error("importvff: unable to import %s of type %s!"%(vfn,vf.meta_type))
265:
266: shutil.rmtree(tmpPath)
267:
268: if RESPONSE:
269: RESPONSE.redirect(self.REQUEST['URL1'])
270:
1.1 dwinter 271: zipThreads={}
272: zipThreads2={}
273:
274: def refreshTxt(self):
275: """txt fuer refresh"""
276: tn=self.REQUEST.SESSION['threadName']
277: return """ 2;url=%s?repeat=%s """%(self.absolute_url()+"/exportFolder",tn)
278:
279: def exportFolder(self,repeat=None):
280: """exportiert alle akutellen files des folders"""
281: threadName=repeat
282:
283: downloadZip=generateDownloadZip(self,self.absolute_url())
284: downloadZip()
285: return downloadZip.getResult()
1.8 casties 286:
1.1 dwinter 287: ## if not threadName or threadName=="":
288: ## threadStart=generateDownloadZip(self,self.absolute_url())
289: ## thread=Thread(target=threadStart)
1.6 casties 290:
1.1 dwinter 291: ## thread.start()
292:
1.6 casties 293:
1.1 dwinter 294: ## self.zipThreads[thread.getName()[0:]]=threadStart
295: ## self.zipThreads2[thread.getName()[0:]]=thread
296: ## self.REQUEST.SESSION['threadName']=thread.getName()[0:]
297: ## wait_template=self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['zip_wait_template'])
298: ## if wait_template:
299: ## return wait_template[0][1]()
300: ## pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_wait.zpt')).__of__(self)
301: ## return pt()
1.6 casties 302:
1.1 dwinter 303: ## else:
304: ## self.REQUEST.SESSION['threadName']=threadName
305:
306: ## if (self.zipThreads[threadName].getResult()==None):
307:
308: ## wait_template=self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['wait_template'])
309: ## if wait_template:
310: ## return wait_template[0][1]()
311:
312: ## pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_wait.zpt')).__of__(self)
313: ## return pt()
314: ## else:
315: ## if self.zipThreads[threadName].isDone():
316: ## self.REQUEST.SESSION['result']=self.zipThreads[threadName].getResult()
317: ## self.zipThreads2[threadName].join()
318: ## del(self.zipThreads2[threadName])
319: ## del(self.zipThreads[threadName])
320: ## pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_result.zpt')).__of__(self)
321: ## return pt()
322:
323: ## else:
324: ## self.REQUEST.SESSION['result']=self.zipThreads[threadName].getResult()
325: ## self.REQUEST.SESSION['threadName']=threadName
326: ## pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_wait_result.zpt')).__of__(self)
327: ## return pt()
328:
329: def downloadSet(self,fn):
1.6 casties 330: """download prepared set"""
331: filename=os.path.join(tdir,fn)
1.1 dwinter 332:
1.6 casties 333:
334: self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename="%s" """%"downloadFileFolder.tgz")
335: self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream")
336: len=os.stat(filename)[6]
337: self.REQUEST.RESPONSE.setHeader("Content-Length",len)
338: images=file(filename).read()
339: self.REQUEST.RESPONSE.write(images)
340: self.REQUEST.RESPONSE.close()
1.1 dwinter 341:
342:
343:
344: def helpDownload(self):
345: """download help"""
346:
347: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','helpDownload')).__of__(self)
348: return pt()
349:
350: def generateIndexHTML_image(self,RESPONSE=None):
351: """lege standard index.html an"""
352:
353:
354: if not self.ZopeFind(self,obj_ids=['index.html']):
355: zt=ZopePageTemplate('index.html')
356: self._setObject('index.html',zt)
357: default_content_fn = os.path.join(package_home(globals()),
1.6 casties 358: 'zpt/versionFileFolderMain_image.zpt')
1.1 dwinter 359: text = open(default_content_fn).read()
360: zt.pt_edit(text, 'text/html')
361:
362: else:
363: return "already exists!"
364:
365: if RESPONSE is not None:
366: RESPONSE.redirect('manage_main')
367:
368:
369: def generateAddFileForm(self,RESPONSE=None):
370: """lege standard addfileform an"""
371: #TODO: write generateaddfileform only a dummy at them moment
372:
373: if not self.ZopeFind(self,obj_ids=['addFileForm.dtml']):
374: zt=ZopePageTemplate('index.html')
375: self._setObject('index.html',zt)
376: default_content_fn = os.path.join(package_home(globals()),
1.6 casties 377: 'zpt/versionFileFolderMain.zpt')
1.1 dwinter 378: text = open(default_content_fn).read()
379: zt.pt_edit(text, 'text/html')
380:
381: else:
382: return "already exists!"
383:
384: if RESPONSE is not None:
385: RESPONSE.redirect('manage_main')
386:
387:
388: def generateIndexHTML(self,RESPONSE=None):
389: """lege standard index.html an"""
390: if not self.ZopeFind(self,obj_ids=['index.html']):
391: zt=ZopePageTemplate('index.html')
392: self._setObject('index.html',zt)
393: default_content_fn = os.path.join(package_home(globals()),
1.6 casties 394: 'zpt/versionFileFolderMain.zpt')
1.1 dwinter 395: text = open(default_content_fn).read()
396: zt.pt_edit(text, 'text/html')
397:
398: else:
399: return "already exists!"
400:
401: if RESPONSE is not None:
402: RESPONSE.redirect('manage_main')
403:
404:
405: def generateHistoryHTML(self,RESPONSE=None):
406: """lege standard index.html an"""
407: if not self.ZopeFind(self,obj_ids=['history_template.html']):
408: zt=ZopePageTemplate('history_template.html')
409: self._setObject('history_template.html',zt)
410: default_content_fn = os.path.join(package_home(globals()),
1.6 casties 411: 'zpt/versionHistory.zpt')
1.1 dwinter 412: text = open(default_content_fn).read()
413: zt.pt_edit(text, 'text/html')
414:
415: else:
416: return "already exists!"
417:
418: if RESPONSE is not None:
419: RESPONSE.redirect('manage_main')
1.6 casties 420:
1.1 dwinter 421:
422: def getVersionedFiles(self,sortField='title'):
423: """get all versioned files"""
424:
425: def sortName(x,y):
426: return cmp(x[1].title.lower(),y[1].title.lower())
427:
428: def sortDate(x,y):
1.7 casties 429: return cmp(y[1].getContentObject().getTime(),x[1].getContentObject().getTime())
1.1 dwinter 430:
431: def sortComment(x,y):
1.6 casties 432: try:
433: xc=getattr(x[1],'comment','ZZZZZZZZZZZZZ').lower()
434: except:
435: xc='ZZZZZZZZZZZZZ'.lower()
436:
437: try:
438: yc=getattr(y[1],'comment','ZZZZZZZZZZZZZ').lower()
439: except:
440: yc='ZZZZZZZZZZZZZ'.lower()
441:
442: if (xc=='') or (xc=='ZZZZZZZZZZZZZ'.lower()):
443: try:
1.7 casties 444: xc=x[1].getContentObject().getVComment().lower()
1.6 casties 445: except:
446: xc='ZZZZZZZZZZZZZ'.lower()
447:
448: if (yc=='') or (yc=='ZZZZZZZZZZZZZ'.lower()):
449: try:
1.7 casties 450: yc=y[1].getContentObject().getVComment().lower()
1.6 casties 451: except:
452: yc='ZZZZZZZZZZZZZ'.lower()
453:
454: return cmp(xc,yc)
1.1 dwinter 455:
456: def sortAuthor(x,y):
457:
1.7 casties 458: return cmp(x[1].getContentObject().lastEditor().lower(),y[1].getContentObject().lastEditor().lower())
1.1 dwinter 459:
1.7 casties 460: versionedFiles=self.objectItems(self.file_meta_type)
461: logging.debug("versionedfiles: %s of type %s"%(repr(versionedFiles),repr(self.file_meta_type)))
1.1 dwinter 462:
463: if sortField=='title':
464: versionedFiles.sort(sortName)
465: elif sortField=='date':
466: versionedFiles.sort(sortDate)
467: elif sortField=='author':
468: versionedFiles.sort(sortAuthor)
469: elif sortField=='comment':
470: versionedFiles.sort(sortComment)
471:
472: return versionedFiles
473:
474:
475: def header_html(self):
1.5 casties 476: """zusaetzlicher header"""
1.1 dwinter 477: ext=self.ZopeFind(self,obj_ids=["header.html"])
478: if ext:
479: return ext[0][1]()
480: else:
481: return ""
482:
483:
484: security.declareProtected('View','index_html')
485: def index_html(self):
486: """main"""
487: ext=self.ZopeFind(self,obj_ids=["index.html"])
488: if ext:
489: return ext[0][1]()
490:
491: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','versionFileFolderMain')).__of__(self)
492: return pt()
493:
494:
495:
496: def addFileForm(self):
497: """add a file"""
498: ext=self.ZopeFind(self,obj_ids=["addFileForm.dtml"])
499: if ext:
500: return ext[0][1]('',globals(),version='1',AUTHENTICATED_USER=self.REQUEST.AUTHENTICATED_USER)
501:
502: out=DTMLFile('dtml/newFileAdd', globals(),Kind='versionedFileObject',kind='versionedFileObject',version='1').__of__(self)
503: return out()
504:
505:
1.8 casties 506: def addFile(self,vC,file,author='',newName='',content_type='',RESPONSE=None):
1.1 dwinter 507: """ add a new file"""
1.9 casties 508: # is file is a real file or a zope download object?
509: isRealFile = type(file) is types.FileType
510:
1.1 dwinter 511: if newName=='':
1.9 casties 512: logging.debug("fileobject: %s real:%s"%(repr(file),repr(isRealFile)))
513: if isRealFile:
514: filename = file.name
515: else:
516: filename=file.filename
517:
1.1 dwinter 518: id=filename[max(filename.rfind('/'),
1.6 casties 519: filename.rfind('\\'),
520: filename.rfind(':'),
521: )+1:]
1.1 dwinter 522:
523: else:
524: id=newName
525:
1.11 casties 526: if vC is None:
1.9 casties 527: vC=self.REQUEST.form['vC']
1.8 casties 528:
529: # get new extVersionedFile
530: vf = self._newVersionedFile(id,title=id)
1.26 dwinter 531: logging.error("addFile id=%s vf=%s of %s"%(repr(id),repr(vf),repr(self)))
1.18 casties 532: # add its content (and don't index)
533: obj=vf.addContentObject(id,vC,author=author,file=file,content_type=content_type,from_tmp=isRealFile,index=False)
534: # add file to this folder (this should do the indexing)
1.8 casties 535: self._setObject(id,vf)
1.1 dwinter 536:
1.18 casties 537: try:
538: self.REQUEST.SESSION['objID']=vf.getId()
539: self.REQUEST.SESSION['objID_parent']=None
540: except:
541: pass
1.1 dwinter 542:
543: if obj.getSize()==0:
544: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','errorUploadFile')).__of__(self)
545: return pt()
546:
1.9 casties 547: if RESPONSE is not None:
548: RESPONSE.redirect(self.REQUEST['URL1'])
1.1 dwinter 549:
550:
1.8 casties 551: def _newVersionedFile(self, id, title='', lockedBy=None, author=None):
552: """factory for versioned files. to be overridden in derived classes."""
553: return extVersionedFile(id, title, lockedBy=lockedBy, author=author)
554:
555:
1.1 dwinter 556: def deleteEmptyObject(self,submit,RESPONSE=None):
557: """deleteemptyobject"""
558: if submit=="delete it":
559: if self.REQUEST.SESSION['objID_parent']:
560: obj=getattr(self,self.REQUEST.SESSION['objID_parent'])
561:
562: else:
563: obj=self
564: obj.manage_delObjects([self.REQUEST.SESSION['objID']])
565:
566: RESPONSE.redirect(self.REQUEST['URL1'])
567:
1.7 casties 568:
569: security.declareProtected('AUTHENTICATED_USER','fixVersionNumbers')
570: def fixVersionNumbers(self):
571: """fix last version number of all files"""
572: for (id,vf) in self.getVersionedFiles():
573: vf.fixVersionNumbers()
1.13 casties 574: # recursively
575: for (id,vf) in self.objectItems(self.meta_type):
576: vf.fixVersionNumbers()
1.1 dwinter 577:
1.8 casties 578:
1.1 dwinter 579: manage_addextVersionedFileFolderForm=DTMLFile('dtml/extfolderAdd', globals())
580:
581:
582: def manage_addextVersionedFileFolder(self, id, title='',
1.6 casties 583: createPublic=0,
584: createUserF=0,
585: REQUEST=None):
1.1 dwinter 586: """Add a new Folder object with id *id*.
587:
588: If the 'createPublic' and 'createUserF' parameters are set to any true
589: value, an 'index_html' and a 'UserFolder' objects are created respectively
590: in the new folder.
591: """
592: ob=extVersionedFileFolder()
593: ob.id=str(id)
594: ob.title=title
595: self._setObject(id, ob)
596: ob=self._getOb(id)
597:
598: checkPermission=getSecurityManager().checkPermission
599:
600: if createUserF:
601: if not checkPermission('Add User Folders', ob):
602: raise Unauthorized, (
1.6 casties 603: 'You are not authorized to add User Folders.'
604: )
1.1 dwinter 605: ob.manage_addUserFolder()
606:
1.6 casties 607:
1.1 dwinter 608: if REQUEST is not None:
609: return self.manage_main(self, REQUEST, update_menu=1)
610:
611:
612:
613: class extVersionedFileObject(ExtFile):
614: """File Object im Folder"""
615: security= ClassSecurityInfo()
616: meta_type = "extVersionedFileObject"
617:
1.7 casties 618: manage_editForm=DTMLFile('dtml/fileEdit',globals(),
1.1 dwinter 619: Kind='File',kind='file')
620: manage_editForm._setName('manage_editForm')
621:
1.7 casties 622: def __init__(self, id, title='', versionNumber=0, versionComment=None, time=None, author=None):
623: """Initialize a new instance of extVersionedFileObject (taken from ExtFile)"""
624: ExtFile.__init__(self,id,title)
625: self.versionNumber = versionNumber
626: self.versionComment= versionComment
627: self.time = time
628: self.author = author
629:
1.22 casties 630: security.declareProtected('manage','changeObject')
631: def changeObject(self,**args):
1.23 casties 632: """modify any of the objects attributes"""
1.22 casties 633: for arg in args:
634: if hasattr(self, arg):
1.24 casties 635: logging.debug("changeObject %s: %s=%s"%(repr(self),arg,args[arg]))
1.22 casties 636: setattr(self, arg, args[arg])
1.7 casties 637:
1.1 dwinter 638: security.declarePublic('getTitle')
639: def getTitle(self):
640: """get title"""
641: return self.title
1.6 casties 642:
643: def getData(self):
644: """returns object content (calls ExtFile.index_html)"""
1.27 dwinter 645: #logging.debug("+++++++getData1:"+repr(self.get_filename()))
646: filename = self.get_filename()
647: #return ExtFile.index_html(self)
1.29 dwinter 648: try:
1.32 dwinter 649: logging.info("readfile:"+filename)
1.29 dwinter 650: return file(filename).read()
651: except:
1.32 dwinter 652: logging.info("cannot readfile:"+filename)
1.29 dwinter 653: return ExtFile.index_html(self)
654:
1.27 dwinter 655:
656: def getFileName(self):
657: """return filename"""
658: return self.get_filename()
659:
660: def addToFile(self,filehandle):
661: filehandle.write(self.getData())
662:
663: def addToFile2(self,filename):
664: str="cat %s > %s"%(self.get_filename(),filename)
665: os.popen(str)
666:
1.1 dwinter 667: security.declarePublic('getVComment')
668: def getVComment(self):
669: """get the comment of this file"""
670: if not hasattr(self,'vComment') or (not self.vComment) or (self.vComment.lstrip()==""):
671: return "Add comment"
672:
673: else:
674: return self.vComment
1.6 casties 675:
1.1 dwinter 676: def manageVCommentForm(self):
677: """add a comment"""
678: self.REQUEST.SESSION['refer']=self.REQUEST['HTTP_REFERER']
679: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addVComment')).__of__(self)
680: return pt()
681:
682: def manageVComment(self,text,comment_author,submit,REQUEST=None):
683: """manage comments"""
684: if submit =='change':
685: if text=='':
686: self.vComment=None
687: else:
688: self.vComment=text
689: self.vComment_author=comment_author
690:
691: self.vComment_date=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
692:
693: if self.REQUEST.SESSION.has_key('refer'):
694:
695: return REQUEST.RESPONSE.redirect(self.REQUEST.SESSION['refer'])
696: return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url()+"/history")
697:
698:
699: security.declarePublic('getVersionComment')
700: def getVersionComment(self):
701: """getversioncomment"""
702: return self.versionComment
703:
704: security.declarePublic('getTime')
705: def getTime(self):
706: """getTime"""
707: #return self.bobobase_modification_time().ISO()
708: if hasattr(self,'time'):
709: return time.strftime("%Y-%m-%d %H:%M:%S",self.time)
710: elif hasattr(self,'timefixed'):
1.6 casties 711: return self.timefixed
1.1 dwinter 712: else:
713: setattr(self,'timefixed',self.bobobase_modification_time().ISO())
714: return self.bobobase_modification_time().ISO()
715:
716: def download(self,REQUEST=None,RESPONSE=None):
717: """download and lock"""
718:
719: self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getId())
720: self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream")
721: #try:
722: # txt=self.index_html()
723: #except:
724: # txt=self.index_html(REQUEST,RESPONSE)
725: #
726: #self.REQUEST.RESPONSE.setHeader("Content-Length","str(len(txt)+1000)")
727:
728: self.content_type="application/octet-stream"
1.26 dwinter 729: return self.getData()
730: #self.REQUEST.RESPONSE.redirect(self.absolute_url())
1.1 dwinter 731: #txt=urllib.urlopen(self.absolute_url()).read()
732: #self.REQUEST.RESPONSE.write(txt)
733:
734:
735: #self.REQUEST.close()
736:
1.19 casties 737: view = download
738:
1.1 dwinter 739: security.declareProtected('AUTHENTICATED_USER','downloadLocked')
740: def downloadLocked(self):
741: """download and lock"""
742:
743:
744: if repr(self.REQUEST['AUTHENTICATED_USER'])=='Anonymous User':
745: return "please login first"
746: if not self.aq_parent.lockedBy=="":
747: return "cannot be locked because is already locked by %s"%self.lockedBy
748: self.aq_parent.lockedBy=self.REQUEST['AUTHENTICATED_USER']
749:
750: self.content_type="application/octet-stream"
751: self.REQUEST.RESPONSE.redirect(self.absolute_url())
752:
753: security.declarePublic('getVersionNumber')
754: def getVersionNumber(self):
755: """get version"""
756: return self.versionNumber
757:
758: security.declarePublic('getVersionComment')
759: def getVersionComment(self):
760: """get version"""
761: return self.versionComment
762:
763: security.declarePublic('lastEditor')
764: def lastEditor(self):
765: """last Editor"""
766: if hasattr(self,'author'):
767: try:
768: ret=self.author.replace("-","\n")
769: except:#old version of versionded file sometimes stored the user object and not only the name the following corrects this
770: ret=str(self.author).replace("-","\n")
771: ret=ret.replace("\r","\n")
772: return ret.lstrip().rstrip()
773:
774: else:
775: jar=self._p_jar
776: oid=self._p_oid
777:
778: if jar is None or oid is None: return None
779:
780: return jar.db().history(oid)[0]['user_name']
781:
782:
783: manage_addextVersionedFileObjectForm=DTMLFile('dtml/fileAdd', globals(),Kind='extVersionedFileObject',kind='extVersionedFileObject', version='1')
784:
1.7 casties 785: def manage_addextVersionedFileObject(self,id,vC='',author='', file='',title='',versionNumber=0,
786: precondition='', content_type='', REQUEST=None):
1.1 dwinter 787: """Add a new File object.
788:
789: Creates a new File object 'id' with the contents of 'file'"""
790:
791: id=str(id)
792: title=str(title)
793: content_type=str(content_type)
794: precondition=str(precondition)
795:
796: id, title = cookId(id, title, file)
797:
798: self=self.this()
799:
800: # First, we create the file without data:
1.7 casties 801: self._setObject(id, extVersionedFileObject(id,title,versionNumber=versionNumber,versionComment=str(vC),author=author))
802: fob = self._getOb(id)
1.1 dwinter 803:
804: # Now we "upload" the data. By doing this in two steps, we
805: # can use a database trick to make the upload more efficient.
806: if file:
1.7 casties 807: fob.manage_upload(file)
1.1 dwinter 808: if content_type:
1.7 casties 809: fob.content_type=content_type
1.1 dwinter 810:
811: if REQUEST is not None:
812: REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main')
813:
814:
815:
816: class extVersionedFile(CatalogAware,Folder):
817: """Versioniertes File"""
818:
1.7 casties 819: meta_type = 'extVersionedFile'
820: # meta_type of contained objects
821: content_meta_type = ['extVersionedFileObject']
1.15 casties 822: # default catalog for extVersionedFile objects
1.7 casties 823: default_catalog = 'fileCatalog'
1.1 dwinter 824:
1.15 casties 825: manage_options = Folder.manage_options+({'label':'Main Config','action':'changeVersionedFileForm'},)
826:
827:
1.7 casties 828: security=ClassSecurityInfo()
1.1 dwinter 829:
1.7 casties 830: def __init__(self, id, title, lockedBy,author):
831: """init"""
832: self.id=id
833: self.title=title
834: self.lockedBy=lockedBy
1.25 casties 835: if self.lockedBy is None:
836: self.lockedBy = ''
1.7 casties 837: self.author=author
838: self.lastVersionNumber=0
839: self.lastVersionId=None
840:
1.1 dwinter 841: security.declarePublic('getTitle')
842: def getTitle(self):
843: """get title"""
844: return self.title
845:
846: def PrincipiaSearchSource(self):
1.6 casties 847: """Return cataloguable key for ourselves."""
848: return str(self)
1.1 dwinter 849:
850: def manageImagesForm(self):
851: """manage Images attached to the file"""
852:
853: self.REQUEST.SESSION['refer']=self.REQUEST['HTTP_REFERER']
854:
855: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','manageImage')).__of__(self)
856: return pt()
857:
858: def manageImages(self,imageUrl=None,caption=None,REQUEST=None):
859: """manage URL"""
860: if imageUrl and (not imageUrl==""):
861: manage_AddImageZogiLib(self,libPath=imageUrl,caption=caption)
862:
863: if self.REQUEST.SESSION.has_key('refer'):
864:
865: return REQUEST.RESPONSE.redirect(self.REQUEST.SESSION['refer'])
866: return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url())
867:
868: def changeImages(self,caption=None,submit=None,id=None,REQUEST=None):
869: """manage URL"""
870: if submit=="change caption":
871: image=self.ZopeFind(self,obj_ids=[id])
872: if image:
873: image[0][1].caption=caption[0:]
874:
875: elif submit=="delete":
876: image=self.ZopeFind(self,obj_ids=[id])
877: if image:
878: self.manage_delObjects([image[0][1].getId()])
879:
880: if self.REQUEST.SESSION.has_key('refer'):
1.7 casties 881: return REQUEST.RESPONSE.redirect(self.REQUEST.SESSION['refer'])
1.1 dwinter 882:
883: return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url())
884:
885: def getImages(self):
886: """get Images"""
887: images=self.ZopeFind(self,obj_metatypes=["ImageZogiLib"])
888: if not images:
889: return None
890: else:
891: return images
1.6 casties 892:
1.1 dwinter 893: security.declarePublic('getComment')
894: def getComment(self):
895: """get the comment of this file"""
896: if not hasattr(self,'comment') or (not self.comment) or (self.comment.lstrip()==""):
897: return "Add comment"
898: else:
899: return self.comment
900:
901: def manageCommentForm(self):
902: """add a comment"""
903: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addComment')).__of__(self)
904: return pt()
905:
906: def manageComment(self,text,comment_author,submit,REQUEST=None):
907: """manage comments"""
908: if submit =='change':
909: if text=='':
910: self.comment=None
911: else:
912: self.comment=text
913: self.comment_author=comment_author
914:
915: self.comment_date=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
916:
917: return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url())
1.6 casties 918:
1.1 dwinter 919: security.declarePublic('getLastChangeDate')
920: def getLastChangeDate(self):
921: """get last change date"""
1.7 casties 922: lv=self.getContentObject()
1.18 casties 923: if lv:
924: time=lv.getTime()
925: return time
926: return None
1.1 dwinter 927:
928: def getLastEditor(self):
929: """get last change date"""
1.7 casties 930: lv=self.getContentObject()
1.1 dwinter 931: le=lv.lastEditor()
932: return le
933:
934: def getLockedBy(self):
935: """get locked by"""
1.25 casties 936: if self.lockedBy is None:
937: self.lockedBy = ''
1.1 dwinter 938: return str(self.lockedBy)
1.6 casties 939:
1.7 casties 940: def getLastVersionNumber(self):
941: """returns the highest version number of all included objects"""
942: lv = self.findLastVersion()
943: if lv:
944: return lv.getVersionNumber()
945: else:
946: return 0
947:
948: def findLastVersion(self):
949: """finds and returns the object with the highest version number"""
950: lvn=0
951: lv=None
952:
953: for v in self.objectValues(self.content_meta_type):
954: logging.debug("findlastversion: check %s"%v.getId())
955: if v.getVersionNumber() > lvn:
956: lvn=v.getVersionNumber()
957: lv=v
958:
959: if lv:
960: logging.debug("findlastversion: got %s"%lv.getId())
961: return lv
962:
1.1 dwinter 963: security.declarePublic('getLastVersion')
964: def getLastVersion(self):
1.7 casties 965: """Last Version (old)"""
1.1 dwinter 966: tmp=0
1.7 casties 967: lv=None
1.1 dwinter 968:
1.7 casties 969: for v in self.objectValues(self.content_meta_type):
1.28 dwinter 970: #logging.debug("getlastversion: check %s"%v.getId())
1.7 casties 971: if v.getVersionNumber() > tmp:
972: tmp=v.getVersionNumber()
973: lv=v
974:
1.28 dwinter 975: #ogging.debug("getlastversion: got %s"%lv.getId())
1.7 casties 976: return lv
977:
978: def getContentObject(self):
979: """returns the last version object"""
1.18 casties 980: if not getattr(self, 'lastVersionId', None):
1.14 casties 981: # find last version and save it
1.7 casties 982: lv = self.findLastVersion()
983: if lv is None:
984: return None
985: self.lastVersionNumber = lv.getVersionNumber()
986: self.lastVersionId = lv.getId()
1.1 dwinter 987:
1.18 casties 988: return getattr(self, self.lastVersionId, None)
1.7 casties 989:
990: security.declarePublic('getData')
991: def getData(self):
992: """Returns the content of the last version"""
1.27 dwinter 993: logging.debug("+++++++getData2")
1.7 casties 994: ob = self.getContentObject()
995: if ob is not None:
996: return ob.getData()
997: else:
998: return None
1.1 dwinter 999:
1.19 casties 1000: security.declarePublic('view')
1001: def view(self,REQUEST=None,RESPONSE=None):
1002: """Returns the last version's view"""
1003: ob = self.getContentObject()
1004: if ob is not None:
1005: return ob.view(REQUEST=REQUEST,RESPONSE=RESPONSE)
1006: else:
1007: return None
1008:
1.1 dwinter 1009: def diff(self,data):
1010: """differenz between lastversion and data"""
1011: d=Differ()
1.7 casties 1012: tmp=self.getData()
1.1 dwinter 1013: #print "XX",data,tmp
1014: try:
1.6 casties 1015: l=list(d.compare(data.splitlines(1),tmp.splitlines(1)))
1.1 dwinter 1016: except:
1017: return 0,""
1018: plus=0
1019: minus=0
1020: for a in l:
1021: if a[0]=='+':
1022: plus+=1
1023: if a[0]=='-':
1024: minus+=1
1025:
1026: return max([plus,minus]),l
1.6 casties 1027:
1028:
1.1 dwinter 1029: security.declarePublic('index_html')
1030: def index_html(self):
1031: """main view"""
1.7 casties 1032: #lastVersion=self.getContentObject()
1.1 dwinter 1033: #return "File:"+self.title+" Version:%i"%lastVersion.versionNumber," modified:",lastVersion.bobobase_modification_time()," size:",lastVersion.getSize(),"modified by:",lastVersion.lastEditor()
1.4 dwinter 1034: #return "File: %s Version:%i modified:%s size:%s modified by:%s"%(self.title,lastVersion.versionNumber,lastVersion.getTime(),lastVersion.getSize(),lastVersion.lastEditor())
1035: return self.history()
1.1 dwinter 1036:
1.30 dwinter 1037: def getVersionNr(self,nr):
1038: """get version with number nr"""
1039: tmp=0
1040: lastVersion=None
1041:
1042:
1043: for version in self.ZopeFind(self):
1044:
1045: if hasattr(version[1],'versionNumber'):
1046:
1047: if int(version[1].versionNumber) ==nr :
1048: return version[1]
1049:
1050: return None
1.1 dwinter 1051: security.declarePublic('getVersion')
1052: def getVersion(self):
1.7 casties 1053: # TODO: this is ugly and it returns the next version number
1.1 dwinter 1054: tmp=0
1055: for version in self.ZopeFind(self):
1056:
1057: if hasattr(version[1],'versionNumber'):
1058:
1059: if int(version[1].versionNumber) > tmp:
1060: tmp=int(version[1].versionNumber,)
1.7 casties 1061: return tmp+1
1.1 dwinter 1062:
1063: def history(self):
1064: """history"""
1065: ext=self.ZopeFind(self.aq_parent,obj_ids=["history_template.html"])
1066: if ext:
1067: return getattr(self,ext[0][1].getId())()
1068:
1069: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','versionHistory')).__of__(self)
1070: return pt()
1071:
1072: def getVersions(self):
1073: """get all versions"""
1074: ret=[]
1075: for version in self.ZopeFind(self):
1076: if hasattr(version[1],'versionNumber'):
1077: ret.append((version[1].versionNumber,version[1]))
1078: ret.sort(sortv)
1079: return ret
1080:
1.20 casties 1081: def getVersionList(self):
1082: """get a list of dicts with author, comment, filename, etc, of all versions"""
1083: vl = []
1084: for v in self.objectValues(self.content_meta_type):
1.21 casties 1085: vl.append({'versionNumber':getattr(v,'versionNumber',0),
1.20 casties 1086: 'title':v.getTitle(),
1.21 casties 1087: 'id':v.getId(),
1.20 casties 1088: 'date':v.getTime(),
1.21 casties 1089: 'author':getattr(v,'author',''),
1090: 'comment':getattr(v,'versionComment','')
1.20 casties 1091: })
1.21 casties 1092: return vl
1.20 casties 1093:
1.1 dwinter 1094: security.declareProtected('AUTHENTICATED_USER','forceunlock')
1.31 dwinter 1095: def forceunlock(self,RESPONSE=None,user=None):
1.1 dwinter 1096: """unlock"""
1097: #safe who had the lock
1.31 dwinter 1098: logging.debug("extVersionFile: (forceunlock)"+str(user))
1.1 dwinter 1099: if self.lockedBy:
1.31 dwinter 1100: if user is not None:
1101: if str(self.lockedBy)==user:
1102: self.brokenLock=str(self.lockedBy)
1103: self.lockedBy=''
1104: else:
1105: self.brokenLock=""
1106: else:
1107: self.brokenLock=str(self.lockedBy)
1108: self.lockedBy=''
1.1 dwinter 1109: else:
1110: self.brokenLock=""
1.31 dwinter 1111:
1.1 dwinter 1112: return self.brokenLock
1113:
1114: security.declareProtected('AUTHENTICATED_USER','unlock')
1115: def unlock(self,RESPONSE):
1116: """unlock"""
1117: if str(self.lockedBy) in [str(self.REQUEST['AUTHENTICATED_USER'])]:
1118: self.lockedBy=''
1.33 ! dwinter 1119: RESPONSE.redirect(self.REQUEST['HTTP_REFERER'])
1.1 dwinter 1120: else:
1121: return "Sorry, not locked by you! (%s,%s)"%(self.lockedBy,self.REQUEST['AUTHENTICATED_USER'])
1122:
1.7 casties 1123:
1.33 ! dwinter 1124:
1.7 casties 1125: def _newContentObject(self, id, title='', versionNumber=0, versionComment=None, time=None, author=None):
1126: """factory for content objects. to be overridden in derived classes."""
1127: return extVersionedFileObject(id,title,versionNumber=versionNumber,versionComment=versionComment,time=time,author=author)
1128:
1129:
1.18 casties 1130: def addContentObject(self,id,vC,author=None,file=None,title='',changeName='no',newName='',from_tmp=False,index=True,
1.7 casties 1131: precondition='', content_type=''):
1132: """add"""
1133:
1134: if changeName=="yes":
1135: filename=file.filename
1136: self.title=filename[max(filename.rfind('/'),
1137: filename.rfind('\\'),
1138: filename.rfind(':'),
1139: )+1:]
1140:
1141: if not newName=='':
1142: self.title=newName[0:]
1143:
1144: posVersNum=getattr(self,'positionVersionNum','front')
1145:
1146: versNum = self.getLastVersionNumber() + 1
1147:
1148: if posVersNum=='front':
1149: id="V%i_%s"%(versNum,self.title)
1150: else:
1151: fn=os.path.splitext(self.title)
1152: if len(fn)>1:
1153: id=fn[0]+"_V%i%s"%(versNum,fn[1])
1154: else:
1155: id=fn[0]+"_V%i"%versNum
1.1 dwinter 1156:
1.7 casties 1157: # what does this do?
1158: id, title = cookId(id, title, file)
1159: self=self.this()
1160:
1161: # First, we create the file without data:
1162: self._setObject(id, self._newContentObject(id,title,versionNumber=versNum,versionComment=str(vC),
1163: time=time.localtime(),author=author))
1164: fob = self._getOb(id)
1165:
1166: # Now we "upload" the data. By doing this in two steps, we
1167: # can use a database trick to make the upload more efficient.
1168: if file and not from_tmp:
1169: fob.manage_upload(file)
1170: elif file and from_tmp:
1171: fob.manage_file_upload(file) # manage_upload_from_tmp doesn't exist in ExtFile2
1172: # fob.manage_upload_from_tmp(file) # manage_upload_from_tmp doesn't exist in ExtFile2
1173: fob.content_type=content_type
1174:
1175: self.lastVersionNumber = versNum
1176: self.lastVersionId = id
1177:
1.9 casties 1178: #logging.debug("addcontentobject: lastversion=%s"%self.getData())
1179: #logging.debug("addcontentobject: fob_data=%s"%fob.getData())
1.18 casties 1180: if index and self.default_catalog:
1181: logging.debug("reindex1: %s in %s"%(repr(self),repr(self.default_catalog)))
1182: self.reindex_object()
1.7 casties 1183:
1184: return fob
1185:
1.1 dwinter 1186:
1187: security.declareProtected('AUTHENTICATED_USER','addVersionedFileObjectForm')
1188: def addVersionedFileObjectForm(self):
1189: """add a new version"""
1190:
1191: if str(self.REQUEST['AUTHENTICATED_USER']) in ["Anonymous User"]:
1192: return "please login first"
1193: if (self.lockedBy==self.REQUEST['AUTHENTICATED_USER']) or (self.lockedBy==''):
1194: ext=self.ZopeFind(self.aq_parent,obj_ids=["addNewVersion.dtml"])
1195: if ext:
1.7 casties 1196: return ext[0][1]('',globals(),version=self.getVersion(),lastComment=self.getContentObject().getVersionComment(),AUTHENTICATED_USER=self.REQUEST.AUTHENTICATED_USER)
1.1 dwinter 1197: else:
1198: out=DTMLFile('dtml/fileAdd', globals(),Kind='VersionedFileObject',kind='versionedFileObject',version=self.getVersion()).__of__(self)
1199: return out()
1200: else:
1201: return "Sorry file is locked by somebody else"
1.7 casties 1202:
1.1 dwinter 1203:
1.7 casties 1204: def manage_addVersionedFileObject(self,id,vC,author,file='',title='',precondition='', content_type='',changeName='no',newName='', from_tmp=False, RESPONSE=None):
1.1 dwinter 1205: """add"""
1206: try: #der ganze vC unsinn muss ueberarbeitet werden
1207: vC=self.REQUEST['vC']
1208: except:
1209: pass
1210:
1211: author=self.REQUEST['author']
1212:
1.7 casties 1213: ob = self.addContentObject(id, vC, author, file, title, changeName=changeName, newName=newName, from_tmp=from_tmp,
1214: precondition=precondition, content_type=content_type)
1215:
1.1 dwinter 1216: self.REQUEST.SESSION['objID_parent']=self.getId()
1217:
1218: if RESPONSE:
1.7 casties 1219: if ob.getSize()==0:
1220: self.REQUEST.SESSION['objID']=ob.getId()
1.1 dwinter 1221: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','errorUploadFile')).__of__(self)
1222: return pt()
1223:
1224: else:
1.19 casties 1225: RESPONSE.redirect(self.absolute_url()+'/history')
1.1 dwinter 1226: else:
1.7 casties 1227: return ob
1.6 casties 1228:
1.15 casties 1229:
1230: changeVersionedFileForm = PageTemplateFile('zpt/changeVersionedFile', globals())
1231:
1.17 casties 1232: def manage_changeVersionedFile(self,title,vC,author,comment,RESPONSE=None):
1.15 casties 1233: """Change VersionedFile metadata"""
1234: self.title = title
1235: self.author = author
1236: cob = self.getContentObject()
1237: if cob:
1238: if vC:
1239: cob.vComment=vC
1240:
1241: if comment=='':
1242: cob.versionComment=None
1243: else:
1244: cob.versionComment=comment
1245:
1.16 casties 1246: if RESPONSE:
1247: RESPONSE.redirect('manage_main')
1248:
1.1 dwinter 1249:
1250: def download(self):
1.15 casties 1251: """download"""
1.26 dwinter 1252:
1253: txt=self.REQUEST['URL1']+'/'+self.getId()+'/'+self.getContentObject().getId()+'/download'
1254:
1255: self.REQUEST.RESPONSE.redirect(txt)
1.16 casties 1256:
1.1 dwinter 1257:
1258: security.declareProtected('AUTHENTICATED_USER','downloadLocked')
1259: def downloadLocked(self):
1260: """download and lock"""
1261:
1262: if repr(self.REQUEST['AUTHENTICATED_USER'])=='Anonymous User':
1263: return "please login first"
1264: if not self.lockedBy=="":
1265: return "cannot be locked because is already locked by %s"%self.lockedBy
1266: self.lockedBy=self.REQUEST['AUTHENTICATED_USER']
1.7 casties 1267: self.getContentObject().content_type="application/octet-stream"
1268: self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'/'+self.getId()+'/'+self.getContentObject().getId())
1269:
1270:
1271: security.declareProtected('AUTHENTICATED_USER','fixVersionNumbers')
1272: def fixVersionNumbers(self):
1273: """check last version number and id"""
1274: if not hasattr(self, 'lastVersionId'):
1275: self.lastVersionNumber = 0
1276: self.lastVersionId = None
1277:
1278: lv = self.getContentObject()
1279: if lv is not None:
1280: lvn = lv.getVersionNumber()
1281: if lvn == 0:
1282: lvn = 1
1283: lv.versionNumber = 1
1284: self.lastVersionNumber = lvn
1285: self.lastVersionId = lv.getId()
1286: else:
1287: self.lastVersionNumber = 0
1288: self.lastVersionId = None
1289: logging.debug("fixing last version number of %s to %s (%s)"%(self.getId(),self.lastVersionNumber,self.lastVersionId))
1290:
1.1 dwinter 1291:
1292: def manage_addextVersionedFileForm(self):
1293: """interface for adding the OSAS_root"""
1294: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addextVersionedFile.zpt')).__of__(self)
1295: return pt()
1296:
1297: def manage_addextVersionedFile(self,id,title,lockedBy, author=None, RESPONSE=None):
1298: """add the OSAS_root"""
1299: newObj=extVersionedFile(id,title,lockedBy,author)
1300: self._setObject(id,newObj)
1.6 casties 1301:
1.1 dwinter 1302: if RESPONSE is not None:
1303: RESPONSE.redirect('manage_main')
1304:
1305:
1306: InitializeClass(extVersionedFile)
1307: InitializeClass(extVersionedFileFolder)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>