Diff for /versionedFile/versionedFile.py between versions 1.39 and 1.54

version 1.39, 2005/07/04 10:59:03 version 1.54, 2005/11/28 12:31:28
Line 7  from AccessControl import getSecurityMan Line 7  from AccessControl import getSecurityMan
 from Products.PageTemplates.PageTemplate import PageTemplate  from Products.PageTemplates.PageTemplate import PageTemplate
 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate  from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
 from AccessControl import ClassSecurityInfo  from AccessControl import ClassSecurityInfo
   from difflib import Differ
   from pprint import pprint
   
   from Products.ZCatalog.CatalogPathAwareness import CatalogAware
   
   try:
 from Products.ImageArchive.ImageArchive import manage_AddImageZogiLib  from Products.ImageArchive.ImageArchive import manage_AddImageZogiLib
   except:
    print "no images"
   
   
 from threading import Thread  from threading import Thread
 import shutil  import shutil
 import tempfile  import tempfile
 import os.path  import os.path
   import urllib
   
 import time  import time
 try:  try:
Line 112  class versionedFileFolder(Folder,ECHO_ba Line 121  class versionedFileFolder(Folder,ECHO_ba
   
     security= ClassSecurityInfo()      security= ClassSecurityInfo()
     security.declareProtected('AUTHENTICATED_USER','addFileForm')      security.declareProtected('AUTHENTICATED_USER','addFileForm')
       filesMetaType=['versionedFile']
     if ECHO_basis:      if ECHO_basis:
         optTMP= Folder.manage_options+ECHO_basis.manage_options          optTMP= Folder.manage_options+ECHO_basis.manage_options
     else:      else:
Line 124  class versionedFileFolder(Folder,ECHO_ba Line 133  class versionedFileFolder(Folder,ECHO_ba
                 {'label':'Generate history_template.html','action':'generateHistoryHTML'},                  {'label':'Generate history_template.html','action':'generateHistoryHTML'},
                 {'label':'Import Folder','action':'importFolderForm'},                  {'label':'Import Folder','action':'importFolderForm'},
                 {'label':'Export Folder','action':'exportFolder'},                  {'label':'Export Folder','action':'exportFolder'},
                   {'label':'Position of version number','action':'changeHistoryFileNamesForm'},
                 )                  )
   
       def changeHistoryFileNamesForm(self):
           """change position of version num"""
           pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeHistoryFileNamesForm.zpt')).__of__(self)
           return pt()
       
       
       def changeHistoryFileNames(self,positionVersionNum="front",RESPONSE=None):
           """change position of version num"""
           
           
           
           versions=self.ZopeFind(self,obj_metatypes=['versionedFileObject'],search_sub=1)
           
           if not (getattr(self,'positionVersionNum','front')==positionVersionNum):
   
               for version in versions:
                                   
                   if positionVersionNum=="front":
           
                       titleTmp=os.path.splitext(version[1].title)
                       titleTmp2="_".join(titleTmp[0].split("_")[0:-1])
                       if len(titleTmp)>1:
                           id=titleTmp[0].split("_")[-1]+"_"+titleTmp2+"."+titleTmp[1]
                       else:
                           id=titleTmp[0].split("_")[-1]+"_"+titleTmp2
   
                   else:
                       titleTmp="_".join(version[1].getId().split("_")[1:])
                       tmp=os.path.splitext(titleTmp)
                       if len(tmp)>1:
                           id=tmp[0]+"_"+version[1].getId().split("_")[0]+tmp[1]
                       else:
                           id=tmp[0]+"_"+version[1].getId().split("_")[0]
                   
                   
                   
                   version[1].aq_parent.manage_renameObjects(ids=[version[1].getId()],new_ids=[id])
                   version[1].title=id
                   
                   
           self.positionVersionNum=positionVersionNum        
           if RESPONSE:
               RESPONSE.redirect("manage_main")
           
           
           
     def importFolderForm(self):      def importFolderForm(self):
         """form fuer folder import"""          """form fuer folder import"""
         pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','importFolderForm.zpt')).__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','importFolderForm.zpt')).__of__(self)
