--- ECHO_content/ECHO_helpers.py 2007/07/24 09:11:46 1.84 +++ ECHO_content/ECHO_helpers.py 2008/12/17 12:05:00 1.96 @@ -17,7 +17,7 @@ import ECHO_collection import base64 import bz2 import xmlrpclib - +import sys import logging #erstzt logging @@ -25,8 +25,12 @@ 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','extVersionedFileFolder','ECHO_movie'] +def normalizeCt(str): + """normalizes content_type""" + #str= str.replace(" ","_") + return str.replace("-"," ").lower() #decode and compress for xmlrpc communication with OSAS_server @@ -66,7 +70,7 @@ def content_html(self,type): # return templates[0][1]() if hasattr(self,type+"_template"): - logging.info("type: %s"%type) + obj=getattr(self,type+"_template") return obj() else: @@ -84,6 +88,49 @@ class ECHO_basis: management_page_charset="utf-8" isVisible = True + # Managment for the PID + def setPID(self,pid): + """set the pid""" + logging.debug(self.getID()+" PID set to "+pid) + self.pid=pid + return True + + def getPID(self): + """get the pid""" + + pid =getattr(self,'pid',None) + + if pid == self.getParentPID(): + return None + else: + return pid + + + def getParentPID(self): + """get the PID of the parent""" + parent = self.aq_parent + + pidF = getattr(parent,'getPID',None) + + if pidF is None: + return None + + else: + return pidF() + + def unicodify(self, s): + """return unicode object for string (utf-8 or latin1) or unicode object s""" + return unicodify(s) + + # compatibility of old decode method + decode = unicodify + + + def utf8ify(self, s): + """return utf-8 encoded string object for string or unicode object s""" + return utf8ify(s) + + 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) @@ -170,28 +217,34 @@ class ECHO_basis: 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() + """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 + # else return True + return True def setIsVisible(self, isVisible): - """ set object attribute isVisible""" - self.isVisible = isVisible + """ set object attribute isVisible""" + self.isVisible = isVisible def getAttributeIsVisible(self): - """ return object attribute isVisible""" - if hasattr(self,'isVisible'): - return self.isVisible - return True + """ return object attribute isVisible""" + if hasattr(self,'isVisible'): + return self.isVisible + return True + + def getDescription(self): + """get content of description field""" + + + return self.unicodify(getattr(self,'description','')); def getTitle(self): """title""" @@ -405,20 +458,33 @@ class ECHO_basis: """generate map link""" bt = BrowserCheck(self) id = ob.getFullId() - link = ob.getLinkId() + url = ob.getTargetUrl() + if url == "": + # ECHOResource with empty link -> no link + href = 'href="#" onclick="return false;"' + else: + href = 'href="%s"'%ob.getLinkId() + + if target is None: + targetattr = "" + else: + targetattr = 'target="%s"'%target + if text is None: text = ob.getLabel() + if text is None: text = "link" + tiptext = ob.getTip() tag = "" if bt.isN4: # N4 needs layer for highlighting - tag += '" else: # a-element - tag = '" @@ -429,6 +495,17 @@ class ECHO_basis: bt = BrowserCheck(self) id = ob.getFullId() link = ob.getLinkId() + url = ob.getTargetUrl() + if url == "": + # ECHOResource with empty link -> no link + href = 'href="#" onclick="return false;"' + else: + href = 'href="%s"'%ob.getLinkId() + + if target is None: + targetattr = "" + else: + targetattr = 'target="%s"'%target tiptext = ob.getTip() tag = "" @@ -454,7 +531,7 @@ class ECHO_basis: if float(rot) < 0: marksrc = circlesrc - tag += ''%(link,marksrc,rot) + tag += ''%(href,marksrc,rot) elif ob.isTypeText(): # N4 - Text tag += '
'%(id,id,id,link,target) + tag = ''%(id,id,id,href,targetattr) if ob.isTypeArrow(): # DOM - Arrow rot = ob.angle @@ -614,8 +691,25 @@ def getSubCols(self, sortfield=None, isVisible=True): def sort(x,y): - return cmp(x[0],y[0]) - + try: + if type(x[0])==type(y[0]): + return cmp(x[0],y[0]) + else: + if type(x[0])==types.StringType: + tmpX=unicodify(x[0]) + tmpY=y[0] + else: + tmpY=unicodify(y[0]) + tmpX=x[0] + return cmp(tmpX,tmpY) + + except: + logging.error("Error at ECHO_helpers.sort:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") + logging.error(" : %s %s"%sys.exc_info()[0:2]) + logging.error("Error at ECHO_helpers.sort:"+repr(x)+"--"+repr(type(x[0]))) + logging.error("Error at ECHO_helpers.sort:"+repr(y)+"--"+repr(type(y[0]))) + logging.error("Error at ECHO_helpers.sort:BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB") + return 0 def sortfnc(sortfield,x,y): try: xa=x[1].getMDValue(sortfield,generic=generic) @@ -1198,6 +1292,21 @@ class MapArea(SimpleItem): return self.aq_parent.label or self.aq_parent.id return self.label + def getTargetUrl(self): + """returns the URL of the linked object""" + if hasattr(self, 'aq_parent'): + p = self.aq_parent + # ECHOResource and ECHOLink have 'link' attribute + if hasattr(p, 'link'): + if p.link is None: + # return empty string for empty link + return "" + else: + return p.link + + # return None for unknown type + return None + def setLabel(self, label): """sets the label""" self.label = label