Diff for /versionedFile/extVersionedFile.py between versions 1.22 and 1.35

version 1.22, 2008/06/27 17:46:45 version 1.35, 2010/03/31 17:07:43
Line 3  using the ExtFile Product, this version Line 3  using the ExtFile Product, this version
 DW 11.10.2006  DW 11.10.2006
 """  """
   
   import email
 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
Line 142  class extVersionedFileFolder(Folder,ECHO Line 143  class extVersionedFileFolder(Folder,ECHO
         )          )
   
           
       def redirect(self,RESPONSE,url):
           """mache ein redirect mit einem angehaengten time stamp um ein reload zu erzwingen"""
           
           timeStamp=time.time()
           
           if url.find("?")>-1: #giebt es schon parameter
               addStr="&time=%s"
           else:
               addStr="?time=%s"
               
           RESPONSE.setHeader('Last-Modified',email.Utils.formatdate().split("-")[0]+'GMT')
           logging.error(email.Utils.formatdate()+' GMT')
           RESPONSE.redirect(url+addStr%timeStamp)
           
     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 514  class extVersionedFileFolder(Folder,ECHO Line 529  class extVersionedFileFolder(Folder,ECHO
                   
         # get new extVersionedFile          # get new extVersionedFile
         vf = self._newVersionedFile(id,title=id)          vf = self._newVersionedFile(id,title=id)
         logging.debug("addFile id=%s vf=%s of %s"%(repr(id),repr(vf),repr(self)))          logging.error("addFile id=%s vf=%s of %s"%(repr(id),repr(vf),repr(self)))
         # add its content (and don't index)          # 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)          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)          # add file to this folder (this should do the indexing)
         self._setObject(id,vf)          #self._setObject(id,vf)
                   
         try:          try:
             self.REQUEST.SESSION['objID']=vf.getId()              self.REQUEST.SESSION['objID']=vf.getId()
Line 615  class extVersionedFileObject(ExtFile): Line 633  class extVersionedFileObject(ExtFile):
   
     security.declareProtected('manage','changeObject')      security.declareProtected('manage','changeObject')
     def changeObject(self,**args):      def changeObject(self,**args):
         """modify object"""          """modify any of the objects attributes"""
         for arg in args:          for arg in args:
             if hasattr(self, arg):              if hasattr(self, arg):
                 logging.debug("changeObject arg:%s = %s"%(arg,args[arg]))                  logging.debug("changeObject %s: %s=%s"%(repr(self),arg,args[arg]))
                 setattr(self, arg, args[arg])                  setattr(self, arg, args[arg])
   
     security.declarePublic('getTitle')      security.declarePublic('getTitle')
Line 628  class extVersionedFileObject(ExtFile): Line 646  class extVersionedFileObject(ExtFile):
           
     def getData(self):      def getData(self):
         """returns object content (calls ExtFile.index_html)"""          """returns object content (calls ExtFile.index_html)"""
           #logging.debug("+++++++getData1:"+repr(self.get_filename()))
           filename = self.get_filename()
           #return ExtFile.index_html(self)
           try:
               logging.info("readfile:"+filename)
               return file(filename).read()
           except:
               logging.info("cannot readfile:"+filename)
         return ExtFile.index_html(self)          return ExtFile.index_html(self)
           
       
       def getFileName(self):
           """return filename"""
           return self.get_filename()
       
       def addToFile(self,filehandle):
           filehandle.write(self.getData())
           
       def addToFile2(self,filename):   
            str="cat %s > %s"%(self.get_filename(),filename)
            os.popen(str)
            
     security.declarePublic('getVComment')      security.declarePublic('getVComment')
     def getVComment(self):      def getVComment(self):
         """get the comment of this file"""          """get the comment of this file"""
Line 692  class extVersionedFileObject(ExtFile): Line 730  class extVersionedFileObject(ExtFile):
     #self.REQUEST.RESPONSE.setHeader("Content-Length","str(len(txt)+1000)")      #self.REQUEST.RESPONSE.setHeader("Content-Length","str(len(txt)+1000)")
                   
         self.content_type="application/octet-stream"          self.content_type="application/octet-stream"
         self.REQUEST.RESPONSE.redirect(self.absolute_url())          return self.getData()
           #self.REQUEST.RESPONSE.redirect(self.absolute_url())
         #txt=urllib.urlopen(self.absolute_url()).read()          #txt=urllib.urlopen(self.absolute_url()).read()
         #self.REQUEST.RESPONSE.write(txt)          #self.REQUEST.RESPONSE.write(txt)
           
Line 704  class extVersionedFileObject(ExtFile): Line 743  class extVersionedFileObject(ExtFile):
     security.declareProtected('AUTHENTICATED_USER','downloadLocked')          security.declareProtected('AUTHENTICATED_USER','downloadLocked')    
     def downloadLocked(self):      def downloadLocked(self):
         """download and lock"""          """download and lock"""
           
           
         if repr(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=="":
Line 792  class extVersionedFile(CatalogAware,Fold Line 829  class extVersionedFile(CatalogAware,Fold
           
     security=ClassSecurityInfo()         security=ClassSecurityInfo()   
           
     def __init__(self, id, title, lockedBy,author):      def __init__(self, id, title, lockedBy,author,defaultAction='history'):
         """init"""          """init"""
         self.id=id          self.id=id
         self.title=title          self.title=title
         self.lockedBy=lockedBy          self.lockedBy=lockedBy
           if self.lockedBy is None:
               self.lockedBy = ''
         self.author=author          self.author=author
         self.lastVersionNumber=0          self.lastVersionNumber=0
         self.lastVersionId=None          self.lastVersionId=None
           self.defaultAction = defaultAction
   
     security.declarePublic('getTitle')      security.declarePublic('getTitle')
     def getTitle(self):      def getTitle(self):
Line 896  class extVersionedFile(CatalogAware,Fold Line 936  class extVersionedFile(CatalogAware,Fold
           
     def getLockedBy(self):      def getLockedBy(self):
         """get locked by"""          """get locked by"""
           if self.lockedBy is None:
               self.lockedBy = ''
         return str(self.lockedBy)          return str(self.lockedBy)
           
     def getLastVersionNumber(self):      def getLastVersionNumber(self):
Line 928  class extVersionedFile(CatalogAware,Fold Line 970  class extVersionedFile(CatalogAware,Fold
         lv=None          lv=None
                   
         for v in self.objectValues(self.content_meta_type):          for v in self.objectValues(self.content_meta_type):
             logging.debug("getlastversion: check %s"%v.getId())              #logging.debug("getlastversion: check %s"%v.getId())
             if v.getVersionNumber() > tmp:              if v.getVersionNumber() > tmp:
                     tmp=v.getVersionNumber()                      tmp=v.getVersionNumber()
                     lv=v                      lv=v
                   
         logging.debug("getlastversion: got %s"%lv.getId())          #ogging.debug("getlastversion: got %s"%lv.getId())
         return lv          return lv
   
     def getContentObject(self):      def getContentObject(self):
Line 951  class extVersionedFile(CatalogAware,Fold Line 993  class extVersionedFile(CatalogAware,Fold
     security.declarePublic('getData')      security.declarePublic('getData')
     def getData(self):      def getData(self):
         """Returns the content of the last version"""          """Returns the content of the last version"""
           logging.debug("+++++++getData2")
         ob = self.getContentObject()          ob = self.getContentObject()
         if ob is not None:          if ob is not None:
             return ob.getData()              return ob.getData()
Line 987  class extVersionedFile(CatalogAware,Fold Line 1030  class extVersionedFile(CatalogAware,Fold
   
   
     security.declarePublic('index_html')      security.declarePublic('index_html')
     def index_html(self):      def index_html(self,REQUEST=None, RESPONSE=None):
         """main view"""          """main view"""
         #lastVersion=self.getContentObject()          #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:"+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())
           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()          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')                                                    security.declarePublic('getVersion')                                              
     def getVersion(self):      def getVersion(self):
Line 1039  class extVersionedFile(CatalogAware,Fold Line 1099  class extVersionedFile(CatalogAware,Fold
         return vl          return vl
   
     security.declareProtected('AUTHENTICATED_USER','forceunlock')         security.declareProtected('AUTHENTICATED_USER','forceunlock')   
     def forceunlock(self,RESPONSE=None):      def forceunlock(self,RESPONSE=None,user=None):
         """unlock"""          """unlock"""
         #safe who had the lock          #safe who had the lock
           logging.debug("extVersionFile: (forceunlock)"+str(user))
         if self.lockedBy:          if self.lockedBy:
               if user is not None:
                   if str(self.lockedBy)==user:
             self.brokenLock=str(self.lockedBy)              self.brokenLock=str(self.lockedBy)
                       self.lockedBy=''
         else:          else:
             self.brokenLock=""              self.brokenLock=""
               else:
                   self.brokenLock=str(self.lockedBy)
         self.lockedBy=''          self.lockedBy=''
           else:
               self.brokenLock=""
           
         return self.brokenLock          return self.brokenLock
   
     security.declareProtected('AUTHENTICATED_USER','unlock')         security.declareProtected('AUTHENTICATED_USER','unlock')   
Line 1059  class extVersionedFile(CatalogAware,Fold Line 1128  class extVersionedFile(CatalogAware,Fold
             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'])
                   
           
   
     def _newContentObject(self, id, title='', versionNumber=0, versionComment=None, time=None, author=None):      def _newContentObject(self, id, title='', versionNumber=0, versionComment=None, time=None, author=None):
         """factory for content objects. to be overridden in derived classes."""          """factory for content objects. to be overridden in derived classes."""
         return extVersionedFileObject(id,title,versionNumber=versionNumber,versionComment=versionComment,time=time,author=author)          return extVersionedFileObject(id,title,versionNumber=versionNumber,versionComment=versionComment,time=time,author=author)
Line 1166  class extVersionedFile(CatalogAware,Fold Line 1236  class extVersionedFile(CatalogAware,Fold
   
     changeVersionedFileForm = PageTemplateFile('zpt/changeVersionedFile', globals())      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"""          """Change VersionedFile metadata"""
         self.title = title          self.title = title
         self.author = author          self.author = author
           self.defaultAction = defaultAction
         cob = self.getContentObject()          cob = self.getContentObject()
         if cob:          if cob:
             if vC:              if vC:
Line 1186  class extVersionedFile(CatalogAware,Fold Line 1257  class extVersionedFile(CatalogAware,Fold
                   
     def download(self):      def download(self):
         """download"""          """download"""
         self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getContentObject().getId())      
         self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream")          txt=self.REQUEST['URL1']+'/'+self.getId()+'/'+self.getContentObject().getId()+'/download'
         self.content_type="application/octet-stream"          
         self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'/'+self.getId()+'/'+self.getContentObject().getId())          self.REQUEST.RESPONSE.redirect(txt)
   
           
     security.declareProtected('AUTHENTICATED_USER','downloadLocked')          security.declareProtected('AUTHENTICATED_USER','downloadLocked')    
Line 1231  def manage_addextVersionedFileForm(self) Line 1302  def manage_addextVersionedFileForm(self)
     pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addextVersionedFile.zpt')).__of__(self)      pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addextVersionedFile.zpt')).__of__(self)
     return pt()      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"""      """add the OSAS_root"""
     newObj=extVersionedFile(id,title,lockedBy,author)      newObj=extVersionedFile(id,title,lockedBy,author,defaultAction=defaultAction)
     self._setObject(id,newObj)      self._setObject(id,newObj)
           
     if RESPONSE is not None:      if RESPONSE is not None:

Removed from v.1.22  
changed lines
  Added in v.1.35


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>