--- versionedFile/extVersionedFile.py 2009/06/21 11:28:55 1.32 +++ versionedFile/extVersionedFile.py 2010/03/31 17:07:43 1.35 @@ -156,6 +156,7 @@ class extVersionedFileFolder(Folder,ECHO RESPONSE.setHeader('Last-Modified',email.Utils.formatdate().split("-")[0]+'GMT') logging.error(email.Utils.formatdate()+' GMT') RESPONSE.redirect(url+addStr%timeStamp) + def changeHistoryFileNamesForm(self): """change position of version num""" pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeHistoryFileNamesForm.zpt')).__of__(self) @@ -530,9 +531,12 @@ class extVersionedFileFolder(Folder,ECHO vf = self._newVersionedFile(id,title=id) logging.error("addFile id=%s vf=%s of %s"%(repr(id),repr(vf),repr(self))) # add its content (and don't index) + self._setObject(id,vf) + vf=getattr(self,id) + 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) try: self.REQUEST.SESSION['objID']=vf.getId() @@ -739,8 +743,6 @@ class extVersionedFileObject(ExtFile): security.declareProtected('AUTHENTICATED_USER','downloadLocked') def downloadLocked(self): """download and lock""" - - if repr(self.REQUEST['AUTHENTICATED_USER'])=='Anonymous User': return "please login first" if not self.aq_parent.lockedBy=="": @@ -827,7 +829,7 @@ class extVersionedFile(CatalogAware,Fold security=ClassSecurityInfo() - def __init__(self, id, title, lockedBy,author): + def __init__(self, id, title, lockedBy,author,defaultAction='history'): """init""" self.id=id self.title=title @@ -837,6 +839,7 @@ class extVersionedFile(CatalogAware,Fold self.author=author self.lastVersionNumber=0 self.lastVersionId=None + self.defaultAction = defaultAction security.declarePublic('getTitle') def getTitle(self): @@ -1027,27 +1030,31 @@ class extVersionedFile(CatalogAware,Fold security.declarePublic('index_html') - def index_html(self): + def index_html(self,REQUEST=None, RESPONSE=None): """main view""" #lastVersion=self.getContentObject() #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 self.history() + act = getattr(self, 'defaultAction', 'history') + if act == 'download': + return self.getContentObject().download() + elif act == 'view': + #return self.getContentObject().download() + return self.getContentObject().index_html(REQUEST=REQUEST, RESPONSE=RESPONSE) + else: + return self.history() def getVersionNr(self,nr): """get version with number nr""" 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 + security.declarePublic('getVersion') def getVersion(self): # TODO: this is ugly and it returns the next version number @@ -1116,11 +1123,12 @@ class extVersionedFile(CatalogAware,Fold """unlock""" if str(self.lockedBy) in [str(self.REQUEST['AUTHENTICATED_USER'])]: self.lockedBy='' - self.redirect(RESPONSE,self.REQUEST['HTTP_REFERER'],) + RESPONSE.redirect(self.REQUEST['HTTP_REFERER']) else: return "Sorry, not locked by you! (%s,%s)"%(self.lockedBy,self.REQUEST['AUTHENTICATED_USER']) + def _newContentObject(self, id, title='', versionNumber=0, versionComment=None, time=None, author=None): """factory for content objects. to be overridden in derived classes.""" return extVersionedFileObject(id,title,versionNumber=versionNumber,versionComment=versionComment,time=time,author=author) @@ -1228,10 +1236,11 @@ class extVersionedFile(CatalogAware,Fold changeVersionedFileForm = PageTemplateFile('zpt/changeVersionedFile', globals()) - def manage_changeVersionedFile(self,title,vC,author,comment,RESPONSE=None): + def manage_changeVersionedFile(self,title,vC,author,comment,defaultAction='history',RESPONSE=None): """Change VersionedFile metadata""" self.title = title self.author = author + self.defaultAction = defaultAction cob = self.getContentObject() if cob: if vC: @@ -1293,9 +1302,9 @@ def manage_addextVersionedFileForm(self) pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addextVersionedFile.zpt')).__of__(self) return pt() -def manage_addextVersionedFile(self,id,title,lockedBy, author=None, RESPONSE=None): +def manage_addextVersionedFile(self,id,title,lockedBy, author=None, defaultAction='history', RESPONSE=None): """add the OSAS_root""" - newObj=extVersionedFile(id,title,lockedBy,author) + newObj=extVersionedFile(id,title,lockedBy,author,defaultAction=defaultAction) self._setObject(id,newObj) if RESPONSE is not None: