Diff for /versionedFile/extVersionedFile.py between versions 1.6 and 1.7

version 1.6, 2007/08/31 13:31:20 version 1.7, 2007/09/10 16:34:16
Line 41  except: Line 41  except:
           
 def sortv(x,y):  def sortv(x,y):
     return cmp(x[0],y[0])      return cmp(x[0],y[0])
   
 tdir = "/tmp/downloadVersionedFiles"  tdir = "/tmp/downloadVersionedFiles"
   
 class generateDownloadZip:  class generateDownloadZip:
Line 71  class generateDownloadZip: Line 72  class generateDownloadZip:
         self.response="<h3>1. step: getting the files</h3>"          self.response="<h3>1. step: getting the files</h3>"
   
         for files in self.folder.ZopeFind(self.folder,obj_metatypes=['extVersionedFile']):          for files in self.folder.ZopeFind(self.folder,obj_metatypes=['extVersionedFile']):
             lastV=files[1].getLastVersion()              lastV=files[1].getContentObject()
             self.response+=str("<p>Get File: %s<br>\n"%lastV.title)              self.response+=str("<p>Get File: %s<br>\n"%lastV.title)
   
             savePath=os.path.join(tmpPath,lastV.title)              savePath=os.path.join(tmpPath,lastV.title)