Line 328  class versionedFileFolder(Folder,ECHO_ba Line 384  class versionedFileFolder(Folder,ECHO_ba
                           
             return cmp(x[1].getLastVersion().lastEditor().lower(),y[1].getLastVersion().lastEditor().lower())              return cmp(x[1].getLastVersion().lastEditor().lower(),y[1].getLastVersion().lastEditor().lower())
                   
     versionedFiles=self.ZopeFind(self,obj_metatypes=['versionedFile'])          versionedFiles=self.ZopeFind(self,obj_metatypes=self.filesMetaType)
           
   
         if sortField=='title':          if sortField=='title':
             versionedFiles.sort(sortName)              versionedFiles.sort(sortName)
Line 350  class versionedFileFolder(Folder,ECHO_ba Line 407  class versionedFileFolder(Folder,ECHO_ba
         else:          else:
             return ""              return ""
                   
   
       security.declareProtected('View','index_html')
     def index_html(self):      def index_html(self):
         """main"""          """main"""
         ext=self.ZopeFind(self,obj_ids=["index.html"])          ext=self.ZopeFind(self,obj_ids=["index.html"])
Line 451  def manage_addVersionedFileFolder(self, Line 510  def manage_addVersionedFileFolder(self,
   
 class versionedFileObject(File):  class versionedFileObject(File):
     """File Object im Folder"""      """File Object im Folder"""
           security= ClassSecurityInfo()
     meta_type = "versionedFileObject"      meta_type = "versionedFileObject"
           
     manage_editForm  =DTMLFile('dtml/fileEdit',globals(),      manage_editForm  =DTMLFile('dtml/fileEdit',globals(),
Line 459  class versionedFileObject(File): Line 518  class versionedFileObject(File):
     manage_editForm._setName('manage_editForm')      manage_editForm._setName('manage_editForm')
   
   
       security.declarePublic('getVComment')
   
     def getVComment(self):      def getVComment(self):
         """get the comment of this file"""          """get the comment of this file"""
         if not hasattr(self,'vComment') or (not self.vComment) or (self.vComment.lstrip()==""):          if not hasattr(self,'vComment') or (not self.vComment) or (self.vComment.lstrip()==""):
Line 494  class versionedFileObject(File): Line 555  class versionedFileObject(File):
         return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url()+"/history")          return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url()+"/history")
           
   
       security.declarePublic('getVersionComment')
       def getVersionComment(self):
           """getversioncomment"""
           return self.versionComment
       
       security.declarePublic('getTime')
   
     def getTime(self):      def getTime(self):
         """getTime"""          """getTime"""
         #return self.bobobase_modification_time().ISO()          #return self.bobobase_modification_time().ISO()
Line 509  class versionedFileObject(File): Line 577  class versionedFileObject(File):
   
           
   
     def download(self):      def download(self,REQUEST=None,RESPONSE=None):
         """download and lock"""          """download and lock"""
                   
         self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getId())          self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getId())
     self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream")      self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream")
       #try:
       #   txt=self.index_html()
       #except:
       #   txt=self.index_html(REQUEST,RESPONSE)
       #
       #self.REQUEST.RESPONSE.setHeader("Content-Length","str(len(txt)+1000)")
               
         self.content_type="application/octet-stream"          self.content_type="application/octet-stream"
         #self.REQUEST.RESPONSE.redirect(self.absolute_url())          self.REQUEST.RESPONSE.redirect(self.absolute_url())
         self.REQUEST.RESPONSE.write(self.index_html())          #txt=urllib.urlopen(self.absolute_url()).read()
         #self.REQUEST.RESPONSE.write("bl")          #self.REQUEST.RESPONSE.write(txt)
         self.REQUEST.close()      
   
           #self.REQUEST.close()
           
     def downloadLocked(self):      def downloadLocked(self):
         """download and lock"""          """download and lock"""
Line 538  class versionedFileObject(File): Line 614  class versionedFileObject(File):
         """set version"""          """set version"""
         self.versionNumber=versionNumber          self.versionNumber=versionNumber
   
   
       security.declarePublic('getVersionNumber')                                              
   
     def getVersionNumber(self):      def getVersionNumber(self):
         """get version"""          """get version"""
         return self.versionNumber          return self.versionNumber
   
       security.declarePublic('getVersionComment')                                              
       def getVersionComment(self):
           """get version"""
           return self.versionComment
   
      
         
       security.declarePublic('lastEditor')                                                
                           
     def lastEditor(self):      def lastEditor(self):
         """last Editor"""          """last Editor"""
Line 599  def manage_addVersionedFileObject(self,i Line 685  def manage_addVersionedFileObject(self,i
   
   
   
 class versionedFile(Folder):  class versionedFile(CatalogAware,Folder):
     """Versioniertes File"""      """Versioniertes File"""
   
       default_catalog='fileCatalog'
       
       def PrincipiaSearchSource(self):
              """Return cataloguable key for ourselves."""
              return str(self)
          
     def __init__(self, id, title, lockedBy,author):      def __init__(self, id, title, lockedBy,author):
         """init"""          """init"""
         self.id=id          self.id=id
Line 611  class versionedFile(Folder): Line 703  class versionedFile(Folder):
   
     def manageImagesForm(self):      def manageImagesForm(self):
         """manage Images attached to the file"""          """manage Images attached to the file"""
   
           self.REQUEST.SESSION['refer']=self.REQUEST['HTTP_REFERER']
           
         pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','manageImage')).__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','manageImage')).__of__(self)
         return pt()          return pt()
   
     def manageImages(self,imageUrl=None,caption=None,RESPONSE=None):      def manageImages(self,imageUrl=None,caption=None,REQUEST=None):
         """manage URL"""          """manage URL"""
         if imageUrl and (not imageUrl==""):          if imageUrl and (not imageUrl==""):
             manage_AddImageZogiLib(self,libPath=imageUrl,caption=caption)              manage_AddImageZogiLib(self,libPath=imageUrl,caption=caption)
                           
         if RESPONSE is not None:          if self.REQUEST.SESSION.has_key('refer'):
             RESPONSE.redirect('../../')  
               return REQUEST.RESPONSE.redirect(self.REQUEST.SESSION['refer'])
           return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url())
       
   
     def changeImages(self,caption=None,submit=None,id=None,RESPONSE=None):      
       def changeImages(self,caption=None,submit=None,id=None,REQUEST=None):
         """manage URL"""          """manage URL"""
         if submit=="change caption":          if submit=="change caption":
             image=self.ZopeFind(self,obj_ids=[id])              image=self.ZopeFind(self,obj_ids=[id])
Line 633  class versionedFile(Folder): Line 732  class versionedFile(Folder):
             image=self.ZopeFind(self,obj_ids=[id])              image=self.ZopeFind(self,obj_ids=[id])
             if image:              if image:
                 self.manage_delObjects([image[0][1].getId()])                  self.manage_delObjects([image[0][1].getId()])
         if RESPONSE is not None:  
             RESPONSE.redirect('../../')  
           if self.REQUEST.SESSION.has_key('refer'):
   
               return REQUEST.RESPONSE.redirect(self.REQUEST.SESSION['refer'])
           return REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url())
       
           
   
   
     def getImages(self):      def getImages(self):
Line 680  class versionedFile(Folder): Line 785  class versionedFile(Folder):
         tmp=0          tmp=0
         lastVersion=None          lastVersion=None
                   
           
         for version in self.ZopeFind(self):          for version in self.ZopeFind(self):
                           
             if hasattr(version[1],'versionNumber'):              if hasattr(version[1],'versionNumber'):
Line 687  class versionedFile(Folder): Line 793  class versionedFile(Folder):
                 if int(version[1].versionNumber) > tmp:                  if int(version[1].versionNumber) > tmp:
                     tmp=int(version[1].versionNumber,)                      tmp=int(version[1].versionNumber,)
                     lastVersion=version[1]                      lastVersion=version[1]
               if lastVersion==None:
                   lastVersion=version[1]
                   lastVersion.versionNumber=1
         return lastVersion          return lastVersion
           
       
       def diff(self,data):
           """differenz between lastversion and data"""
           d=Differ()
           tmp=self.getLastVersion().data
           #print "XX",data,tmp
           l=list(d.compare(data.splitlines(1),tmp.splitlines(1)))
           
           plus=0
           minus=0
           for a in l:
               if a[0]=='+':
                   plus+=1
               if a[0]=='-':
                   minus+=1
           
           
           return max([plus,minus]),l
       
     def index_html(self):      def index_html(self):
         """main view"""          """main view"""
         lastVersion=self.getLastVersion()          lastVersion=self.getLastVersion()
         #return "File:"+self.title+"  Version:%i"%lastVersion.versionNumber," modified:",lastVersion.bobobase_modification_time()," size:",lastVersion.getSize(),"modified by:",lastVersion.lastEditor()          #return "File:"+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())
                                                                                security= ClassSecurityInfo()                           
       security.declarePublic('getVersion')                                              
     def getVersion(self):      def getVersion(self):
         tmp=0          tmp=0
         for version in self.ZopeFind(self):          for version in self.ZopeFind(self):
Line 705  class versionedFile(Folder): Line 834  class versionedFile(Folder):
                     tmp=int(version[1].versionNumber,)                      tmp=int(version[1].versionNumber,)
         return tmp+1          return tmp+1
   
     security= ClassSecurityInfo()  
     security.declareProtected('AUTHENTICATED_USER','unlock')      security.declareProtected('AUTHENTICATED_USER','unlock')
   
     def history(self):      def history(self):
Line 775  class versionedFile(Folder): Line 904  class versionedFile(Folder):
   
         if not newName=='':          if not newName=='':
             self.title=newName[0:]              self.title=newName[0:]
         print self.title  
                   
           
   
           
           
           positionVersionNum=getattr(self,'positionVersionNum','front')
           
           if positionVersionNum=='front':
         id="V%i"%self.getVersion()+"_"+self.title          id="V%i"%self.getVersion()+"_"+self.title
           else:
               tmp=os.path.splitext(self.title)
               if len(tmp)>1:
                   id=tmp[0]+"_V%i"%self.getVersion()+tmp[1]
               else:
                   id=tmp[0]+"_V%i"%self.getVersion()
               
                   
         manage_addVersionedFileObject(self,id,vC,author,file,"V%i"%self.getVersion()+"_"+self.title,precondition, content_type)          manage_addVersionedFileObject(self,id,vC,author,file,id,precondition, content_type)
         objs=self.ZopeFind(self,obj_ids=[id])[0][1].setVersionNumber(int(self.getVersion()))          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()
   
Line 804  class versionedFile(Folder): Line 946  class versionedFile(Folder):
         self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getLastVersion().getId())          self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.getLastVersion().getId())
     self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream")      self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream")
               
       #try:   
       #   txt=self.getLastVersion.index_html()
       #except:
       #   txt=self.getLastVersion.index_html(REQUEST,RESPONSE)
   
       #self.REQUEST.RESPONSE.setHeader("Content-Length","str(len(txt)+1000)")
           
         self.content_type="application/octet-stream"          self.content_type="application/octet-stream"
         #self.REQUEST.RESPONSE.write("bl")          #self.REQUEST.RESPONSE.write("bl")
         self.REQUEST.RESPONSE.write(self.getLastVersion().index_html())          #self.REQUEST.RESPONSE.write(txt)
         self.REQUEST.close()          #self.REQUEST.close()
   
         #self.getLastVersion().content_type="application/octet-stream"          #self.getLastVersion().content_type="application/octet-stream"
         #self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'/'+self.getId()+'/'+self.getLastVersion().getId())          self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'/'+self.getId()+'/'+self.getLastVersion().getId())
           
     def downloadLocked(self):      def downloadLocked(self):
         """download and lock"""          """download and lock"""

Removed from v.1.39  
changed lines
  Added in v.1.54


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