--- ECHO_content/ECHO_collection.py 2012/01/18 16:57:00 1.310.2.5 +++ ECHO_content/ECHO_collection.py 2012/01/03 13:02:31 1.312 @@ -9,7 +9,11 @@ class ECHO_externalLink contains informa """ - +try: + from reportlab.pdfgen import canvas + from reportlab.lib.pagesizes import A4 +except: + print "PDF generation will not work" import urlparse import string @@ -17,6 +21,7 @@ import tempfile import zipfile import re import os,shutil +import traceback import OFS.Image from types import * from OFS.Cache import Cacheable @@ -36,7 +41,6 @@ from Globals import Persistent, package_ from Acquisition import Implicit from Products.ZCatalog.CatalogPathAwareness import CatalogAware from Products.ZCTextIndex.ZCTextIndex import manage_addLexicon -from Acquisition import aq_parent try: from Products.MetaDataProvider.MetaDataClient import MetaDataClient except: @@ -46,11 +50,11 @@ import urllib2 import cgi import smtplib import time -#from Ft.Xml.Domlette import NonvalidatingReader -#from Ft.Xml.Domlette import PrettyPrint, Print -#from Ft.Xml import EMPTY_NAMESPACE -# -#import Ft.Xml.XPath +from Ft.Xml.Domlette import NonvalidatingReader +from Ft.Xml.Domlette import PrettyPrint, Print +from Ft.Xml import EMPTY_NAMESPACE + +import Ft.Xml.XPath import cStringIO import sys @@ -694,8 +698,6 @@ class ECHO_collection(CatalogAware, Fold meta_type='ECHO_collection' default_catalog='resourceCatalog' - rootMetaTypes = ['ECHO_root', 'ECHO_main', 'ECHO_nav'] - # viewClassificationList=viewClassificationListMaster displayTypes=displayTypes @@ -708,11 +710,12 @@ class ECHO_collection(CatalogAware, Fold return crumbs[0][2].getId() p = self + sec = None # descend parents to the root (and remember the last id) - while p is not None and p.meta_type not in self.rootMetaTypes: + while p is not None and p.meta_type != 'ECHO_root' and p.meta_type!='ECHO_main' and p.meta_type!='ECHO_nav': sec = p.getId() - p = aq_parent(p.context) + p = p.aq_parent return sec @@ -726,32 +729,13 @@ class ECHO_collection(CatalogAware, Fold sec = None subsec = None # descend parents to the root (and remember the last id) - while p is not None and p.meta_type not in self.rootMetaTypes: + while p is not None and p.meta_type != 'ECHO_root' and p.meta_type!='ECHO_main' and p.meta_type!='ECHO_nav': subsec = sec sec = p.getId() - p = aq_parent(p.context) + p = p.aq_parent return subsec - def getHierCrumbs(self): - """returns a list of hierarchical breadcrumbs from self to the ECHO_root""" - # crumb for this object - crumb = {'obj': self, - 'url': self.absolute_url(), - 'label': self.getLabel()} - crumbs = [crumb] - # call the parent's method recursively - parent = aq_parent(self) - if hasattr(parent, 'getHierCrumbs'): - if self.title: - return parent.getHierCrumbs() + crumbs - else: - # if there's no title, skip this level - return parent.getHierCrumbs() - - return crumbs - - def exportImportObjects_html(self,RESPONSE): """ImportObject""" @@ -1054,18 +1038,37 @@ class ECHO_collection(CatalogAware, Fold pass return ret - def importCollection(self,path=None,viewerUrl=None,metaDataUrl=None,replacePathPermanent=None,replacePathExperimental=None,RESPONSE=None): + def importCollection(self,path=None,viewerUrl=None,metaDataUrl=None,replacePathPermanent=None,replacePathExperimental=None,folderListFile=None,RESPONSE=None): """liest verzeichnisse aus dem pfad und legt sie dann als objekte in den ordner""" - if path is None: + if (path is None) & (folderListFile is None): pt=zptFile(self, 'zpt/importCollection.zpt') return pt() - files=os.listdir(path) + + + if (path !=""): + files=os.listdir(path) + pathToFolder=path; + else: + pathToFolder=""; + files=[]; + for fileLine in folderListFile.readlines(): + for fileLine2 in fileLine.split("\r"): + logging.debug("append:"+fileLine2) + files.append(fileLine2) + ret="" for fileName in files: if fileName: + logging.debug("split:"+fileName); + if(pathToFolder==""): # pfad ist leer, da filename aud folderlistfile dann: + splitted=fileName.split("/"); + path="/".join(splitted[0:-1]); + fileName=splitted[-1].rstrip().lstrip(); + + if (replacePathExperimental and replacePathExperimental!=''): path=re.sub(replacePathExperimental,"/mpiwg/online/experimental",path) @@ -1075,20 +1078,38 @@ class ECHO_collection(CatalogAware, Fold link=viewerUrl%(path+"/"+fileName+"/pageimg") - metalink=metaDataUrl+"/"+path+"/"+fileName+"/index.meta" - try: - - #link="http://nausikaa2.mpiwg-berlin.mpg.de/cgi-bin/toc/toc.x.cgi?dir="+fileName+"&step=thumb" - - newObj=ECHO_resource(fileName,link,metalink,fileName,fileName,fileName,'','book','','','','','','') - self._setObject(fileName,newObj) + metalink=metaDataUrl+re.sub("/mpiwg/online/","",path+"/"+fileName+"/index.meta") + + #metalink=metaDataUrl+"/"+path+"/"+fileName+"/index.meta" - genObj=getattr(self,fileName) - #genObj.createIndexFile() - ret+="OK:"+fileName+"
" + newindexMeta =re.sub("/mpiwg/online/","",path+"/"+fileName) + + try: + type=self.metadata.getBibTypeFromIndexMeta(newindexMeta) + + try: + + #link="http://nausikaa2.mpiwg-berlin.mpg.de/cgi-bin/toc/toc.x.cgi?dir="+fileName+"&step=thumb" + logging.debug("create:"+fileName); + logging.debug("type:"+type); + newObj=ECHO_resource(fileName,link,metalink,fileName,fileName,fileName,'',type,'','','','','','') + self._setObject(fileName,newObj) + + genObj=getattr(self,fileName) + #genObj.createIndexFile() + ret+="OK:"+fileName+"
" + except: + exc_type, exc_value, exc_traceback = sys.exc_info(); + #logging.error("%s %s %s"%[sys.exc_info()[0],ssys.exc_info()[1],; + traceback.print_exception(exc_type, exc_value, exc_traceback, + limit=2, file=sys.stdout) + ret+="ERROR:"+fileName+"
" except: - print "ERROR" - ret+="ERROR:"+fileName+"
" + exc_type, exc_value, exc_traceback = sys.exc_info(); + #logging.error("%s %s %s"%[sys.exc_info()[0],ssys.exc_info()[1],; + traceback.print_exception(exc_type, exc_value, exc_traceback, + limit=2, file=sys.stdout) + ret+="not a file ERROR:"+fileName+"
" return ret @@ -1151,7 +1172,38 @@ class ECHO_collection(CatalogAware, Fold if RESPONSE is not None: RESPONSE.write("

Done

") - + def changeViewerTemplateSets(self,project,xslt,thumbtemplate,topbar,digiLibTemplate,digiliburlprefix,RESPONSE=None): + """change the templates""" + + resources=self.ZopeFind(self,obj_metatypes=['ECHO_resource'],search_sub=1) + + for resource in resources: + + resource[1].changeViewerTemplateSet(project,xslt,thumbtemplate,topbar,digiLibTemplate,digiliburlprefix) + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + + + def setStartpageFolderForm(self): + """Form for changing the startpage""" + + + pt=zptFile(self, 'zpt/ChangeECHO_resourceStartPageFolder.zpt') + pt.content_type="text/html" + return pt() + + def setStartpageFolder(self,startpage=None,RESPONSE=None): + """change the templates""" + + resources=self.ZopeFind(self,obj_metatypes=['ECHO_resource'],search_sub=1) + + for resource in resources: + + resource[1].setStartPage(startpage) + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') def copyTitleToInfoXMLFolder(self,RESPONSE=None): """copy title into the title field of info.xml @@ -1186,7 +1238,17 @@ class ECHO_collection(CatalogAware, Fold if RESPONSE is not None: RESPONSE.redirect('manage_main') - + def reloadMetaDataFromStorageWarning(self,RESPONSE=None): + """warning""" + pt=zptFile(self, 'zpt/reloadMetaDataFromStorageWarning.zpt') + pt.content_type="text/html" + return pt() + + def reloadMetaDataFromStorage(self,RESPONSE=None): + """copy metadata from the storage to ECHO""" + + return reloadMetaDataFromStorage(self,RESPONSE) + def getPartnerCopyright(self,name,sonst="generic"): """gibt generisches copyright eines partners aus, sonst behalte jetzige einsteillung""" @@ -1419,8 +1481,11 @@ class ECHO_collection(CatalogAware, Fold {'label':'Export/Import Objects','action':'exportImportObjects_html'}, {'label':'Graphic Coords','action':'ECHO_graphicEntry'}, {'label':'create resources from XML','action':'createRessourcesFromXMLForm'}, + {'label':'Set Startpage','action':'setStartpageFolderForm'}, {'label':'Change Viewer Templates and Image Viewer','action':'changeViewerTemplateSetsForm'}, + {'label':'Reload Metadata','action':'reloadMetaDataFromStorageWarning'}, {'label':'ImportCollection','action':'importCollection'}, + {'label':'Copy MD for indexing and search','action':'copySearchFields'}, {'label':'Change access rights', 'action':'changeAccessRightsCollectionForm'}, ) @@ -1479,15 +1544,15 @@ class ECHO_collection(CatalogAware, Fold def showOverview(self): """overview""" - # use ECHO_overview.html template in this instance - if 'ECHO_overview.html' in self: - return self['ECHO_overview.html']() + # ECHO_overview.html template for this instance + if 'ECHO_overview.html' in self.__dict__.keys(): + return getattr(self,'ECHO_overview.html')() - # use ECHO_overview_main template in path + # ECHO_overview_main template in path if hasattr(self, 'ECHO_overview_main'): return getattr(self, 'ECHO_overview_main')() - # use template from Product + # template from product pt=zptFile(self, 'zpt/ECHO_content_overview.zpt') return pt() @@ -1496,35 +1561,23 @@ class ECHO_collection(CatalogAware, Fold def index_html(self): """standard page""" if self.ZCacheable_isCachingEnabled(): + result = self.ZCacheable_get() if result is not None: # Got a cached value. return result - - # old Zope 2.9 method - #if 'index.html' in self.__dict__.keys(): - # ret=getattr(self,'index.html')() - - # use Zope 2.12 IContainer for child access - if 'index.html' in self: - # use index.html template if it exists - ret = self['index.html']() - - elif 'overview' in self: - # use red-rectangle template when there's an 'overview' + + if 'index.html' in self.__dict__.keys(): + ret=getattr(self,'index.html')() + + elif 'overview' in self.__dict__.keys(): ret=self.showOverview() - - # use getattr for acquisition elif hasattr(self,'collection_index_template'): - # use 'collection_index_template' in acquisition path - ret=self.collection_index_template() - + ret=self.collection_index_template() elif hasattr(self,'main_index_template'): - # use 'main_index_template' in acquisition path + ret=self.main_index_template.__of__(self)(self.main_template) - else: - # use template from Product pt=zptFile(self, 'zpt/ECHO_main_index_template_standard.zpt') pt.content_type="text/html" ret=pt.render() @@ -1553,8 +1606,8 @@ class ECHO_collection(CatalogAware, Fold def area_img(self): """area image""" - bt = browserType(self) - if bt['isIE'] or bt['isN4']: + bt = BrowserCheck(self) + if bt.isIE or bt.isN4: return sendFile(self, 'images/red.gif', 'image/gif') else: return sendFile(self, 'images/reda.png', 'image/png') @@ -1913,11 +1966,12 @@ class ECHO_root(Folder,Persistent,Implic getSubCols = ECHO_helpers.getSubCols manage_options=Folder.manage_options+( - {'label':'Main Config','action':'ECHO_copyright_configForm'}, + {'label':'Reload Metadata','action':'reloadMetaDataFromStorageWarning'}, {'label':'Change Weights','action':'changeWeights'}, {'label':'Generate from RDF','action':'generateFromRDFForm'}, {'label':'update Resource Catalog','action':'updateResourceCatalog'}, - ) + {'label':'Copy MD for indexing and search','action':'copySearchFields'}, +) @@ -1927,11 +1981,18 @@ class ECHO_root(Folder,Persistent,Implic def getECHORoot(self): return self - - def getBrowserType(self): - """returns browserType object""" - return browserType(self) + def copySearchFields(self,RESPONSE=None): + """copys < metadatafields to the object""" + resources=self.ZopeFind(self,obj_metatypes=['ECHO_resource'],search_sub=1) + + for resource in resources: + + resource[1].copySearchFields() + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + def mod_re_sub(self,pattern,replace,string): """re.sub aus mod re zur Verfuegung stellen""" return re.sub(pattern,replace,string) @@ -2175,6 +2236,17 @@ class ECHO_root(Folder,Persistent,Implic pt.content_type="text/html" return pt() + + def reloadMetaDataFromStorageWarning(self,RESPONSE=None): + """warning""" + pt=zptFile(self, 'zpt/reloadMetaDataFromStorageWarning.zpt') + pt.content_type="text/html" + return pt() + + def reloadMetaDataFromStorage(self,RESPONSE=None): + """reload MD from Storage""" + + return reloadMetaDataFromStorage(self,RESPONSE) def getRDF(self,urn=None): """rdf of the collection""" @@ -2260,7 +2332,7 @@ class ECHO_root(Folder,Persistent,Implic retStr+="""