version 1.72, 2006/02/06 11:00:20
|
version 1.84, 2007/07/24 09:11:46
|
Line 18 import base64
|
Line 18 import base64
|
import bz2 |
import bz2 |
import xmlrpclib |
import xmlrpclib |
|
|
|
import logging |
|
|
|
#erstzt logging |
|
def logger(txt,method,txt2): |
|
"""logging""" |
|
logging.info(txt+ txt2) |
|
|
displayTypes = ['ZSQLExtendFolder','ZSQLBibliography','ECHO_group','ECHO_collection','ECHO_resource','ECHO_link','ECHO_sqlElement','ECHO_pageTemplate','ECHO_externalLink','ImageCollectionIFrame','VLP_resource','VLP_essay','ECHO_ZCatalogElement','ImageCollection','versionedFileFolder','ECHO_movie'] |
displayTypes = ['ZSQLExtendFolder','ZSQLBibliography','ECHO_group','ECHO_collection','ECHO_resource','ECHO_link','ECHO_sqlElement','ECHO_pageTemplate','ECHO_externalLink','ImageCollectionIFrame','VLP_resource','VLP_essay','ECHO_ZCatalogElement','ImageCollection','versionedFileFolder','ECHO_movie'] |
|
|
|
|
Line 28 def encodeRPC(string):
|
Line 35 def encodeRPC(string):
|
def decodeRPC(string): |
def decodeRPC(string): |
return bz2.decompress(base64.decodestring(string)) |
return bz2.decompress(base64.decodestring(string)) |
|
|
|
def unicodify(s): |
|
"""decode str (utf-8 or latin-1 representation) into unicode object""" |
|
if not s: |
|
return u"" |
|
if isinstance(s, str): |
|
try: |
|
return s.decode('utf-8') |
|
except: |
|
return s.decode('latin-1') |
|
else: |
|
return s |
|
|
|
def utf8ify(s): |
|
"""encode unicode object or string into byte string in utf-8 representation. |
|
assumes string objects to be utf-8""" |
|
if not s: |
|
return "" |
|
if isinstance(s, str): |
|
return s |
|
else: |
|
return s.encode('utf-8') |
|
|
|
|
def content_html(self,type): |
def content_html(self,type): |
"""template fuer content""" |
"""template fuer content""" |
#templates = self.ZopeFind(self.aq_parent,obj_ids=[type+"_template"]) |
#templates = self.ZopeFind(self.aq_parent,obj_ids=[type+"_template"]) |
Line 36 def content_html(self,type):
|
Line 66 def content_html(self,type):
|
# return templates[0][1]() |
# return templates[0][1]() |
|
|
if hasattr(self,type+"_template"): |
if hasattr(self,type+"_template"): |
|
logging.info("type: %s"%type) |
obj=getattr(self,type+"_template") |
obj=getattr(self,type+"_template") |
return obj() |
return obj() |
else: |
else: |
Line 51 class ECHO_basis:
|
Line 82 class ECHO_basis:
|
security.declarePublic('getImageTag') |
security.declarePublic('getImageTag') |
|
|
management_page_charset="utf-8" |
management_page_charset="utf-8" |
|
isVisible = True |
|
|
def manage_addECHO_locale(self,lang,title,label,text=None,content_type=None,RESPONSE=None): |
def manage_addECHO_locale(self,lang,title,label,text=None,content_type=None,RESPONSE=None): |
return ECHO_collection.manage_addECHO_locale(self,lang,title,label) |
return ECHO_collection.manage_addECHO_locale(self,lang,title,label) |
Line 137 class ECHO_basis:
|
Line 169 class ECHO_basis:
|
|
|
return content_html(self,type) |
return content_html(self,type) |
|
|
|
def getIsVisible(self): |
|
"""return if object and all parents are visible""" |
|
|
|
# if object is not visible return False |
|
if hasattr(self,'isVisible'): |
|
if not self.isVisible : return False |
|
|
|
# else if parent of object is not ECHO_root, ECHO_basis or None |
|
if not self.aq_parent.meta_type in ['ECHO_root','ECHO_basis',None] : |
|
return self.aq_parent.getIsVisible() |
|
|
|
# else return True |
|
return True |
|
|
|
def setIsVisible(self, isVisible): |
|
""" set object attribute isVisible""" |
|
self.isVisible = isVisible |
|
|
|
def getAttributeIsVisible(self): |
|
""" return object attribute isVisible""" |
|
if hasattr(self,'isVisible'): |
|
return self.isVisible |
|
return True |
|
|
def getTitle(self): |
def getTitle(self): |
"""title""" |
"""title""" |
|
if hasattr(self,'getLanguage'): |
lang=self.getLanguage() |
lang=self.getLanguage() |
|
else: |
|
lang=None |
|
|
locale=None |
locale=None |
if lang and not (lang =="de"): |
if lang and not (lang =="de"): |
locale=self.ZopeFind(self,obj_ids=["locale_"+lang]) |
locale=self.ZopeFind(self,obj_ids=["locale_"+lang]) |
Line 147 class ECHO_basis:
|
Line 207 class ECHO_basis:
|
if locale: |
if locale: |
return self.decode(locale[0][1].title) |
return self.decode(locale[0][1].title) |
else: |
else: |
|
try: |
return self.decode(self.title) |
return self.decode(self.title) |
|
except: |
|
return self.title |
|
|
def getLabel(self): |
def getLabel(self): |
"""title""" |
"""title""" |
|
if hasattr(self,'getLanguage'): |
lang=self.getLanguage() |
lang=self.getLanguage() |
|
else: |
|
lang=None |
|
|
locale=None |
locale=None |
|
|
if lang and not (lang=="de"): |
if lang and not (lang=="de"): |
locale=self.ZopeFind(self,obj_ids=["locale_"+lang]) |
locale=self.ZopeFind(self,obj_ids=["locale_"+lang]) |
|
|
Line 312 class ECHO_basis:
|
Line 379 class ECHO_basis:
|
js+="""addArea('%s', 'overview', %s, '%s', '%s');\n"""%(ob.getFullId(),ob.getCoordString(),ob.getType(),perm) |
js+="""addArea('%s', 'overview', %s, '%s', '%s');\n"""%(ob.getFullId(),ob.getCoordString(),ob.getType(),perm) |
return js |
return js |
|
|
def createMapHead(self): |
def createMapHead(self,mapColTypes=None): |
"""create javascript include and script tags for head""" |
"""create javascript include and script tags for head""" |
pt=zptFile(self, 'zpt/ECHO_content_map_frag_js') |
pt=zptFile(self, 'zpt/ECHO_content_map_frag_js') |
return pt() |
return pt(mapColTypes=mapColTypes) |
|
|
def createMapImg(self): |
def createMapImg(self): |
"""generate img-tag for map""" |
"""generate img-tag for map""" |
Line 512 def readFieldFromXML(meta_url,parent,fie
|
Line 579 def readFieldFromXML(meta_url,parent,fie
|
|
|
def urlopen(url): |
def urlopen(url): |
"""urlopen mit timeout""" |
"""urlopen mit timeout""" |
socket.setdefaulttimeout(2) |
socket.setdefaulttimeout(10) |
ret=urllib.urlopen(url) |
ret=urllib.urlopen(url) |
socket.setdefaulttimeout(5) |
socket.setdefaulttimeout(5) |
return ret |
return ret |
Line 537 def checkOnlyOneInGroup(object):
|
Line 604 def checkOnlyOneInGroup(object):
|
else: return object |
else: return object |
|
|
|
|
def getSubCols(self, sortfield=None, subColTypes=displayTypes, sortFieldMD=None,searchMD=None,searchSimple=None,generic="yes",search_sub=0): |
def getSubCols(self, sortfield=None, |
|
subColTypes=displayTypes, |
|
sortFieldMD=None, |
|
searchMD=None, |
|
searchMD_modus='search', |
|
searchSimple=None, |
|
generic="yes",search_sub=0, |
|
isVisible=True): |
|
|
def sort(x,y): |
def sort(x,y): |
return cmp(x[0],y[0]) |
return cmp(x[0],y[0]) |
Line 559 def getSubCols(self, sortfield=None, sub
|
Line 633 def getSubCols(self, sortfield=None, sub
|
|
|
if searchSimple and (not (searchSimple==""))and hasattr(self,'resourceCatalog'): |
if searchSimple and (not (searchSimple==""))and hasattr(self,'resourceCatalog'): |
searchString=" AND ".join(searchSimple.split()) |
searchString=" AND ".join(searchSimple.split()) |
ids=[x.getObject() for x in self.resourceCatalog({'getMDValueSimpleSearchField':searchString})] |
ids=[x.getObject() for x in self.resourceCatalog({'getMDValueSimpleSearchField':searchString,'getIsVisible':True})] |
else: |
else: |
for entry in displayedObjects: |
for entry in displayedObjects: |
object=entry[1] |
object=entry[1] |
Line 568 def getSubCols(self, sortfield=None, sub
|
Line 642 def getSubCols(self, sortfield=None, sub
|
flag=0 |
flag=0 |
for field in searchMD.keys(): |
for field in searchMD.keys(): |
#if object.getMDValue(field,generic=generic)==searchMD[field]: |
#if object.getMDValue(field,generic=generic)==searchMD[field]: |
if re.match(searchMD[field],object.getMDValue(field,generic=generic)): |
#if re.match(searchMD[field],object.getMDValue(field,generic=generic)): |
|
if searchMD_modus=='match': |
|
searchResult=re.match(searchMD[field],object.getMDValue(field,generic=generic)) |
|
else: |
|
searchResult=re.search(searchMD[field],object.getMDValue(field,generic=generic)) |
|
if searchResult: |
flag=1 |
flag=1 |
else: |
else: |
flag=0 |
flag=0 |
Line 855 def writeMetadata(url,metadict,project=N
|
Line 934 def writeMetadata(url,metadict,project=N
|
node.appendChild(nodetext) |
node.appendChild(nodetext) |
metanode.appendChild(node) |
metanode.appendChild(node) |
|
|
|
|
if xmlfrag: |
if xmlfrag: |
geturl="""<?xml version="1.0" encoding="UTF-8" ?> |
geturl="""<?xml version="1.0" encoding="UTF-8" ?> |
<resource type="MPIWG"> |
<resource type="MPIWG"> |
Line 872 def writeMetadata(url,metadict,project=N
|
Line 952 def writeMetadata(url,metadict,project=N
|
|
|
|
|
except: |
except: |
|
logger("ECHO writeMetadata",logging.ERROR,"XCannot open: "+url) |
return (None,"XCannot open: "+url) |
return (None,"XCannot open: "+url) |
|
|
try: |
try: |
dom=xml.dom.minidom.parseString(geturl) |
dom=xml.dom.minidom.parseString(geturl) |
except: |
except: |
|
logger("ECHO writeMetadata",logging.ERROR,"Cannot parse: "+url+"<br>"+geturl) |
return (None,"Cannot parse: "+url+"<br>"+geturl) |
return (None,"Cannot parse: "+url+"<br>"+geturl) |
|
|
|
|
Line 889 def writeMetadata(url,metadict,project=N
|
Line 971 def writeMetadata(url,metadict,project=N
|
metanode=metanodes[0] |
metanode=metanodes[0] |
|
|
for metaData in metadict.keys(): |
for metaData in metadict.keys(): |
|
if metaData: |
try: |
try: |
nodeOld=metanode.getElementsByTagName(metaData) |
nodeOld=metanode.getElementsByTagName(metaData) |
except: |
except: |
Line 907 def writeMetadata(url,metadict,project=N
|
Line 989 def writeMetadata(url,metadict,project=N
|
if nodeOld: |
if nodeOld: |
metanode.removeChild(nodeOld[0]).unlink() |
metanode.removeChild(nodeOld[0]).unlink() |
|
|
|
|
metanodeneu=dom.createElement(metaData) |
metanodeneu=dom.createElement(metaData) |
|
try: |
metanodetext=dom.createTextNode(metadict[metaData].decode('utf-8')) |
metanodetext=dom.createTextNode(metadict[metaData].decode('utf-8')) |
|
except: |
|
metanodetext=dom.createTextNode(metadict[metaData]) |
#try: |
#try: |
|
|
#metanodetext=dom.createTextNode(unicode(metadict[metaData],"utf-8")) |
#metanodetext=dom.createTextNode(unicode(metadict[metaData],"utf-8")) |
#except: |
#except: |
#metanodetext=dom.createTextNode(metadict[metaData].encode('utf-8')) |
#metanodetext=dom.createTextNode(metadict[metaData].encode('utf-8')) |
Line 940 def writeMetadata(url,metadict,project=N
|
Line 1027 def writeMetadata(url,metadict,project=N
|
updateTextToolNode('digiliburlprefix',digiliburlprefix) |
updateTextToolNode('digiliburlprefix',digiliburlprefix) |
|
|
try: |
try: |
|
|
return dom.toxml(encoding='utf-8').encode('utf-8') |
return dom.toxml(encoding='utf-8').encode('utf-8') |
except: |
except: |
|
|
|
|
return dom.toxml(encoding='utf-8') |
return dom.toxml(encoding='utf-8') |
|
|
def readMetadata(url): |
def readMetadata(url): |
Line 1097 class MapArea(SimpleItem):
|
Line 1187 class MapArea(SimpleItem):
|
parent = self.aq_parent |
parent = self.aq_parent |
text = parent.getMapText() |
text = parent.getMapText() |
if text is not None: |
if text is not None: |
return text.document_src() |
#return text.document_src() |
|
return text() |
return "" |
return "" |
|
|
def getLabel(self): |
def getLabel(self): |
Line 1152 class MapText(Folder,ZopePageTemplate):
|
Line 1243 class MapText(Folder,ZopePageTemplate):
|
self.ZBindings_edit(self._default_bindings) |
self.ZBindings_edit(self._default_bindings) |
if text is None: |
if text is None: |
text = open(self._default_content_fn).read() |
text = open(self._default_content_fn).read() |
|
if content_type is None: |
|
content_type = self.content_type |
self.pt_edit(text, content_type) |
self.pt_edit(text, content_type) |
|
|
def createLocale(self): |
def createLocale(self): |