--- MPIWGWeb/Attic/MPIWGHelper.py 2008/06/25 06:41:25 1.1.2.2 +++ MPIWGWeb/Attic/MPIWGHelper.py 2008/10/23 07:53:50 1.1.2.7 @@ -1,5 +1,5 @@ from types import * - +import logging definedFields=['WEB_title','xdata_01','xdata_02','xdata_03','xdata_04','xdata_05','xdata_06','xdata_07','xdata_08','xdata_09','xdata_10','xdata_11','xdata_12','xdata_13','WEB_project_header','WEB_project_description','WEB_related_pub'] checkFields = ['xdata_01'] @@ -18,13 +18,22 @@ 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'): self._v_stopWords=self.stopwords_en.data.split("\n") - x=str(xo[1]) - y=str(yo[1]) + x=unicodify(xo[1]) + y=unicodify(yo[1]) strx=x.split(" ") stry=y.split(" ") @@ -77,6 +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) if not str: return "" if type(str) is StringType: @@ -96,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:])