--- ECHO_content/ECHO_collection.py 2012/01/17 18:39:07 1.310.2.4 +++ 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 @@ -45,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 @@ -1033,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) @@ -1054,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" + + newindexMeta =re.sub("/mpiwg/online/","",path+"/"+fileName) - genObj=getattr(self,fileName) - #genObj.createIndexFile() - ret+="OK:"+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 @@ -1130,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 @@ -1165,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""" @@ -1398,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'}, ) @@ -1458,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() @@ -1475,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() @@ -1532,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') @@ -1892,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'}, +) @@ -1906,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) @@ -2154,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""" @@ -2239,7 +2332,7 @@ class ECHO_root(Folder,Persistent,Implic retStr+="""