Line 122  class extVersionedFileFolder(Folder,ECHO Line 123  class extVersionedFileFolder(Folder,ECHO
     security= ClassSecurityInfo()      security= ClassSecurityInfo()
     security.declareProtected('AUTHENTICATED_USER','addFileForm')      security.declareProtected('AUTHENTICATED_USER','addFileForm')
   
     filesMetaType=['extVersionedFile']      file_meta_type=['extVersionedFile']
   
     if ECHO_basis:      if ECHO_basis:
         optTMP= Folder.manage_options+ECHO_basis.manage_options          optTMP= Folder.manage_options+ECHO_basis.manage_options
Line 357  class extVersionedFileFolder(Folder,ECHO Line 358  class extVersionedFileFolder(Folder,ECHO
             return cmp(x[1].title.lower(),y[1].title.lower())              return cmp(x[1].title.lower(),y[1].title.lower())
   
         def sortDate(x,y):          def sortDate(x,y):
             return cmp(y[1].getLastVersion().getTime(),x[1].getLastVersion().getTime())              return cmp(y[1].getContentObject().getTime(),x[1].getContentObject().getTime())
   
         def sortComment(x,y):          def sortComment(x,y):
             try:              try:
Line 372  class extVersionedFileFolder(Folder,ECHO Line 373  class extVersionedFileFolder(Folder,ECHO
   
             if (xc=='') or (xc=='ZZZZZZZZZZZZZ'.lower()):              if (xc=='') or (xc=='ZZZZZZZZZZZZZ'.lower()):
                 try:                  try:
                     xc=x[1].getLastVersion().getVComment().lower()                      xc=x[1].getContentObject().getVComment().lower()
                 except:                  except:
                     xc='ZZZZZZZZZZZZZ'.lower()                      xc='ZZZZZZZZZZZZZ'.lower()
                                                           
             if (yc=='') or (yc=='ZZZZZZZZZZZZZ'.lower()):              if (yc=='') or (yc=='ZZZZZZZZZZZZZ'.lower()):
                 try:                  try:
                     yc=y[1].getLastVersion().getVComment().lower()                      yc=y[1].getContentObject().getVComment().lower()
                 except:                  except:
                     yc='ZZZZZZZZZZZZZ'.lower()                      yc='ZZZZZZZZZZZZZ'.lower()
                                                                           
Line 386  class extVersionedFileFolder(Folder,ECHO Line 387  class extVersionedFileFolder(Folder,ECHO
   
         def sortAuthor(x,y):          def sortAuthor(x,y):
                           
             return cmp(x[1].getLastVersion().lastEditor().lower(),y[1].getLastVersion().lastEditor().lower())              return cmp(x[1].getContentObject().lastEditor().lower(),y[1].getContentObject().lastEditor().lower())
                   
         versionedFiles=self.ZopeFind(self,obj_metatypes=self.filesMetaType)          versionedFiles=self.objectItems(self.file_meta_type)
           logging.debug("versionedfiles: %s of type %s"%(repr(versionedFiles),repr(self.file_meta_type)))
                   
         if sortField=='title':          if sortField=='title':
             versionedFiles.sort(sortName)              versionedFiles.sort(sortName)
Line 449  class extVersionedFileFolder(Folder,ECHO Line 451  class extVersionedFileFolder(Folder,ECHO
         manage_addextVersionedFile(self,id,'','')          manage_addextVersionedFile(self,id,'','')
         #if (getattr(self,'commentNonEmpty',0)==1) and vC.strip()=="":          #if (getattr(self,'commentNonEmpty',0)==1) and vC.strip()=="":
                   
           
         ob=self._getOb(id)          ob=self._getOb(id)
         ob.title=id          ob.title=id
         file2=file          file2=file
Line 479  class extVersionedFileFolder(Folder,ECHO Line 480  class extVersionedFileFolder(Folder,ECHO
         RESPONSE.redirect(self.REQUEST['URL1'])          RESPONSE.redirect(self.REQUEST['URL1'])
                   
                   
       security.declareProtected('AUTHENTICATED_USER','fixVersionNumbers')    
       def fixVersionNumbers(self):
           """fix last version number of all files"""
           for (id,vf) in self.getVersionedFiles():
               vf.fixVersionNumbers()
           
 manage_addextVersionedFileFolderForm=DTMLFile('dtml/extfolderAdd', globals())  manage_addextVersionedFileFolderForm=DTMLFile('dtml/extfolderAdd', globals())
   
   
Line 522  class extVersionedFileObject(ExtFile): Line 529  class extVersionedFileObject(ExtFile):
                                Kind='File',kind='file')                                 Kind='File',kind='file')
     manage_editForm._setName('manage_editForm')      manage_editForm._setName('manage_editForm')
   
       def __init__(self, id, title='', versionNumber=0, versionComment=None, time=None, author=None):
           """Initialize a new instance of extVersionedFileObject (taken from ExtFile)"""
           ExtFile.__init__(self,id,title)
           self.versionNumber = versionNumber
           self.versionComment= versionComment
           self.time = time
           self.author = author
   
   
     security.declarePublic('getTitle')      security.declarePublic('getTitle')
     def getTitle(self):      def getTitle(self):
         """get title"""          """get title"""
Line 542  class extVersionedFileObject(ExtFile): Line 558  class extVersionedFileObject(ExtFile):
                   
     def manageVCommentForm(self):      def manageVCommentForm(self):
         """add a comment"""          """add a comment"""
   
         self.REQUEST.SESSION['refer']=self.REQUEST['HTTP_REFERER']          self.REQUEST.SESSION['refer']=self.REQUEST['HTTP_REFERER']
         pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addVComment')).__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addVComment')).__of__(self)
         return pt()          return pt()
Line 570  class extVersionedFileObject(ExtFile): Line 585  class extVersionedFileObject(ExtFile):
         return self.versionComment          return self.versionComment
           
     security.declarePublic('getTime')      security.declarePublic('getTime')
   
     def getTime(self):      def getTime(self):
         """getTime"""          """getTime"""
         #return self.bobobase_modification_time().ISO()          #return self.bobobase_modification_time().ISO()
Line 582  class extVersionedFileObject(ExtFile): Line 596  class extVersionedFileObject(ExtFile):
             setattr(self,'timefixed',self.bobobase_modification_time().ISO())              setattr(self,'timefixed',self.bobobase_modification_time().ISO())
             return self.bobobase_modification_time().ISO()              return self.bobobase_modification_time().ISO()
   
   
   
       
   
     def download(self,REQUEST=None,RESPONSE=None):      def download(self,REQUEST=None,RESPONSE=None):
         """download and lock"""          """download and lock"""
                   
Line 620  class extVersionedFileObject(ExtFile): Line 630  class extVersionedFileObject(ExtFile):
         self.content_type="application/octet-stream"          self.content_type="application/octet-stream"
         self.REQUEST.RESPONSE.redirect(self.absolute_url())          self.REQUEST.RESPONSE.redirect(self.absolute_url())
           
     def setVersionNumber(self,versionNumber):  
         """set version"""  
         self.versionNumber=versionNumber  
   
   
     security.declarePublic('getVersionNumber')                                                    security.declarePublic('getVersionNumber')                                              
     def getVersionNumber(self):      def getVersionNumber(self):
         """get version"""          """get version"""
Line 635  class extVersionedFileObject(ExtFile): Line 640  class extVersionedFileObject(ExtFile):
         """get version"""          """get version"""
         return self.versionComment          return self.versionComment
   
       
   
     security.declarePublic('lastEditor')                                                      security.declarePublic('lastEditor')                                                
     def lastEditor(self):      def lastEditor(self):
         """last Editor"""          """last Editor"""
Line 659  class extVersionedFileObject(ExtFile): Line 662  class extVersionedFileObject(ExtFile):
                   
 manage_addextVersionedFileObjectForm=DTMLFile('dtml/fileAdd', globals(),Kind='extVersionedFileObject',kind='extVersionedFileObject', version='1')  manage_addextVersionedFileObjectForm=DTMLFile('dtml/fileAdd', globals(),Kind='extVersionedFileObject',kind='extVersionedFileObject', version='1')
   
 def manage_addextVersionedFileObject(self,id,vC='',author='', file='',title='',precondition='', content_type='',  def manage_addextVersionedFileObject(self,id,vC='',author='', file='',title='',versionNumber=0,
                                      REQUEST=None):                                       precondition='', content_type='', REQUEST=None):
     """Add a new File object.      """Add a new File object.
   
     Creates a new File object 'id' with the contents of 'file'"""      Creates a new File object 'id' with the contents of 'file'"""
Line 675  def manage_addextVersionedFileObject(sel Line 678  def manage_addextVersionedFileObject(sel
     self=self.this()      self=self.this()
   
     # First, we create the file without data:      # First, we create the file without data:
     self._setObject(id, extVersionedFileObject(id,title,'',content_type, precondition))      self._setObject(id, extVersionedFileObject(id,title,versionNumber=versionNumber,versionComment=str(vC),author=author))
     self._getOb(id).versionComment=str(vC)      fob = self._getOb(id)
     self._getOb(id).time=time.localtime()  
       
     setattr(self._getOb(id),'author',author)  
           
     # Now we "upload" the data.  By doing this in two steps, we      # Now we "upload" the data.  By doing this in two steps, we
     # can use a database trick to make the upload more efficient.      # can use a database trick to make the upload more efficient.
     if file:      if file:
         self._getOb(id).manage_upload(file)          fob.manage_upload(file)
     if content_type:      if content_type:
         self._getOb(id).content_type=content_type          fob.content_type=content_type
   
     if REQUEST is not None:      if REQUEST is not None:
         REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main')          REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main')
   
   
   
   
 class extVersionedFile(CatalogAware,Folder):  class extVersionedFile(CatalogAware,Folder):
     """Versioniertes File"""      """Versioniertes File"""
   
       meta_type = 'extVersionedFile'
       # meta_type of contained objects
       content_meta_type = ['extVersionedFileObject']
     default_catalog='fileCatalog'      default_catalog='fileCatalog'
           
     security= ClassSecurityInfo()         security= ClassSecurityInfo()   
           
       def __init__(self, id, title, lockedBy,author):
           """init"""
           self.id=id
           self.title=title
           self.lockedBy=lockedBy
           self.author=author
           self.lastVersionNumber=0
           self.lastVersionId=None
   
     security.declarePublic('getTitle')      security.declarePublic('getTitle')
     def getTitle(self):      def getTitle(self):
         """get title"""          """get title"""
Line 710  class extVersionedFile(CatalogAware,Fold Line 721  class extVersionedFile(CatalogAware,Fold
         """Return cataloguable key for ourselves."""          """Return cataloguable key for ourselves."""
         return str(self)          return str(self)
           
     def __init__(self, id, title, lockedBy,author):  
         """init"""  
         self.id=id  
         self.title=title  
         self.lockedBy=lockedBy  
         self.author=author  
   
     def manageImagesForm(self):      def manageImagesForm(self):
         """manage Images attached to the file"""          """manage Images attached to the file"""
   
Line 735  class extVersionedFile(CatalogAware,Fold Line 739  class extVersionedFile(CatalogAware,Fold
             return REQUEST.RESPONSE.redirect(self.REQUEST.SESSION['refer'])              return REQUEST.RESPONSE.redirect(self.REQUEST.SESSION['refer'])
         return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url())          return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url())
           
       
       
     def changeImages(self,caption=None,submit=None,id=None,REQUEST=None):      def changeImages(self,caption=None,submit=None,id=None,REQUEST=None):
         """manage URL"""          """manage URL"""
         if submit=="change caption":          if submit=="change caption":
Line 749  class extVersionedFile(CatalogAware,Fold Line 751  class extVersionedFile(CatalogAware,Fold
             if image:              if image:
                 self.manage_delObjects([image[0][1].getId()])                  self.manage_delObjects([image[0][1].getId()])
   
   
         if self.REQUEST.SESSION.has_key('refer'):          if self.REQUEST.SESSION.has_key('refer'):
   
             return REQUEST.RESPONSE.redirect(self.REQUEST.SESSION['refer'])              return REQUEST.RESPONSE.redirect(self.REQUEST.SESSION['refer'])
         return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url())  
       
       
   
           return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url())
   
     def getImages(self):      def getImages(self):
         """get Images"""          """get Images"""
Line 771  class extVersionedFile(CatalogAware,Fold Line 769  class extVersionedFile(CatalogAware,Fold
         """get the comment of this file"""          """get the comment of this file"""
         if not hasattr(self,'comment') or (not self.comment) or (self.comment.lstrip()==""):          if not hasattr(self,'comment') or (not self.comment) or (self.comment.lstrip()==""):
             return "Add comment"              return "Add comment"
   
         else:          else:
             return self.comment              return self.comment
                   
           
     meta_type="extVersionedFile"  
   
     def manageCommentForm(self):      def manageCommentForm(self):
         """add a comment"""          """add a comment"""
         pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addComment')).__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addComment')).__of__(self)
Line 797  class extVersionedFile(CatalogAware,Fold Line 791  class extVersionedFile(CatalogAware,Fold
         return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url())          return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url())
           
     security.declarePublic('getLastChangeDate')      security.declarePublic('getLastChangeDate')
       
     def getLastChangeDate(self):      def getLastChangeDate(self):
         """get last change date"""          """get last change date"""
         lv=self.getLastVersion()          lv=self.getContentObject()
         time=lv.getTime()          time=lv.getTime()
         return time          return time
           
     def getLastEditor(self):      def getLastEditor(self):
         """get last change date"""          """get last change date"""
         lv=self.getLastVersion()          lv=self.getContentObject()
         le=lv.lastEditor()          le=lv.lastEditor()
         return le          return le
           
Line 814  class extVersionedFile(CatalogAware,Fold Line 807  class extVersionedFile(CatalogAware,Fold
         """get locked by"""          """get locked by"""
         return str(self.lockedBy)          return str(self.lockedBy)
           
       def getLastVersionNumber(self):
           """returns the highest version number of all included objects"""
           lv = self.findLastVersion()
           if lv:
               return lv.getVersionNumber()
           else:
               return 0
   
       def findLastVersion(self):
           """finds and returns the object with the highest version number"""
           lvn=0
           lv=None
           
           for v in self.objectValues(self.content_meta_type):
               logging.debug("findlastversion: check %s"%v.getId())
               if v.getVersionNumber() > lvn:
                       lvn=v.getVersionNumber()
                       lv=v
           
           if lv:
               logging.debug("findlastversion: got %s"%lv.getId())
           return lv
   
     security.declarePublic('getLastVersion')      security.declarePublic('getLastVersion')
     def getLastVersion(self):      def getLastVersion(self):
         """Last Version"""          """Last Version (old)"""
         tmp=0          tmp=0
         lastVersion=None          lv=None
           
         for version in self.ZopeFind(self):  
                           
             if hasattr(version[1],'versionNumber'):          for v in self.objectValues(self.content_meta_type):
               logging.debug("getlastversion: check %s"%v.getId())
               if v.getVersionNumber() > tmp:
                       tmp=v.getVersionNumber()
                       lv=v
           
           logging.debug("getlastversion: got %s"%lv.getId())
           return lv
   
       def getContentObject(self):
           """returns the last version object"""
           if not self.lastVersionId:
               lv = self.findLastVersion()
               if lv is None:
                   return None
               self.lastVersionNumber = lv.getVersionNumber()
               self.lastVersionId = lv.getId()
                                   
                 if int(version[1].versionNumber) > tmp:          return getattr(self, self.lastVersionId)
                     tmp=int(version[1].versionNumber,)  
                     lastVersion=version[1]  
             if lastVersion==None:  
                 lastVersion=version[1]  
                 lastVersion.versionNumber=1  
         return lastVersion  
           
       security.declarePublic('getData')
       def getData(self):
           """Returns the content of the last version"""
           ob = self.getContentObject()
           if ob is not None:
               return ob.getData()
           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()
         tmp=self.getLastVersion().getData()          tmp=self.getData()
         #print "XX",data,tmp          #print "XX",data,tmp
         try:          try:
             l=list(d.compare(data.splitlines(1),tmp.splitlines(1)))              l=list(d.compare(data.splitlines(1),tmp.splitlines(1)))
Line 856  class extVersionedFile(CatalogAware,Fold Line 888  class extVersionedFile(CatalogAware,Fold
     security.declarePublic('index_html')      security.declarePublic('index_html')
     def index_html(self):      def index_html(self):
         """main view"""          """main view"""
         #lastVersion=self.getLastVersion()          #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())
         return self.history()          return self.history()
Line 864  class extVersionedFile(CatalogAware,Fold Line 896  class extVersionedFile(CatalogAware,Fold
           
     security.declarePublic('getVersion')                                                    security.declarePublic('getVersion')                                              
     def getVersion(self):      def getVersion(self):
           # TODO: this is ugly and it returns the next version number 
         tmp=0          tmp=0
         for version in self.ZopeFind(self):          for version in self.ZopeFind(self):
                           
Line 873  class extVersionedFile(CatalogAware,Fold Line 906  class extVersionedFile(CatalogAware,Fold
                     tmp=int(version[1].versionNumber,)                      tmp=int(version[1].versionNumber,)
         return tmp+1          return tmp+1
   
   
     def history(self):      def history(self):
         """history"""            """history"""  
   
         ext=self.ZopeFind(self.aq_parent,obj_ids=["history_template.html"])          ext=self.ZopeFind(self.aq_parent,obj_ids=["history_template.html"])
         if ext:          if ext:
             return getattr(self,ext[0][1].getId())()              return getattr(self,ext[0][1].getId())()
Line 914  class extVersionedFile(CatalogAware,Fold Line 945  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):
           """factory for content objects. to be overridden in derived classes."""
           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,
                            precondition='', content_type=''):
           """add"""
           
           if changeName=="yes":
               filename=file.filename
               self.title=filename[max(filename.rfind('/'),
                                       filename.rfind('\\'),
                                       filename.rfind(':'),
                                       )+1:]
   
           if not newName=='':
               self.title=newName[0:]
           
           posVersNum=getattr(self,'positionVersionNum','front')
           
           versNum = self.getLastVersionNumber() + 1
           
           if posVersNum=='front':
               id="V%i_%s"%(versNum,self.title)
           else:
               fn=os.path.splitext(self.title)
               if len(fn)>1:
                   id=fn[0]+"_V%i%s"%(versNum,fn[1])
               else:
                   id=fn[0]+"_V%i"%versNum
   
           # what does this do?
           id, title = cookId(id, title, file)
           self=self.this()
       
           # First, we create the file without data:
           self._setObject(id, self._newContentObject(id,title,versionNumber=versNum,versionComment=str(vC),
                                                 time=time.localtime(),author=author))
           fob = self._getOb(id)
           
           # Now we "upload" the data.  By doing this in two steps, we
           # can use a database trick to make the upload more efficient.
           if file and not from_tmp:
               fob.manage_upload(file)
           elif file and from_tmp:
               fob.manage_file_upload(file) # manage_upload_from_tmp doesn't exist in ExtFile2
           #    fob.manage_upload_from_tmp(file) # manage_upload_from_tmp doesn't exist in ExtFile2
           fob.content_type=content_type
           
           self.lastVersionNumber = versNum
           self.lastVersionId = id
           
           logging.debug("addcontentobject: lastversion=%s"%self.getData())
           logging.debug("reindex1: %s in %s"%(repr(self),repr(self.default_catalog)))
           self.reindex_object()
           logging.debug("addcontentobject: fob_data=%s"%fob.getData())
           
           return fob
               
           
     security.declareProtected('AUTHENTICATED_USER','addVersionedFileObjectForm')      security.declareProtected('AUTHENTICATED_USER','addVersionedFileObjectForm')
     def addVersionedFileObjectForm(self):      def addVersionedFileObjectForm(self):
Line 924  class extVersionedFile(CatalogAware,Fold Line 1015  class extVersionedFile(CatalogAware,Fold
         if (self.lockedBy==self.REQUEST['AUTHENTICATED_USER']) or (self.lockedBy==''):          if (self.lockedBy==self.REQUEST['AUTHENTICATED_USER']) or (self.lockedBy==''):
             ext=self.ZopeFind(self.aq_parent,obj_ids=["addNewVersion.dtml"])              ext=self.ZopeFind(self.aq_parent,obj_ids=["addNewVersion.dtml"])
             if ext:              if ext:
                 return ext[0][1]('',globals(),version=self.getVersion(),lastComment=self.getLastVersion().getVersionComment(),AUTHENTICATED_USER=self.REQUEST.AUTHENTICATED_USER)                  return ext[0][1]('',globals(),version=self.getVersion(),lastComment=self.getContentObject().getVersionComment(),AUTHENTICATED_USER=self.REQUEST.AUTHENTICATED_USER)
             else:              else:
                 out=DTMLFile('dtml/fileAdd', globals(),Kind='VersionedFileObject',kind='versionedFileObject',version=self.getVersion()).__of__(self)                  out=DTMLFile('dtml/fileAdd', globals(),Kind='VersionedFileObject',kind='versionedFileObject',version=self.getVersion()).__of__(self)
                 return out()                  return out()
         else:          else:
             return "Sorry file is locked by somebody else"              return "Sorry file is locked by somebody else"
                   
     def manage_addVersionedFileObject(self,id,vC,author,file='',title='',precondition='', content_type='',changeName='no',newName='', RESPONSE=None):          
       def manage_addVersionedFileObject(self,id,vC,author,file='',title='',precondition='', content_type='',changeName='no',newName='', from_tmp=False, RESPONSE=None):
         """add"""          """add"""
         try: #der ganze vC unsinn muss ueberarbeitet werden          try: #der ganze vC unsinn muss ueberarbeitet werden
             vC=self.REQUEST['vC']              vC=self.REQUEST['vC']
Line 940  class extVersionedFile(CatalogAware,Fold Line 1032  class extVersionedFile(CatalogAware,Fold
                   
         author=self.REQUEST['author']          author=self.REQUEST['author']
                   
         if changeName=="yes":          ob = self.addContentObject(id, vC, author, file, title, changeName=changeName, newName=newName, from_tmp=from_tmp,
             filename=file.filename                                     precondition=precondition, content_type=content_type)
             self.title=filename[max(filename.rfind('/'),  
                                     filename.rfind('\\'),  
                                     filename.rfind(':'),  
                                     )+1:]  
   
         if not newName=='':  
             self.title=newName[0:]  
           
         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_addextVersionedFileObject(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()          self.REQUEST.SESSION['objID_parent']=self.getId()
   
         if getattr(self,'defaultFileCatalog',None):  
               
             self.reindex_object()  
               
         if RESPONSE:          if RESPONSE:
             obj=self.ZopeFind(self,obj_ids=[id])[0][1]              if ob.getSize()==0:
             if obj.getSize()==0:                  self.REQUEST.SESSION['objID']=ob.getId()
                 self.REQUEST.SESSION['objID']=obj.getId()  
                 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','errorUploadFile')).__of__(self)                  pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','errorUploadFile')).__of__(self)
                 return pt()                  return pt()
   
             else:              else:
                 RESPONSE.redirect(self.REQUEST['URL2'])                  RESPONSE.redirect(self.REQUEST['URL2'])
   
         else:          else:
             return self.ZopeFind(self,obj_ids=[id])[0][1]              return ob
   
                   
     def download(self):      def download(self):
         """download and lock"""          """download and lock"""
         self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getLastVersion().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.getLastVersion().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):
Line 999  class extVersionedFile(CatalogAware,Fold Line 1065  class extVersionedFile(CatalogAware,Fold
         if not self.lockedBy=="":          if not self.lockedBy=="":
             return "cannot be locked because is already locked by %s"%self.lockedBy              return "cannot be locked because is already locked by %s"%self.lockedBy
         self.lockedBy=self.REQUEST['AUTHENTICATED_USER']          self.lockedBy=self.REQUEST['AUTHENTICATED_USER']
         self.getLastVersion().content_type="application/octet-stream"          self.getContentObject().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.getContentObject().getId())
       
   
       security.declareProtected('AUTHENTICATED_USER','fixVersionNumbers')    
       def fixVersionNumbers(self):
           """check last version number and id"""
           if not hasattr(self, 'lastVersionId'):
               self.lastVersionNumber = 0
               self.lastVersionId = None
               
           lv = self.getContentObject()
           if lv is not None:
               lvn = lv.getVersionNumber()
               if lvn == 0:
                   lvn = 1
                   lv.versionNumber = 1
               self.lastVersionNumber = lvn
               self.lastVersionId = lv.getId()
           else:
               self.lastVersionNumber = 0
               self.lastVersionId = None
           logging.debug("fixing last version number of %s to %s (%s)"%(self.getId(),self.lastVersionNumber,self.lastVersionId))
       
           
 def manage_addextVersionedFileForm(self):  def manage_addextVersionedFileForm(self):
     """interface for adding the OSAS_root"""      """interface for adding the OSAS_root"""

Removed from v.1.6  
changed lines
  Added in v.1.7


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