--- MPIWGWeb/Attic/MPIWGHelper.py 2008/08/27 21:08:40 1.1.2.5 +++ MPIWGWeb/Attic/MPIWGHelper.py 2008/10/23 07:53:50 1.1.2.7 @@ -18,6 +18,15 @@ def getTextFromNode(nodename): rc = rc + node.data return rc +def getTemplate(self, tpName): + """get a template file either form the instance or from the product""" + ext=self.ZopeFind(self.aq_parent,obj_ids=[tpName]) + if ext: + pt = getattr(self,ext[0][1].getId()) + else: + pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/'+tpName)).__of__(self) + assert(pt) + return pt def sortStopWordsF(self,xo,yo): if not hasattr(self,'_v_stopWords'): @@ -77,7 +86,7 @@ def sortI(x,y): def unicodify(str): """decode str (utf-8 or latin-1 representation) into unicode object""" - logging.error("unicodify: %s"%str) + #logging.error("unicodify: %s"%str) if not str: return "" if type(str) is StringType: @@ -97,3 +106,8 @@ def utf8ify(str): else: return str.encode('utf-8') + +def shortenString(s, l, ellipsis='...'): + """returns a string of length l (or l-1) by omitting characters in the middle of s, replacing with ellipsis.""" + l1 = int((l - len(ellipsis)) / 2) + return "%s%s%s"%(s[:l1],ellipsis,s[-l1:])