--- ECHO_content/VLPExtension.py 2008/09/08 18:41:34 1.77 +++ ECHO_content/VLPExtension.py 2008/11/13 14:35:53 1.81 @@ -16,6 +16,7 @@ from stat import * from types import * from Globals import package_home import transaction +import Acquisition from Products.ECHO_content.ECHO_collection import * from vlp_xmlhelpers import * @@ -161,6 +162,10 @@ def manage_addSendMailForm(self, id, toA return '' +class VLP_collectionFolder(Folder): + """klasse fŸr folder innheralb der collection""" + meta_type="VLP_collectionFolder" + class VLP_essay(Folder): """classe fr VLP essays""" @@ -478,10 +483,72 @@ def manage_addVLP_subCollection(self,id, if RESPONSE is not None: 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""" + + + 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") or (lastActual=="index_meta"): + #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) + #if (lastActual=="index_meta"): + # logging.debug("index_meta requested") + # return ob.index_meta + 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" manage_options=ECHO_collection.manage_options+( @@ -490,8 +557,6 @@ class VLP_collection(ECHO_collection): {'label':'Update Metadata','action':'updateCollectionMD'}, ) - - def generateSubCollections(self,errorsTXT="",forceUpdate=False,RESPONSE=None): """erzeuge subcollectionen""" logging.debug("generateSubCollections") @@ -503,23 +568,24 @@ class VLP_collection(ECHO_collection): for found in founds: try: litid = str(found.reference) - foundCol=self.ZopeFind(self,obj_ids=[litid]) + foundCol=self.findObjFromLitName(litid) + #foundCol=self.ZopeFind(self,obj_ids=[litid]) if foundCol: - col = foundCol[0][1] - logging.debug("generateSubCollections: subcollection %s exists (%s)"%(col.getId(),found.reference)) + col = foundCol + logging.debug("generateSubCollections: subcollection %s exists (%s)"%(repr(col),found.reference)) if (col.title != found.titlerefdisplay) or (col.label != found.titlerefdisplay): # subcollection seems to have changed logging.debug("generateSubCollections: subcollection has changed, recreating!") - self.manage_delObjects([foundCol[0][0]]) - manage_addVLP_subCollection(self,litid,found.titlerefdisplay,found.titlerefdisplay) + col.aq_parent.manage_delObjects([col.getId()]) + manage_addVLP_subCollection(self.getOrCreateFolderForFile(litid),litid,found.titlerefdisplay,found.titlerefdisplay) else: 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) if os.path.exists(os.path.join(self.vlp_basis,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]): metalink=self.REQUEST['URL1']+"/"+litid+"/"+litid+"/index_meta" newObj=VLP_resource(litid,'',metalink,litid,litid,litid,'generated','book','','','','','','') @@ -530,7 +596,7 @@ class VLP_collection(ECHO_collection): if RESPONSE is not None: self.REQUEST.RESPONSE.write("

%s

\n"%litid) - logging.debug("

%s

\n"%litid) + logging.debug("

%s

\n"%litid) except: error=sys.exc_info()[0:2] @@ -555,6 +621,29 @@ class VLP_collection(ECHO_collection): if RESPONSE is not None: 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): """liest verzeichnisse aus dem pfad und legt sie dann als objekte in den ordner""" errorsTXT="

Errors

" @@ -581,21 +670,27 @@ class VLP_collection(ECHO_collection): RESPONSE.write("

committed

") if fileName[0:3]=="lit": 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: - if not hasattr(self,fileName): + if not hasattr(folder,fileName): # create new resource logging.debug("updateCollection: new %s"%fileName) if RESPONSE is not None: RESPONSE.write("

new: %s

\n"%fileName) logging.debug("new: %s \n"%fileName) newObj=VLP_resource(fileName,'',metalink,fileName,fileName,fileName,'generated','book','','','','','','') - self._setObject(fileName,newObj) + + folder._setObject(fileName,newObj) if RESPONSE is not None: RESPONSE.write("

got: %s "%fileName) - - logging.debug("got: %s "%fileName) - genObj=getattr(self,fileName) + + genObj=getattr(folder,fileName) + logging.debug("got: %s "%fileName) + logging.debug("updateCollection: inspecting %s"%fileName) # create index if hasattr(genObj,'createIndexFile'): @@ -863,21 +958,31 @@ class VLP_resource(ECHO_resource,Cacheab RESPONSE.redirect('manage_main') - def index_meta(self): + def index_meta(self,RESPONSE=None): """index_meta""" - + pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','index_meta.zpt')).__of__(self) - pt.content_type="text/html" - return pt() - + pt.content_type="text/xml" + x= pt.pt_render() + #logging.debug("index_meta 4:"+x) + if RESPONSE: + RESPONSE.setHeader("Content-Type","text/xml") + return x def file2page(self,p): """converts filename to pagenumber""" - dom=xml.dom.minidom.parse(ECHO_helpers.urlopen(getattr(self,'index.xml').absolute_url())) + + #dom=xml.dom.minidom.parse(ECHO_helpers.urlopen(getattr(self,'index.xml').absolute_url())) + index=getattr(self,'index.xml') + + txt=index.pt_render() + dom=xml.dom.minidom.parseString(txt) for page in dom.getElementsByTagName('page'): # pageummer mit lo oder hi sind aequivalent if (page.getAttribute('file')==p) or ("%slo"%page.getAttribute('file')==p) or ("%shi"%page.getAttribute('file')==p): - return page.getAttribute('nr') + nr=page.getAttribute('nr') + + return nr return 0