--- MPIWGWeb/Attic/MPIWGHelper.py 2009/11/06 15:37:42 1.1.2.9 +++ MPIWGWeb/Attic/MPIWGHelper.py 2010/07/23 17:30:38 1.1.2.11 @@ -1,5 +1,7 @@ -from types import * +from Products.PageTemplates.PageTemplateFile import PageTemplateFile + 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'] @@ -20,11 +22,11 @@ def getTextFromNode(nodename): 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()) + #ext=self.ZopeFind(self.aq_parent,obj_ids=[tpName]) + if hasattr(self,tpName): + pt = getattr(self,tpName) else: - pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/'+tpName)).__of__(self) + pt=PageTemplateFile('zpt/'+tpName, globals()).__of__(self) assert(pt) return pt @@ -84,27 +86,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): - """encode unicode object or string into byte string in utf-8 representation""" - if not str: +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 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='...'):