Diff for /ECHO_content/VLPExtension.py between versions 1.75 and 1.79

version 1.75, 2008/09/05 16:08:30 version 1.79, 2008/10/08 10:18:04
Line 16  from stat import * Line 16  from stat import *
 from types import *  from types import *
 from Globals import package_home  from Globals import package_home
 import transaction  import transaction
   import Acquisition
   
 from Products.ECHO_content.ECHO_collection import *  from Products.ECHO_content.ECHO_collection import *
 from vlp_xmlhelpers import *  from vlp_xmlhelpers import *
Line 161  def manage_addSendMailForm(self, id, toA Line 162  def manage_addSendMailForm(self, id, toA
     return ''      return ''
   
                   
   class VLP_collectionFolder(Folder):
       """klasse fŸr folder innheralb der collection"""
       meta_type="VLP_collectionFolder"
       
 class VLP_essay(Folder):  class VLP_essay(Folder):
     """classe fr VLP essays"""      """classe fr VLP essays"""
   
Line 478  def manage_addVLP_subCollection(self,id, Line 483  def manage_addVLP_subCollection(self,id,
         if RESPONSE is not None:          if RESPONSE is not None:
                 RESPONSE.redirect('manage_main')                  RESPONSE.redirect('manage_main')
   
   from zope.publisher.interfaces import IPublishTraverse
   from zope.interface import implements
   from zope.publisher.interfaces import NotFound 
   from zope.app import zapi 
   from zope.component import queryMultiAdapter
   from ZPublisher.BaseRequest import DefaultPublishTraverse
   
 class VLP_collection(ECHO_collection):  class VLP_collection(ECHO_collection,Acquisition.Explicit):
     """VLP spezifische Erweiterung der Collection"""      """VLP spezifische Erweiterung der Collection"""
   
           
       
       implements(IPublishTraverse)
       def findObjFromLitName(self,fileName):
           if not fileName[0:3]=="lit":
               logging.error("getOrCreateFolder wrong filename: %s"%fileName)
               return None
           
           
           restName="%08d"%int(fileName[3:])
           
           fs=(restName[0:2],restName[0:4],restName[0:6])
           
           current =self
           for f in fs:
               obj = getattr(current,f,None)
               if not obj: #subfolder existiert nicht
                   return None
               current=obj
               
           return getattr(current,fileName,None)
           
       def publishTraverse(self,request,name):
           """change the traversal if literature object"""
           
           actual_url=request['ACTUAL_URL']
           lastActual=actual_url.split("/")[-1]
           
      
           if name.startswith("lit"): #umleitung wenn lit aufgerufen wirk
               # umleitung auf den eigentlichen folder nur wenn direkt der Folder litXXX oder dessen index_html methode aufgerufen wird
               if lastActual.startswith("lit") or (lastActual=="index_html"):
                   #obj=self. ZopeFind(self,obj_ids=[name],search_sub=1)
                   ob=self.findObjFromLitName(name)
                   if not ob:
                       return "LIt not found"
                   else:
             
                       logging.error("request:"+repr(ob))
                       request.response.setStatus(200)
                       return ob
               else: ## andern falls transversiere zum parent.
                   obj = self.aq_parent
                   return obj
           else: # mache gar nichts falls nicht lit aufgerufen wird
    
              
               tr=DefaultPublishTraverse(self, request)
               ob= tr.publishTraverse(request, name)
          
               return ob
            #raise NotFound(self.context, name, request) 
               #return repr(request)
       
     meta_type="VLP_collection"      meta_type="VLP_collection"
     manage_options=ECHO_collection.manage_options+(      manage_options=ECHO_collection.manage_options+(
         {'label':'Change Path','action':'VLP_path_configForm'},          {'label':'Change Path','action':'VLP_path_configForm'},
Line 490  class VLP_collection(ECHO_collection): Line 554  class VLP_collection(ECHO_collection):
         {'label':'Update Metadata','action':'updateCollectionMD'},          {'label':'Update Metadata','action':'updateCollectionMD'},
         )          )
   
   
   
     def generateSubCollections(self,errorsTXT="",forceUpdate=False,RESPONSE=None):      def generateSubCollections(self,errorsTXT="",forceUpdate=False,RESPONSE=None):
         """erzeuge subcollectionen"""          """erzeuge subcollectionen"""
         logging.debug("generateSubCollections")          logging.debug("generateSubCollections")
Line 503  class VLP_collection(ECHO_collection): Line 565  class VLP_collection(ECHO_collection):
         for found in founds:          for found in founds:
             try:              try:
                 litid = str(found.reference)                  litid = str(found.reference)
                 foundCol=self.ZopeFind(self,obj_ids=[litid])                  foundCol=self.findObjFromLitName(litid)
                   #foundCol=self.ZopeFind(self,obj_ids=[litid])
                 if foundCol:                  if foundCol:
                     col = foundCol[0][1]                      col = foundCol
                     logging.debug("generateSubCollections: subcollection %s exists (%s)"%(col.getId(),found.reference))                      logging.debug("generateSubCollections: subcollection %s exists (%s)"%(repr(col),found.reference))
                     if (col.title != found.titlerefdisplay) or (col.label != found.titlerefdisplay):                      if (col.title != found.titlerefdisplay) or (col.label != found.titlerefdisplay):
                         # subcollection seems to have changed                              # subcollection seems to have changed    
                         logging.debug("generateSubCollections: subcollection has changed, recreating!")                          logging.debug("generateSubCollections: subcollection has changed, recreating!")
                         self.manage_delObjects([foundCol[0][0]])                          col.aq_parent.manage_delObjects([col.getId()])
                         manage_addVLP_subCollection(self,litid,found.titlerefdisplay,found.titlerefdisplay)                          manage_addVLP_subCollection(self.getOrCreateFolderForFile(litid),litid,found.titlerefdisplay,found.titlerefdisplay)
                 else:                  else:
                     logging.debug("generateSubCollections: creating new subcollection %s"%found.reference)                      logging.debug("generateSubCollections: creating new subcollection %s"%found.reference)
                     manage_addVLP_subCollection(self,litid,found.titlerefdisplay,found.titlerefdisplay)                      manage_addVLP_subCollection(self.getOrCreateFolderForFile(litid),litid,found.titlerefdisplay,found.titlerefdisplay)
                                   
                 #teste ob es Images auf dem Server gibt mit gleichem Namen (frontmatter)                  #teste ob es Images auf dem Server gibt mit gleichem Namen (frontmatter)
                 if os.path.exists(os.path.join(self.vlp_basis,litid)):                  if os.path.exists(os.path.join(self.vlp_basis,litid)):
                     logging.debug("generateSubCollections: found frontmatter in %s"%litid)                      logging.debug("generateSubCollections: found frontmatter in %s"%litid)
                     obj=getattr(self,litid)                      obj=self.findObjFromLitName(litid)
                     if not self.ZopeFind(obj,obj_ids=[litid]):                      if not self.ZopeFind(obj,obj_ids=[litid]):
                         metalink=self.REQUEST['URL1']+"/"+litid+"/"+litid+"/index_meta"                          metalink=self.REQUEST['URL1']+"/"+litid+"/"+litid+"/index_meta"
                         newObj=VLP_resource(litid,'',metalink,litid,litid,litid,'generated','book','','','','','','')                          newObj=VLP_resource(litid,'',metalink,litid,litid,litid,'generated','book','','','','','','')
Line 530  class VLP_collection(ECHO_collection): Line 593  class VLP_collection(ECHO_collection):
   
                 if RESPONSE is not None:                  if RESPONSE is not None:
                     self.REQUEST.RESPONSE.write("<p>%s</p>\n"%litid)                      self.REQUEST.RESPONSE.write("<p>%s</p>\n"%litid)
                   logging.debug("<p>%s</p>\n"%litid)
   
             except:              except:
                 error=sys.exc_info()[0:2]                  error=sys.exc_info()[0:2]
Line 554  class VLP_collection(ECHO_collection): Line 618  class VLP_collection(ECHO_collection):
         if RESPONSE is not None:          if RESPONSE is not None:
             RESPONSE.redirect('manage_main')              RESPONSE.redirect('manage_main')
   
       
       def getOrCreateFolderForFile(self,fileName):
           
           if not fileName[0:3]=="lit":
               logging.error("getOrCreateFolder wrong filename: %s"%fileName)
               return None
           
           
           restName="%08d"%int(fileName[3:])
           
           fs=(restName[0:2],restName[0:4],restName[0:6])
           
           current =self
           for f in fs:
               obj = getattr(current,f,None)
               if not obj:
                    newObj=VLP_collectionFolder(f)
                    current._setObject(f,newObj)
                    obj = getattr(current,f)
               current=obj
               
           return current
           
     def updateCollection(self,forceUpdate=False,RESPONSE=None):      def updateCollection(self,forceUpdate=False,RESPONSE=None):
         """liest verzeichnisse aus dem pfad und legt sie dann als objekte in den ordner"""          """liest verzeichnisse aus dem pfad und legt sie dann als objekte in den ordner"""
         errorsTXT="<h2>Errors</h2>"          errorsTXT="<h2>Errors</h2>"
Line 568  class VLP_collection(ECHO_collection): Line 655  class VLP_collection(ECHO_collection):
                 i+=1                  i+=1
             else:              else:
                 i=0                  i=0
                   j=0
                   while j<5:
                       try:
                 transaction.get().commit()                    transaction.get().commit()  
                           j=6
                       except:
                           logging.error("Commit: %s"%j)
                           j+=1
                           
                 RESPONSE.write("<p>committed</p>")                  RESPONSE.write("<p>committed</p>")
             if fileName[0:3]=="lit":              if fileName[0:3]=="lit":
                 metalink=self.REQUEST['URL1']+"/"+fileName+"/index_meta"                  metalink=self.REQUEST['URL1']+"/"+fileName+"/index_meta"
                   
                   folder=self.getOrCreateFolderForFile(fileName) #get the folder where fileName lives or should live
                   if not folder: #folder gave an error
                       continue
                 try:                  try:
                     if not hasattr(self,fileName):                      if not hasattr(folder,fileName):
                         # create new resource                          # create new resource
                         logging.debug("updateCollection: new %s"%fileName)                          logging.debug("updateCollection: new %s"%fileName)
                         if RESPONSE is not None:                          if RESPONSE is not None:
                             RESPONSE.write("<p>new: %s</p>\n"%fileName)                              RESPONSE.write("<p>new: %s</p>\n"%fileName)
                           logging.debug("new: %s \n"%fileName)
                         newObj=VLP_resource(fileName,'',metalink,fileName,fileName,fileName,'generated','book','','','','','','')                          newObj=VLP_resource(fileName,'',metalink,fileName,fileName,fileName,'generated','book','','','','','','')
                         self._setObject(fileName,newObj)                          
                           folder._setObject(fileName,newObj)
                                   
                     if RESPONSE is not None:                      if RESPONSE is not None:
                         RESPONSE.write("<p>got: %s "%fileName)                          RESPONSE.write("<p>got: %s "%fileName)
                     genObj=getattr(self,fileName)  
                       genObj=getattr(folder,fileName)
                       logging.debug("got: %s "%fileName)
   
                     logging.debug("updateCollection: inspecting %s"%fileName)                      logging.debug("updateCollection: inspecting %s"%fileName)
                     # create index                      # create index
                     if hasattr(genObj,'createIndexFile'):                      if hasattr(genObj,'createIndexFile'):

Removed from v.1.75  
changed lines
  Added in v.1.79


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