--- MPIWGWeb/Attic/MPIWGHelper.py 2009/04/16 15:55:19 1.1.2.8 +++ MPIWGWeb/Attic/MPIWGHelper.py 2010/02/10 18:25:44 1.1.2.10 @@ -84,27 +84,27 @@ def sortI(x,y): return cmp(x[1],y[1]) -def unicodify(str): +def unicodify(s): """decode str (utf-8 or latin-1 representation) into unicode object""" #logging.error("unicodify: %s"%str) - if not str: - return "" - if type(str) is StringType: + if not s: + return u"" + if isinstance(s, str): try: - return str.decode('utf-8') + return s.decode('utf-8') except: - return str.decode('latin-1') + return s.decode('latin-1') else: - return str + return s -def utf8ify(str): +def utf8ify(s): """encode unicode object or string into byte string in utf-8 representation""" - if not str: + if not s: return "" - if type(str) is StringType: - return str + if isinstance(s, str): + return s else: - return str.encode('utf-8') + return s.encode('utf-8') def shortenString(s, l, ellipsis='...'): @@ -130,8 +130,12 @@ def getBreadcrumbs(self): return crumbs -def getSection(self): +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) @@ -141,8 +145,12 @@ def getSection(self): return sec -def getSubSection(self): +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