--- ECHO_content/ECHO_collection.py 2008/12/04 21:27:00 1.299 +++ ECHO_content/ECHO_collection.py 2012/01/17 18:39:07 1.310.2.4 @@ -1,4 +1,4 @@ -"""New version of the product started February, 8th. Without scientific classification, use content-type for further classification.""" +"""New version of the produc started February, 8th. Without scientific classification, use content-type for further classification.""" """Echo collection provides the classes for the ECHO content web-site. class ECHO_collection is the basis class for an ECHO collection. @@ -9,11 +9,7 @@ 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 @@ -40,20 +36,24 @@ from Globals import Persistent, package_ from Acquisition import Implicit from Products.ZCatalog.CatalogPathAwareness import CatalogAware from Products.ZCTextIndex.ZCTextIndex import manage_addLexicon -from Products.MetaDataProvider.MetaDataClient import MetaDataClient +try: + from Products.MetaDataProvider.MetaDataClient import MetaDataClient +except: + print "no metadataclient" import urllib 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 +import logging try: from psycopg import libpq @@ -103,6 +103,7 @@ def setECHO_collectionInformation(self,t self.weight=weight import ECHO_resource +from ECHO_resource import manage_addECHO_resource class ECHO_resource(ECHO_resource.ECHO_resource): """depricated use class in ECHO_resource.py""" @@ -376,7 +377,7 @@ class ECHO_fullText(ZopePageTemplate,ECH try: dom=xml.dom.minidom.parseString(self()) except: - dom=xml.dom.minidom.parseString(self().encode('latin-1')) + dom=xml.dom.minidom.parseString(self.utf8ify(self())) pages=dom.getElementsByTagName('page') return pages[int(nr)-1].toxml() @@ -697,6 +698,39 @@ class ECHO_collection(CatalogAware, Fold path="/mpiwg/online/permanent/shipbuilding" + def getSection(self, crumbs=None): + """returns the current section name""" + # use breadcrumbs if available + if crumbs is not None and len(crumbs) > 0: + 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 != 'ECHO_root' and p.meta_type!='ECHO_main' and p.meta_type!='ECHO_nav': + sec = p.getId() + p = p.aq_parent + + return sec + + def getSubSection(self, crumbs=None): + """returns the current subsection name""" + # use breadcrumbs if available + if crumbs is not None and len(crumbs) > 1: + return crumbs[1][2].getId() + + p = self + sec = None + subsec = None + # descend parents to the root (and remember the last id) + 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 = p.aq_parent + + return subsec + def exportImportObjects_html(self,RESPONSE): """ImportObject""" @@ -718,7 +752,7 @@ class ECHO_collection(CatalogAware, Fold ret=None for name in zf.namelist(): - fn=tempfile.mkstemp()[1] + ds,fn=tempfile.mkstemp() tf=file(fn,"w") x=zf.read(name) tf.write(x) @@ -729,8 +763,11 @@ class ECHO_collection(CatalogAware, Fold if not ret: ret="" ret+="Cannot import: %s (Already existing?)
"%name + os.close(ds) os.remove(fn) - + + zf.close() + if ret: return """%s"""%ret if RESPONSE: @@ -849,17 +886,24 @@ class ECHO_collection(CatalogAware, Fold if not urn: urn=self.absolute_url() - li="""\n""" + li="""\n""" for content in contents: + try: ret+=content[1].getRDF()+"\n" - - ret+="""\n"""%urn + except: + logging.error("getrdf: "+repr(content[1].getRDF())) + try: + ret+=self.unicodify(content[1].getRDF())+"\n" + except: + logging.error("--still cannot do it") + ret+=repr(content[1].getRDF())+"\n" + ret+="""\n"""%urn for content in contents: nurn=content[1].absolute_url() ret+=li%nurn - return ret+"" + return ret+"" @@ -989,7 +1033,7 @@ class ECHO_collection(CatalogAware, Fold pass return ret - def importCollection(self,path=None,RESPONSE=None): + def importCollection(self,path=None,viewerUrl=None,metaDataUrl=None,replacePathPermanent=None,replacePathExperimental=None,RESPONSE=None): """liest verzeichnisse aus dem pfad und legt sie dann als objekte in den ordner""" if path is None: @@ -1002,15 +1046,20 @@ class ECHO_collection(CatalogAware, Fold if fileName: - tempPath=re.sub("/mpiwg/online","",path) - link="http://echo.mpiwg-berlin.mpg.de/zogilib_book?fn="+tempPath+"/"+fileName+"/pageimg" + if (replacePathExperimental and replacePathExperimental!=''): + path=re.sub(replacePathExperimental,"/mpiwg/online/experimental",path) + + if (replacePathPermanent and replacePathPermanent!=''): + path=re.sub(replacePathPermanent,"/mpiwg/online/permanent",path) + + link=viewerUrl%(path+"/"+fileName+"/pageimg") - metalink=self.path+"/"+fileName+"/index.meta" + 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,'generated','book','','','','','','') + newObj=ECHO_resource(fileName,link,metalink,fileName,fileName,fileName,'','book','','','','','','') self._setObject(fileName,newObj) genObj=getattr(self,fileName) @@ -1081,38 +1130,7 @@ 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 @@ -1147,17 +1165,7 @@ 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""" @@ -1390,11 +1398,8 @@ 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'}, ) @@ -1453,8 +1458,15 @@ class ECHO_collection(CatalogAware, Fold def showOverview(self): """overview""" - if 'ECHO_overview.html' in self.__dict__.keys(): - return getattr(self,'ECHO_overview.html')() + # use ECHO_overview.html template in this instance + if 'ECHO_overview.html' in self: + return self['ECHO_overview.html']() + + # use ECHO_overview_main template in path + if hasattr(self, 'ECHO_overview_main'): + return getattr(self, 'ECHO_overview_main')() + + # use template from Product pt=zptFile(self, 'zpt/ECHO_content_overview.zpt') return pt() @@ -1463,23 +1475,35 @@ 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 - - if 'index.html' in self.__dict__.keys(): - ret=getattr(self,'index.html')() - - elif 'overview' in self.__dict__.keys(): + + # 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' ret=self.showOverview() + + # use getattr for acquisition elif hasattr(self,'collection_index_template'): - ret=self.collection_index_template() + # use 'collection_index_template' in acquisition path + 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() @@ -1508,8 +1532,8 @@ class ECHO_collection(CatalogAware, Fold def area_img(self): """area image""" - bt = BrowserCheck(self) - if bt.isIE or bt.isN4: + bt = browserType(self) + if bt['isIE'] or bt['isN4']: return sendFile(self, 'images/red.gif', 'image/gif') else: return sendFile(self, 'images/reda.png', 'image/png') @@ -1607,17 +1631,17 @@ class ECHO_group(ECHO_collection): if not urn: urn=self.absolute_url() - li="""\n""" + li="""\n""" for content in contents: - ret+=content[1].getRDF()+"\n" + ret+=self.unicodify(content[1].getRDF())+"\n" - ret+="""\n"""%urn + ret+="""\n"""%urn for content in contents: nurn=content[1].absolute_url() ret+=li%nurn - return ret+"" + return ret+"" def index_html(self): """standard page""" @@ -1801,7 +1825,8 @@ class ECHO_userFolder(UserFolder): return 1 return 0 -Globals.default__class_init__(ECHO_userFolder) +# ROC: problem with 2.12 +#Globals.default__class_init__(ECHO_userFolder) @@ -1868,12 +1893,12 @@ class ECHO_root(Folder,Persistent,Implic 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'}, -) + ) + + def getECHORootURL(self): @@ -1881,18 +1906,11 @@ class ECHO_root(Folder,Persistent,Implic def getECHORoot(self): return 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 getBrowserType(self): + """returns browserType object""" + return browserType(self) + def mod_re_sub(self,pattern,replace,string): """re.sub aus mod re zur Verfuegung stellen""" return re.sub(pattern,replace,string) @@ -2052,8 +2070,8 @@ class ECHO_root(Folder,Persistent,Implic global key global value seq="" - if name=="RDF:Seq": - key=attrs.get('RDF:about') + if name=="rdf:Seq": + key=attrs.get('rdf:about') try: # teste ob liste x=seqs[key][0] except: @@ -2061,20 +2079,20 @@ class ECHO_root(Folder,Persistent,Implic seqs[key]=[] - elif name=="RDF:Description": - key=attrs.get('RDF:about') + elif name=="rdf:Description": + key=attrs.get('rdf:about') - elif name=="RDF:li": - name=attrs.get('RDF:resource') + elif name=="rdf:li": + name=attrs.get('rdf:resource') seqs[key].append(name) - elif name=="ECHONAVIGATION:type": + elif name=="echonavigation:type": value="type" - elif name=="ECHONAVIGATION:name": + elif name=="echonavigation:name": value="name" - elif name=="ECHONAVIGATION:linkClickable": + elif name=="echonavigation:linkClickable": value="linkClickable" def end_element(name): @@ -2136,17 +2154,6 @@ 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""" @@ -2155,17 +2162,17 @@ class ECHO_root(Folder,Persistent,Implic ret=getRDFDescription(self,self.absolute_url(),urn=urn) - li="""\n""" + li="""\n""" for content in contents: ret+=content[1].getRDF()+"\n" - ret+="""\n"""%urn + ret+="""\n"""%urn for content in contents: nurn=content[1].absolute_url() ret+=li%nurn - return ret+"" + return ret+"" def showContent(self,path): @@ -2194,7 +2201,11 @@ class ECHO_root(Folder,Persistent,Implic """ret attribute if existing""" try: - return getattr(found,field)#.decode('utf-8','ignore') + + return getattr(found,field)#.decode('ascii','ignore') + + + except: logging.error("can't: decode: %s"%repr(field)) logging.error(" %s %s"%(sys.exc_info()[0],sys.exc_info()[1])) @@ -2546,7 +2557,7 @@ class ECHO_root(Folder,Persistent,Implic ret="""

Resources in ECHO

""" - resources = self.ZopeFind(self,obj_metatypes=['ECHO_resource'],search_sub=1) + resources = self.ZopeFind(self,obj_metatypes=['ECHO_resource','VLP_resource'],search_sub=1) ret+="""

Found %i resources

"""%len(resources) resources.sort(sortHTML) for resource in resources: @@ -2572,7 +2583,7 @@ class ECHO_root(Folder,Persistent,Implic """gebe all ressourcen aus""" ret=""" """ - for resource in self.ZopeFind(self,obj_metatypes=['ECHO_resource'],search_sub=1): + for resource in self.ZopeFind(self,obj_metatypes=['ECHO_resource','VLP_resource'],search_sub=1): echo_url=resource[1].absolute_url() if hasattr(resource[1],'link'): @@ -3192,7 +3203,6 @@ class ECHO_main(ECHO_root,ECHO_navigatio {'label':'Main Config','action':'ECHO_navigationConfigForm'}, {'label':'Cache','action':'ECHO_cacheManageForm'}, {'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'},