![]() ![]() | ![]() |
fixed problems with project editing preview
1: from Products.PageTemplates.PageTemplateFile import PageTemplateFile 2: 3: import logging 4: 5: 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'] 6: 7: checkFields = ['xdata_01'] 8: 9: #ersetzt logging 10: def logger(txt,method,txt2): 11: """logging""" 12: logging.info(txt+ txt2) 13: 14: def getTextFromNode(nodename): 15: 16: nodelist=nodename.childNodes 17: rc = "" 18: for node in nodelist: 19: if node.nodeType == node.TEXT_NODE: 20: rc = rc + node.data 21: return rc 22: 23: def getTemplate(self, tpName): 24: """get a template file either form the instance or from the product""" 25: #ext=self.ZopeFind(self.aq_parent,obj_ids=[tpName]) 26: if hasattr(self,tpName): 27: pt = getattr(self,tpName) 28: else: 29: pt=PageTemplateFile('zpt/'+tpName, globals()).__of__(self) 30: assert(pt) 31: return pt 32: 33: def sortStopWordsF(self,xo,yo): 34: if not hasattr(self,'_v_stopWords'): 35: self._v_stopWords=self.stopwords_en.data.split("\n") 36: 37: x=unicodify(xo[1]) 38: y=unicodify(yo[1]) 39: 40: strx=x.split(" ") 41: stry=y.split(" ") 42: 43: for tmp in strx: 44: if tmp.lower() in self._v_stopWords: 45: del strx[strx.index(tmp)] 46: 47: for tmp in stry: 48: if tmp.lower() in self._v_stopWords: 49: del stry[stry.index(tmp)] 50: 51: return cmp(" ".join(strx)," ".join(stry)) 52: 53: def sortStopWords(self): 54: return lambda x,y : sortStopWordsF(self,x,y) 55: 56: def sortF(x,y): 57: try: 58: return cmp(x[1],y[1]) 59: except: 60: try: 61: return cmp(str(x[1]),str(y[1])) 62: except: 63: 64: return 0 65: 66: def sortI(x,y): 67: xsplit=x[1].split(".") 68: ysplit=y[1].split(".") 69: xret="" 70: yret="" 71: try: 72: for i in range(5): 73: try: 74: yret=yret+"%04i"%int(xsplit[i]) 75: except: 76: yret=yret+"%04i"%0 77: 78: try: 79: xret=xret+"%04i"%int(ysplit[i]) 80: except: 81: xret=xret+"%04i"%0 82: 83: 84: return cmp(int(yret),int(xret)) 85: except: 86: return cmp(x[1],y[1]) 87: 88: 89: def unicodify(s): 90: """decode str (utf-8 or latin-1 representation) into unicode object""" 91: if not s: 92: return u"" 93: if isinstance(s, str): 94: try: 95: return s.decode('utf-8') 96: except: 97: return s.decode('latin-1') 98: else: 99: return s 100: 101: def utf8ify(s): 102: """encode unicode object or string into byte string in utf-8 representation. 103: assumes string objects to be utf-8""" 104: if not s: 105: return "" 106: if isinstance(s, str): 107: return s 108: else: 109: return s.encode('utf-8') 110: 111: 112: def shortenString(s, l, ellipsis='...'): 113: """returns a string of length l (or l-1) by omitting characters in the middle of s, replacing with ellipsis.""" 114: l1 = int((l - len(ellipsis)) / 2) 115: return "%s%s%s"%(s[:l1],ellipsis,s[-l1:]) 116: 117: 118: # 119: # navigation methods (should better be a mixin class) 120: # 121: def getBreadcrumbs(self): 122: """return list of breadcrumbs from here to the root""" 123: crumbs = [(self.title, self.absolute_url(), self)] 124: parent = self.aq_parent 125: if hasattr(parent, 'getBreadcrumbs'): 126: if self.title: 127: return parent.getBreadcrumbs() + crumbs 128: else: 129: # if there's no title, skip this level 130: return parent.getBreadcrumbs() 131: 132: return crumbs 133: 134: 135: def getSection(self, crumbs=None): 136: """returns the current section name""" 137: # use breadcrumbs if available 138: if crumbs is not None and len(crumbs) > 0: 139: return crumbs[0][2].getId() 140: 141: p = self 142: sec = None 143: # descend parents to the root (and remember the last id) 144: while p is not None and p.meta_type != 'MPIWGRoot': 145: sec = p.getId() 146: p = p.aq_parent 147: 148: return sec 149: 150: def getSubSection(self, crumbs=None): 151: """returns the current subsection name""" 152: # use breadcrumbs if available 153: if crumbs is not None and len(crumbs) > 1: 154: return crumbs[1][2].getId() 155: 156: p = self 157: sec = None 158: subsec = None 159: # descend parents to the root (and remember the last id) 160: while p is not None and p.meta_type != 'MPIWGRoot': 161: subsec = sec 162: sec = p.getId() 163: p = p.aq_parent 164: 165: return subsec 166: