65
|
1
|
|
2 def sortWeight(x,y):
|
|
3 x1=int(getattr(x[1],'weight','0'))
|
|
4 y1=int(getattr(y[1],'weight','0'))
|
|
5 return cmp(x1,y1)
|
|
6
|
|
7
|
|
8
|
50
|
9 class MPIWGRoot_deleted:
|
|
10
|
|
11
|
33
|
12 def removeStopWords(self,xo):
|
1
|
13 """remove stop words from xo"""
|
|
14 if not hasattr(self,'_v_stopWords'):
|
|
15 self._v_stopWords=self.stopwords_en.data.split("\n")
|
|
16
|
|
17 x=str(xo)
|
|
18
|
|
19 strx=x.split(" ")
|
|
20
|
|
21 for tmp in strx:
|
|
22
|
|
23 if tmp.lower() in self._v_stopWords:
|
|
24 del strx[strx.index(tmp)]
|
|
25
|
|
26 return " ".join(strx)
|
|
27
|
|
28
|
|
29 def getGetNeighbourhood(self,obj, wordStr, length=100,tagging=True):
|
|
30 """finde umgebung um die worte in wordStr, zurueckgegeben wird eine Array mit den Umgebungen von Fundstellen der Worte
|
|
31 alle Tags werden entfernt, die Fundstellen werden mit <span class="found">XX</span> getaggt, die Umgebungen werden
|
|
32 case insensitive gesucht
|
|
33 @param wordStr: string mit Worten getrennt durch Leerzeichen, Phrasen sind mit " gekennzeichnet
|
|
34 "eine phrase", "*" bezeichnet wildcards und wird ignoriert"
|
|
35 @param length: optional, default wert 100, 2*length ist die groesse der Umgebung
|
|
36 @param tagging: optional default wert true, kein span tag wird erzweugt falls tag=false
|
|
37 """
|
|
38
|
|
39 ret=[] # nimmt das Array auf, dass spaeter zurueckgegeben wird
|
|
40 ranges=[] #Array mit tupeln x,y wobei x die Position des Anfang und y des Endes der i-ten Umgebung angiebt
|
|
41
|
|
42 wordStr=wordStr.lstrip().rstrip()
|
|
43
|
|
44 def isInRanges(nr,length):
|
|
45 """test ob eine gegeben Position nr schon irgendwo in einer Umgebung ist, gibt den Index des ersten Wertes aus ranges zurueck,
|
|
46 -1, wenn kein Treffer
|
|
47
|
|
48 @param nr: Position die geprueft werden soll
|
|
49 @param length: Laenge des Wortes das geprueft werden soll
|
|
50 """
|
|
51 for x in ranges:
|
|
52 if (x[0]<=nr) and (nr < (x[1]-length)):
|
|
53 return ranges.index(x)
|
|
54 return -1
|
|
55
|
|
56 # deal with phrases, in Phrasen werden die Leerzeichen durch "_" ersetzt.
|
|
57 def rep_empty(str):
|
|
58 x= re.sub(" ","_",str.group(0))
|
|
59 return re.sub("\"","",x)
|
|
60
|
|
61 wordStr=re.sub("\".*?\"", rep_empty,wordStr)#ersetze leerzeichen in " " durch "_" und loesche "
|
|
62
|
|
63 #deal with wildcards, for our purposes it is enough to delete the wildcard
|
|
64 wordStr=wordStr.replace("*","")
|
|
65
|
|
66 words=wordStr.split(" ")
|
|
67 #if not words is ListType:
|
|
68 # words=[words]
|
|
69
|
|
70
|
|
71 txtCache = self.en.getHarvestCache();
|
|
72 txt= txtCache.get(obj.absolute_url(),None)
|
|
73
|
|
74 if txt==None:
|
|
75
|
|
76 logging.debug("NO CACHE for: "+obj.absolute_url())
|
|
77 txt=obj.harvest_page(mode="slim")
|
|
78
|
|
79
|
|
80 if not txt:
|
|
81 return ret
|
|
82
|
|
83 soup = BeautifulSoup(txt)
|
|
84
|
|
85 comments = soup.findAll(text=lambda text:isinstance(text, Comment))
|
|
86 [comment.extract() for comment in comments]
|
|
87
|
|
88 txt = ''.join(soup.findAll(text=True))
|
|
89
|
|
90
|
|
91 #txt=re.sub("<.*?>", "", txt) # loesche alle Tags
|
|
92 for word in words:
|
|
93 word=re.sub("_"," ",word) # ersetze zurueck "_" durch " "
|
|
94 pos=0
|
|
95
|
|
96 n=txt.lower().count(word.lower()) # wie oft tritt das Wort auf
|
|
97
|
|
98 for i in range(n):
|
|
99 pos=txt.lower().find(word.lower(),pos)
|
|
100
|
|
101 if pos > 0:
|
|
102 x=max(0,pos-length)
|
|
103 y=min(len(txt),pos+length)
|
|
104
|
|
105
|
|
106 #is word already in one of the results
|
|
107 nr=isInRanges(pos,len(word))
|
|
108 if nr >=0:# word ist in einer schon gefunden Umgebung, dann vergroessere diese
|
|
109 x=min(ranges[nr][0],x)
|
|
110 y=max(ranges[nr][1],y)
|
|
111
|
|
112 str=txt[x:y]
|
|
113 if x!=0: #add dots if in the middle of text
|
|
114 str="..."+str
|
|
115
|
|
116 if y!=len(txt): #add dots if in the middle of text
|
|
117 str=str+"..."
|
|
118
|
|
119
|
|
120
|
|
121 if nr >=0: # word ist in einer schon gefunden Umgebung
|
|
122 ranges[nr]=(x,y) # neue Position der Umgebung
|
|
123
|
|
124 ret[nr]=str # neue Umgebung
|
|
125 else: # andernfalls neue Umgebung hinzufuegen
|
|
126 ranges.append((x,y))
|
|
127
|
|
128 ret.append(str)
|
|
129
|
|
130 pos=pos+len(word)
|
|
131 else:
|
|
132 break;
|
|
133
|
|
134 # now highlight everything
|
|
135 if tagging:
|
|
136 for x in range(len(ret)):
|
|
137 for word in words:
|
|
138 repl=re.compile(word,re.IGNORECASE)
|
|
139 ret[x]=repl.sub(""" <span class="found">%s</span>"""%word.upper(),ret[x])
|
|
140
|
|
141 return ret
|
|
142 def copyAllImagesToMargin(self):
|
|
143 """tranformiere alle Bilder in die Margins"""
|
|
144 projects=self.getTree()
|
|
145 ret=""
|
|
146 for project in projects:
|
|
147 proj=project[3]
|
|
148 try:
|
|
149 persons=proj.copyImageToMargin();
|
|
150 except:
|
|
151 logging.error("Cannnot do: %s"%repr(project))
|
|
152
|
|
153 def transformProjectsToId(self):
|
|
154 """trnasformiere zu ID, Hilfsfunktion die die alten Templates analysiert und mit der neuen Liste
|
|
155 verantwortlicher Personen versieht"""
|
|
156 projects=self.getTree()
|
|
157 ret=""
|
|
158 for project in projects:
|
|
159
|
|
160 proj=project[3]
|
|
161 persons=proj.identifyNames(proj.getContent('xdata_01'))
|
|
162 if not hasattr(proj,'responsibleScientistsList'):
|
|
163 proj.responsibleScientistsList=[]
|
|
164
|
|
165 for person in persons.items():
|
|
166
|
|
167 if len(person[1]) >1: #nicht eindeutig
|
|
168 ret+="nicht eindeutig --- %s: %s\n"%(proj.getId(),person[0])
|
|
169
|
|
170 elif len(person[1]) ==0: #kein eintrage
|
|
171 ret+="kein eintrag--- %s: %s\n"%(proj.getId(),person[0])
|
|
172 proj.responsibleScientistsList.append((person[0],""))
|
|
173 else:
|
|
174 proj.responsibleScientistsList.append((person[0],person[1][0].getObject().getKey()))
|
|
175
|
|
176 return ret
|
|
177
|
|
178
|
|
179 def harvestProjects(self):
|
|
180 """harvest"""
|
|
181 folder="/tmp"
|
|
182 try:
|
|
183 os.mkdir("/tmp/harvest_MPIWG")
|
|
184 except:
|
|
185 pass
|
|
186 founds=self.ZopeFind(self.aq_parent.projects,obj_metatypes=['MPIWGProject'],search_sub=1)
|
|
187 for found in founds:
|
|
188 txt=found[1].harvest_page()
|
|
189
|
|
190 if txt and (txt != ""):
|
|
191 name=found[0].replace("/","_")
|
|
192 fh=file("/tmp/harvest_MPIWG/"+name,"w")
|
|
193 fh.write(txt)
|
|
194 fh.close()
|
33
|
195
|
|
196
|
|
197
|
|
198 def generateNameIndex(self):
|
|
199 """erzeuge einen index verwendeter personen"""
|
|
200 import psycopg
|
|
201 o = psycopg.connect('dbname=authorities user=dwinter password=3333',serialize=0)
|
|
202 results={}
|
|
203 print self.fulltext.historicalNames.items()
|
|
204 for nameItem in self.fulltext.historicalNames.items(): #gehe durch alle namen des lexikons
|
|
205
|
|
206 c = o.cursor()
|
|
207 name=nameItem[0]
|
|
208 print "check",name
|
|
209 c.execute("select lastname,firstname from persons where lower(lastname) = '%s'"%quote(name))
|
|
210 tmpres=c.fetchall()
|
|
211 firstnames=[result[1] for result in tmpres] # find all firstnames
|
|
212 if tmpres:
|
|
213 lastname=tmpres[0][0]
|
|
214
|
|
215 for found in self.fulltext({'names':name}):
|
|
216 if found.getObject().isActual():
|
|
217 for nh in found.getObject().getGetNeighbourhood(name, length=50,tagging=False): #hole umgebung
|
|
218 #schaue nun ob der vorname hinter oder vor dem name ist
|
|
219 position=nh.find(lastname)
|
|
220 # vorher
|
|
221 #print "NH",nh
|
|
222 bevorS=nh[0:position].split()
|
|
223 #print "BV",bevorS
|
|
224 if len(bevorS)>1:
|
|
225 try:
|
|
226 bevor=[bevorS[-1],bevorS[-2]]
|
|
227 except:
|
|
228 bevor=[bevorS[0]]
|
|
229 else:
|
|
230 bevor=[]
|
|
231 #nachher
|
|
232 behindS= re.split("[,|;| ]",nh[position:])
|
|
233 #print "BH",behindS
|
|
234 if len(behindS)>2:
|
|
235 try:
|
|
236 behind=behindS[1:3]
|
|
237 except:
|
|
238 behind=[bevorS[1]]
|
|
239 else:
|
|
240 behind=[]
|
|
241 for firstname in firstnames:
|
|
242 if firstname in bevor+behind: #Namen wie mit Adelspraedikaten werden so erstmal nich gefunden
|
|
243 id="%s,%s"%(lastname,firstname)
|
|
244 if not results.has_key(id):
|
|
245 results[id]=[]
|
|
246 objId=found.getObject().getId()
|
|
247 if not (objId in results[id]):
|
|
248 print "d %s for %s"%(id,objId)
|
|
249 results[id].append(objId)
|
|
250 self.nameIndex=results
|
|
251 return results
|
|
252
|
|
253 def editNameIndexHTML(self):
|
|
254 """edit the name index"""
|
|
255 if not hasattr(self,'nameIndexEdited'): # falls editierter index noch nicht existiert, kopiere automatisch erstellten
|
|
256 self.nameIndexEdited=copy.copy(self.nameIndex)
|
|
257 print "huh"
|
|
258 #self.nameIndexEdited=copy.copy(self.nameIndex)
|
|
259 #print self.nameIndexEdited
|
|
260 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editHistoricalNames.zpt')).__of__(self)
|
|
261 return pt()
|
|
262
|
|
263 def getNamesInProject(self,projectId):
|
|
264 """get all names ofnameIndexEdited which are references in projec with projectId"""
|
|
265
|
|
266 ret=[]
|
|
267 for name in self.nameIndexEdited.keys():
|
|
268 if projectId in self.nameIndexEdited[name]:
|
|
269 ret.append(name)
|
|
270
|
|
271 return ret
|
|
272
|
|
273 def editNameIndex(self,RESPONSE=None,name=None,occurrances=None,submit=None):
|
|
274 """edit the index"""
|
|
275 nI=self.nameIndexEdited # mI introduced to make sure that changes to nameIndexEdited are know to ZODB
|
|
276 if submit=="delete":
|
|
277
|
|
278
|
|
279 dh=getattr(self,'deletedHistoricalNames',{})
|
|
280
|
|
281 if type(dh) is ListType:
|
|
282 dh={}
|
|
283 if not dh.has_key(name):
|
|
284 dh[name]=occurrances.split("\n")
|
|
285 else:
|
|
286 dh[name]+=occurrances.split("\n")
|
|
287
|
|
288 self.deletedHistoricalNames=dh
|
|
289
|
|
290 del self.nameIndexEdited[name]
|
|
291
|
|
292
|
|
293 elif (submit=="change"):
|
|
294
|
|
295 nI[name]=occurrances.split("\n")[0:]
|
|
296
|
|
297 elif (submit=="add"):
|
|
298 if not nI.has_key(name):
|
|
299 nI[name]=occurrances.split("\n")
|
|
300 else:
|
|
301 nI[name]+=occurrances.split("\n")
|
|
302
|
|
303 self.nameIndexEdited=nI
|
|
304
|
|
305
|
|
306 if RESPONSE is not None:
|
|
307 RESPONSE.redirect('editNameIndexHTML')
|
|
308
|
|
309
|
|
310
|
|
311 def restoreIndex(self):
|
|
312 """restore"""
|
|
313 self.nameIndexEdited=self.nameIndex
|
|
314 return "done"
|
50
|
315
|
|
316 def getProjectsOfMembers(self,date=None):
|
|
317 """give tuple member /projects"""
|
|
318 ret=[]
|
|
319 members=self.getAllMembers()
|
|
320 logging.debug("X %s"%repr(members))
|
|
321 #return str(members)
|
|
322 for x in members:
|
|
323 #logging.debug("X %s"%repr(x))
|
|
324 projects=self.getProjectsOfMember(key=x[1],date=date)
|
|
325 if len(projects)>0:
|
|
326 ret.append((x[0],projects))
|
|
327
|
|
328 return ret
|
|
329
|
|
330 def getProjectsOfMember(self,key=None,date=None,onlyArchived=1,onlyActive=1):
|
|
331 """get projects of a member
|
33
|
332
|
50
|
333 @param key: (optional) Key zur Idenfikation des Benutzer
|
|
334 @param date: (optional) Version die zum Zeitpunkt date gueltig war
|
|
335 @param onlyArchived:
|
|
336 onlyArchived=0: alle Projekte
|
|
337 onlyArchived= 1 : nur aktuelle Projekte
|
|
338 onlyArchived = 2: nur archivierte Projekte
|
|
339 """
|
|
340 # TODO: Die ganze Loesung
|
|
341 def sortP(x,y):
|
|
342 """sort by sorting number"""
|
|
343 return cmp(x.WEB_title,y.WEB_title)
|
|
344
|
|
345 ret=[]
|
|
346 if key:
|
|
347 logging.debug("MPIWGROOT (getProjectsOfMember):"+key)
|
|
348 proj=self.ProjectCatalog({'getPersonKeyList':utf8ify(key)})
|
|
349 else:
|
|
350 return ret # key muss definiert sein
|
|
351
|
|
352 #logging.debug("MPIWGROOT (getProjectsOfMember):"+repr(proj))
|
|
353 if proj:
|
|
354 proj2=[]
|
|
355 for x in proj:
|
|
356 #logging.error("proj:%s"%repr(x.getPath()))
|
|
357 if (not getattr(x.getObject(),'invisible',None)) and (getattr(x.getObject(),'archiveTime','')==''):
|
|
358 proj2.append(x)
|
|
359
|
|
360 else:
|
|
361 proj2=[]
|
|
362
|
|
363
|
|
364
|
|
365 proj2.sort(sortP)
|
|
366
|
|
367 projectListe=[]
|
|
368 #logging.error("getprojectsofmember proj2: %s"%repr(proj2))
|
|
369 for proj in proj2:
|
|
370 obj=proj.getObject()
|
|
371 add=False
|
|
372 if onlyArchived==1: #nur aktuell projecte
|
|
373 if not obj.isArchivedProject():
|
|
374 add=True
|
|
375 elif onlyArchived==2: #nur archivierte
|
|
376 if obj.isArchivedProject():
|
|
377 add=True
|
|
378 else: #alle
|
|
379 add=True
|
|
380
|
|
381 if onlyActive==1: #nur active projecte
|
|
382 if obj.isActiveProject():
|
|
383 add=add & True
|
|
384 else:
|
|
385 add=add & False
|
|
386
|
|
387 elif onlyArchived==2: #nur nicht aktvive
|
|
388 if not obj.isActiveProject():
|
|
389 add=add & True
|
|
390 else: #alle
|
|
391 add=add & True
|
|
392
|
|
393 if add:
|
|
394 projectListe.append(obj)
|
|
395
|
|
396 #logging.error("getprojectsofmember projectliste: %s"%repr(projectListe))
|
|
397 return projectListe
|
|
398
|
|
399
|
|
400 def givePersonList(self,name):
|
|
401 """check if person is in personfolder and return list of person objects"""
|
|
402
|
|
403 splitted=name.split(",")
|
|
404 if len(splitted)==1:
|
|
405 splitted=name.lstrip().rstrip().split(" ")
|
|
406 splittedNew=[split.lstrip() for split in splitted]
|
|
407
|
|
408 if splittedNew[0]=='':
|
|
409 del splittedNew[0]
|
|
410 search=string.join(splittedNew,' AND ')
|
|
411
|
|
412 if not search=='':
|
|
413 proj=self.MembersCatalog({'title':search})
|
|
414
|
|
415 if proj:
|
|
416 return [[x.lastName,x.firstName] for x in proj]
|
|
417 else:
|
|
418 return []
|
|
419
|
|
420 ## splitted=name.split(",") # version nachname, vorname...
|
|
421 ## if len(splitted)>1:
|
|
422 ## lastName=splitted[0]
|
|
423 ## firstName=splitted[1]
|
|
424 ## else:
|
|
425 ## splitted=name.split(" ") #version vorname irgenwas nachnamae
|
|
426
|
|
427 ## lastName=splitted[len(splitted)-1]
|
|
428 ## firstName=string.join(splitted[0:len(splitted)-1])
|
|
429
|
|
430 ## objs=[]
|
|
431
|
|
432 #print self.members
|
|
433 ## for x in self.members.__dict__:
|
|
434 ## obj=getattr(self.members,x)
|
|
435 ## if hasattr(obj,'lastName') and hasattr(obj,'firstName'):
|
|
436
|
|
437 ## if (re.match(".*"+obj.lastName+".*",lastName) or re.match(".*"+lastName+".*",obj.lastName)) and (re.match(".*"+obj.firstName+".*",firstName) or re.match(".*"+firstName+".*",obj.firstName)):
|
|
438
|
|
439 ## objs.append((obj,lastName+", "+firstName))
|
|
440
|
|
441
|
|
442 ## return objs
|
|
443
|
|
444
|
|
445 def personCheck(self,names):
|
|
446 """all persons for list"""
|
|
447 #print "names",names
|
|
448 splitted=names.split(";")
|
|
449 ret={}
|
|
450 for name in splitted:
|
|
451
|
|
452 if not (name==""):
|
|
453 try:
|
|
454 ret[name]=self.givePersonList(name)
|
|
455 except:
|
|
456 """NOTHIHN"""
|
|
457 #print "RET",ret
|
|
458 return ret
|
|
459
|
|
460 def giveCheckList(self,person,fieldname):
|
|
461 """return checklist"""
|
|
462 #print "GCL",fieldname
|
|
463 if fieldname=='xdata_01':
|
|
464 x=self.personCheck(person.getContent(fieldname))
|
|
465 #print "GCLBACKX",x
|
|
466 return x
|
|
467
|
|
468
|
|
469 # TODO: do we need this here?
|
|
470 def isCheckField(self,fieldname):
|
|
471 """return chechfield"""
|
|
472 return (fieldname in checkFields)
|
|
473
|
|
474
|
|
475
|
|
476 def sortResults(self,results):
|
|
477 """search the catalog and give results back sorted by meta_type"""
|
|
478 ret = {}
|
|
479 logging.debug(results())
|
|
480 for result in results():
|
|
481 metaType = result.meta_type
|
|
482 resultList= ret.get(metaType,[])
|
|
483 resultList.append(result)
|
|
484 ret[metaType]=resultList
|
|
485
|
|
486 logging.debug(ret)
|
|
487 return ret
|
|
488
|
|
489 # TODO: remove
|
|
490 def isActiveMember(self,key):
|
|
491 """tested ob Mitarbeiter key ist aktiv"""
|
|
492 key=utf8ify(key)
|
|
493 ret=getAt(self.ZSQLInlineSearch(_table='personal_www',
|
|
494 _op_key='eq',key=key,
|
|
495 _op_publish_the_data='eq',
|
|
496 publish_the_data='yes'), 0)
|
|
497
|
|
498 logging.info("MPIWGROOT ACTIVE_MEMBER %s"%ret)
|
|
499 if ret:
|
|
500 return True
|
|
501 else:
|
|
502 return False
|
|
503
|
|
504 # TODO: remove
|
|
505 def isActual(self,project):
|
|
506 """checke if project is actual"""
|
|
507 actualTime=time.localtime()
|
|
508
|
|
509 if hasattr(project,'getObject'): #obj ist aus einer catalogTrefferList
|
|
510 obj=project.getObject()
|
|
511 else:
|
|
512 obj=project
|
|
513
|
|
514 if getattr(obj,'archiveTime',actualTime)< actualTime:
|
|
515 return False
|
|
516 else:
|
|
517 return True
|
|
518
|
51
|
519
|
|
520 def getTree(self,dep=None,date=None,onlyActive=0,onlyArchived=0):
|
|
521 """generate Tree from project list
|
|
522 als Liste, jeder Eintrag ist ein Tupel (Tiefe, ProjektNummer, Titel, ProjektObject)
|
|
523 onlyActive = 0 : alle Projekte
|
|
524 onlyActive = 1 : nur active Projekte
|
|
525 onlyActive = 2: nur inactive Projekte
|
|
526
|
|
527 onlyArchived=0: alle Projekte
|
|
528 onlyArchived= 1 : nur aktuelle Projekte
|
|
529 onlyArchived = 2: nur archivierte Projekte
|
|
530
|
|
531 department fuer das Tree geholt werden soll
|
|
532 """
|
|
533 logging.debug("MPIWGRoot.getTree()")
|
|
534
|
|
535 returnListTmp=[]
|
|
536 returnList=[]
|
|
537
|
|
538 for project in self.getProjectFields('xdata_05',sort="int",date=date): # get Projects sorted by xdata_05
|
|
539
|
|
540 for idNr in project[1].split(";"): # more than one number
|
|
541 if not idNr=="":
|
|
542 splittedId=idNr.split(".")
|
|
543 depth=len(splittedId)
|
|
544 nr=idNr
|
|
545 #title=project[0].WEB_title
|
|
546 title=[project[0].getContent('WEB_title')]
|
|
547 #print title
|
|
548
|
|
549 if idNr[0]=="x": # kompatibilitaet mit alter Konvention, x vor der Nummer macht project inactive
|
|
550 project[0].setActiveFlag(False)
|
|
551
|
|
552 if (not dep) or (splittedId[0]==dep): #falls dep gesetzt ist nur dieses hinzufuegen.
|
|
553
|
|
554 if (onlyActive==0):
|
|
555 returnListTmp.append((depth,nr,title,project[0]))
|
|
556 elif (onlyActive==1) and project[0].isActiveProject(): #nur active projekte
|
|
557 returnListTmp.append((depth,nr,title,project[0]))
|
|
558 elif (onlyActive==2) and (not project[0].isActiveProject()): #nur active projekte
|
|
559 returnListTmp.append((depth,nr,title,project[0]))
|
|
560
|
|
561
|
|
562 #filter jetzt die Liste nach Archived oder nicht
|
|
563 for entry in returnListTmp:
|
|
564 if (onlyArchived==0):
|
|
565 returnList.append(entry)
|
|
566 elif (onlyArchived==1) and (not entry[3].isArchivedProject()): #nur active projekte
|
|
567 returnList.append(entry)
|
|
568 elif (onlyArchived==2) and (entry[3].isArchivedProject()): #nur active projekte
|
|
569 returnList.append(entry)
|
|
570
|
|
571
|
|
572 return returnList
|
|
573
|
|
574 def changePosition(self,treeId,select,RESPONSE=None):
|
|
575 """Change Postion Entry"""
|
|
576 numbers=[]
|
|
577
|
|
578 # Suche hoechste bisherige nummer
|
|
579 projects=self.getProjectFields('xdata_05') # get Projects sorted by xdata_05
|
|
580 #print "pj",projects
|
|
581 for project in projects: #suche alle subtrees der treeId
|
|
582 #print treeId
|
|
583
|
|
584 founds=re.match(treeId+"\.(.*)",project[1].split(";")[0])
|
|
585 if founds:
|
|
586 #print "x",founds.group(0),len(founds.group(0).split("."))
|
|
587 if len(founds.group(0).split("."))==len(treeId.split("."))+1: # nur ein punkt mehr, d.h. untere ebene
|
|
588 try:
|
|
589 numbers.append(int(founds.group(0).split(".")[len(founds.group(0).split("."))-1]))
|
|
590 except:
|
|
591 numbers.append(int(0))
|
|
592
|
|
593 try:
|
|
594 highest=max(numbers)
|
|
595 except:
|
|
596 highest=0
|
|
597 projects=self.showNewProjects()
|
|
598 for i in self.makeList(select):
|
|
599 highest+=10
|
|
600 projects[int(i)][0].xdata_05=treeId+"."+str(highest)
|
|
601
|
|
602 if RESPONSE is not None:
|
|
603 RESPONSE.redirect('showTree')
|
|
604
|
|
605 def changeTree(self,RESPONSE=None):
|
|
606 """change the complete tree"""
|
|
607 form=self.REQUEST.form
|
|
608 hashList={}
|
|
609 onlyArchived=int(form.get("onlyArchived",0))
|
|
610 onlyActive=int(form.get("onlyActive",0))
|
|
611 dep=form.get("dep",None)
|
|
612
|
|
613 fields=self.getTree(dep=dep,onlyArchived=onlyArchived,onlyActive=onlyActive)
|
|
614
|
|
615 logging.info("GOT TREE!----------------------------------------------------")
|
|
616 for field in form.keys():
|
|
617
|
|
618 splitted=field.split('_')
|
|
619 if (len(splitted)>1) and (splitted[1]=="runningNumber"): #feld hat die Form Nummer_name und runnignNumber
|
|
620
|
|
621
|
|
622 nr=int(splitted[0]) # nummer des Datensatzes
|
|
623 currentEntry = fields[nr]
|
|
624
|
|
625 if form.has_key(str(nr)+'_active'): # active flag is set
|
|
626 fields[nr][3].setActiveFlag(True)
|
|
627 else:
|
|
628 fields[nr][3].setActiveFlag(False)
|
|
629
|
|
630 #nummer hat sich geaendert
|
|
631
|
|
632 entryChanged = False;
|
|
633
|
|
634 if isinstance(fields[nr][3].xdata_05,list): #for some reasons somtimes the content of the field is a list with one entry.
|
|
635 fields[nr][3].xdata_05=fields[nr][3].xdata_05[0]
|
|
636
|
|
637 if not (fields[nr][3].xdata_05==form[str(nr)+'_number']):
|
|
638 logging.info("Changed!Number+++++++++++++++++++++++++++++++++")
|
|
639 logging.info(repr(fields[nr][3].xdata_05)+" ---> "+ repr(form[str(nr)+'_number']))
|
|
640 fields[nr][3].xdata_05=form[str(nr)+'_number']
|
|
641 entryChanged = True
|
|
642
|
|
643 #completed har sich geaendert
|
|
644
|
|
645 td = fields[nr][3].transformDate # hole die funktion zum transformieren des datums
|
|
646
|
|
647 if not (td(fields[nr][3].getCompletedAt())==td(form[str(nr)+'_completed'])):
|
|
648 fields[nr][3].setCompletedAt(form[str(nr)+'_completed'])
|
|
649 logging.info(repr(td(fields[nr][3].getCompletedAt()))+" ---> "+ repr(td(form[str(nr)+'_completed'])))
|
|
650 logging.info("Changed!Completed+++++++++++++++++++++++++++++++++")
|
|
651 entryChanged = True
|
|
652
|
|
653 if not (td(fields[nr][3].getStartedAt())==td(form[str(nr)+'_started'])):
|
|
654 fields[nr][3].setStartedAt(form[str(nr)+'_started'])
|
|
655
|
|
656 logging.info(repr(td(fields[nr][3].getStartedAt()))+" ---> "+ repr(td(form[str(nr)+'_started'])))
|
|
657 logging.info("Changed!Started+++++++++++++++++++++++++++++++++")
|
|
658 entryChanged = True
|
|
659
|
|
660
|
|
661 if entryChanged:
|
|
662 logging.info("Changed!+++++++++++++++++++++++++++++++++")
|
|
663 fields[nr][3].copyObjectToArchive()
|
|
664
|
|
665
|
|
666 if RESPONSE is not None:
|
|
667 RESPONSE.redirect('showTree')
|
|
668
|
|
669
|
|
670
|
|
671 def getProjectWithId(self,id):
|
|
672 fields=self.getProjectFields('xdata_05')
|
|
673 for field in fields:
|
|
674 if field[1]==id:
|
|
675 return field[0]
|
|
676
|
|
677 return None
|
|
678
|
|
679
|
|
680
|
|
681 def reindexCatalogs(self,RESPONSE=None):
|
|
682 """reindex members and project catalog"""
|
|
683
|
|
684
|
|
685 try:
|
|
686
|
|
687 self.ProjectCatalog.manage_catalogReindex(self.REQUEST,RESPONSE,self.REQUEST['URL1'])
|
|
688 logger("MPIWG Root (reindexCatalog: projects)",logging.INFO,"DONE")
|
|
689 except:
|
|
690 logger("MPIWG Root (reindexCatalog: projects)",logging.WARNING," %s %s"%sys.exc_info()[:2])
|
|
691
|
|
692 try:
|
|
693
|
|
694 self.MembersCatalog.manage_catalogReindex(self.REQUEST,RESPONSE,self.REQUEST['URL1'])
|
|
695 logger("MPIWG Root (reindexCatalog: members)",logging.INFO,"DONE")
|
|
696 except:
|
|
697 logger("MPIWG Root (reindexCatalog: members)",logging.WARNING," %s %s"%sys.exc_info()[:2])
|
|
698
|
|
699
|
|
700 #
|
|
701 # try:
|
|
702 #
|
|
703 # self.fulltextProjectsMembers.manage_catalogReindex(self.REQUEST,RESPONSE,self.REQUEST['URL1'])
|
|
704 # logger("MPIWG Root (reindexCatalog: fulltextProjectsMembers)",logging.INFO,"DONE")
|
|
705 # except:
|
|
706 # logger("MPIWG Root (reindexCatalog: fulltextProjectsMembers)",logging.WARNING," %s %s"%sys.exc_info()[:2])
|
|
707 #
|
|
708 #
|
|
709 #
|
|
710 #
|
|
711
|
|
712
|
|
713 if RESPONSE:
|
|
714 RESPONSE.redirect('manage_main')
|
|
715
|
|
716
|
|
717
|
|
718 def getProjectsByFieldContent(self,fieldName,fieldContentsEntry, date=None):
|
|
719 """gib alle Projekte aus mit Value von field mit fieldName enthaelt ein Element der Liste fieldContents"""
|
|
720 def sort(x,y):
|
|
721 return cmp(x.WEB_title[0],y.WEB_title[0])
|
|
722
|
|
723 if type(fieldContentsEntry) is StringType:
|
|
724 fieldContentsTmp=[fieldContentsEntry]
|
|
725 else:
|
|
726 fieldContentsTmp=fieldContentsEntry
|
|
727
|
|
728 fieldContents=[]
|
|
729 for x in fieldContentsTmp:
|
|
730 fieldContents.append(" AND ".join(x.split()))
|
|
731 projects=self.ProjectCatalog({fieldName:string.join(fieldContents,' AND')})
|
|
732 #print projects
|
|
733 #ret=[x for x in projects]
|
|
734 ret=[]
|
|
735 for x in projects:
|
|
736 obj=x.getObject()
|
|
737 obj=obj.getActualVersion(date)
|
|
738 if obj and (not getattr(obj,'invisible',None)):
|
|
739 #if not (x in ret):
|
|
740 ret.append(x)
|
|
741
|
|
742 ret.sort(sort)
|
|
743 return ret
|
|
744
|
|
745
|
|
746 def getProjectFields(self,fieldName,date=None,folder=None,sort=None):
|
|
747 """getListofFieldNames"""
|
|
748 ret=[]
|
|
749
|
|
750 objects=self.ZopeFind(self.projects,obj_metatypes=['MPIWGProject'],search_sub=0)
|
|
751
|
|
752
|
|
753 for object in objects:
|
|
754 obj=object[1]
|
|
755 obj=obj.getActualVersion(date)
|
|
756 if obj and (not getattr(obj,'invisible',None)):
|
|
757 if fieldName=="WEB_title_or_short":
|
|
758
|
|
759 if len(obj.getContent('xdata_07'))<3: # hack weil z.Z. manchmal noch ein Trennzeichen ; oder , im Feld statt leer
|
|
760 fieldNameTmp="WEB_title"
|
|
761 else:
|
|
762 fieldNameTmp="xdata_07"
|
|
763 else:
|
|
764 fieldNameTmp=fieldName
|
|
765
|
|
766 ret.append((obj,obj.getContent(fieldNameTmp)))
|
|
767
|
|
768
|
|
769 if sort=="int":
|
|
770 ret.sort(sortI)
|
|
771 elif sort=="stopWords":
|
|
772
|
|
773 ret.sort(sortStopWords(self))
|
|
774
|
|
775 else:
|
|
776 ret.sort(sortF)
|
|
777
|
|
778 return ret
|
|
779
|
|
780 def showNewProjects(self):
|
|
781 projects=[]
|
|
782 for objs in self.getProjectFields('WEB_title_or_short'): # Get all Projets
|
|
783 if objs[0].xdata_05 and (objs[0].xdata_05[0] == ""):
|
|
784
|
|
785 projects.append(objs)
|
|
786
|
|
787 return projects
|
|
788
|
|
789 def generateUrlProject(self,url,project=None):
|
|
790 """erzeuge aus absoluter url, relative des Projektes"""
|
|
791 if project:
|
|
792 splitted=url.split("/")
|
|
793 length=len(splitted)
|
|
794 short=splitted[length-2:length]
|
|
795
|
|
796 base=self.REQUEST['URL3']+"/"+"/".join(short)
|
|
797
|
|
798 else:
|
|
799 findPart=url.find("/projects/")
|
|
800 base=self.REQUEST['URL1']+"/"+url[findPart:]
|
|
801
|
|
802
|
|
803 return base
|
|
804
|
|
805
|
|
806 def versionHeaderEN(self):
|
|
807 """version header text"""
|
|
808
|
|
809 date= self.REQUEST.get('date',None)
|
|
810 if date:
|
|
811 txt="""<h2>This pages shows the project which existed at %s</h2>"""%str(date)
|
|
812 return txt
|
|
813 return ""
|
|
814
|
|
815 def versionHeaderDE(self):
|
|
816 """version header text"""
|
|
817 date= self.REQUEST.get('date',None)
|
|
818 if date:
|
|
819 txt="""<h2>Auf dieser Seite finden Sie die Projekte mit Stand vom %s</h2>"""%str(date)
|
|
820 return ""
|
|
821
|
|
822
|
52
|
823 def getContexts(self,childs=None,parents=None,depth=None,date=None,onlyActive=True):
|
|
824 """childs alle childs, alle parents"""
|
|
825 ret=[]
|
|
826
|
|
827 if parents:
|
|
828 pnums=parents.split(".")
|
|
829 while len(pnums) > 1:
|
|
830 pnums.pop()
|
|
831 parentId=string.join(pnums,".")
|
|
832
|
|
833 for project in self.getProjectFields('xdata_05',sort='int',date=date):
|
|
834 if project[1]==parentId:
|
|
835 ret.append(project)
|
|
836
|
|
837 if (depth is not None) and (len(ret) >= depth):
|
|
838 break
|
|
839
|
|
840 if childs:
|
|
841 for project in self.getProjectFields('xdata_05',sort='int',date=date):
|
|
842 searchStr=childs+"(\..*)"
|
|
843
|
|
844 if (onlyActive and project[0].isActiveProject()) or (not onlyActive):
|
|
845 if re.match(searchStr,project[1]):
|
|
846
|
|
847 if depth:
|
|
848
|
|
849 if int(depth)>=len(project[1].split("."))-len(childs.split(".")):
|
|
850
|
|
851 ret.append(project)
|
|
852 else:
|
|
853 ret.append(project)
|
|
854
|
|
855 #logging.debug("getContexts: childs=%s parents=%s depth=%s => %s"%(childs,parents,depth,repr(ret)))
|
|
856
|
|
857 return ret
|
|
858
|
60
|
859 def getAttribute(self, field):
|
|
860 """get attrbiute"""
|
|
861 return getattr(self, field)
|
|
862
|
52
|
863
|
65
|
864
|
|
865
|
|
866 def redirectIndex_html(self,request):
|
|
867 #return request['URL1']+'/index_html'
|
|
868
|
|
869 return urllib.urlopen(request['URL1']+'/index_html').read()
|
|
870
|
|
871
|
|
872 def formatBibliography(self,here,found):
|
|
873 """format"""
|
|
874 return formatBibliography(here,found)
|
|
875
|
|
876 def getValue(self,fieldStr):
|
|
877 """Inhalt des Feldes"""
|
|
878
|
|
879 if type(fieldStr)==StringType:
|
|
880 field=fieldStr
|
|
881 else:
|
|
882 field=fieldStr[0]
|
|
883 try:
|
|
884 if field[len(field)-1]==";":
|
|
885 field=field[0:len(field)-1]
|
|
886 except:
|
|
887
|
|
888 """nothing"""
|
|
889 field=re.sub(r';([^\s])','; \g<1>',field)
|
|
890 return field.encode('utf-8')
|
|
891
|
|
892
|
|
893
|
|
894 def sortedNames(self,list):
|
|
895 """sort names"""
|
|
896
|
|
897 def sortLastName(x_c,y_c):
|
|
898 try:
|
|
899 x=urllib.unquote(x_c).encode('utf-8','ignore')
|
|
900 except:
|
|
901 x=urllib.unquote(x_c)
|
|
902
|
|
903 try:
|
|
904 y=urllib.unquote(y_c).encode('utf-8','ignore')
|
|
905 except:
|
|
906 x=urllib.unquote(y_c)
|
|
907
|
|
908
|
|
909
|
|
910 try:
|
|
911 last_x=x.split()[len(x.split())-1]
|
|
912 last_y=y.split()[len(y.split())-1]
|
|
913
|
|
914 except:
|
|
915
|
|
916 last_x=""
|
|
917 last_y=""
|
|
918
|
|
919
|
|
920
|
|
921 if last_x<last_y:
|
|
922 return 1
|
|
923 elif last_x>last_y:
|
|
924 return -1
|
|
925 else:
|
|
926 return 0
|
|
927
|
|
928 list.sort(sortLastName)
|
|
929 list.reverse()
|
|
930
|
|
931 return list
|
|
932
|
|
933 def createOrUpdateId_raw(self):
|
|
934 """create sequence to create ids for bibliography"""
|
|
935 debug=None
|
|
936 #suche groesste existierende id
|
|
937 founds=self.ZSQLQuery("select id from bibliography")
|
|
938
|
|
939 if founds:
|
|
940 ids=[int(x.id[1:]) for x in founds]
|
|
941 maximum=max(ids)
|
|
942
|
|
943 id_raw=self.ZSQLQuery("select nextval('id_raw')",debug=debug)
|
|
944
|
|
945 if id_raw:
|
|
946 self.ZSQLQuery("drop sequence id_raw",debug=debug)
|
|
947
|
|
948 self.ZSQLQuery("create sequence id_raw start %i"%(maximum+1),debug=debug)
|
|
949
|
|
950
|
|
951 def queryLink(self,link):
|
|
952 """append querystring to the link"""
|
|
953 return "%s?%s"%(link,self.REQUEST.get('QUERY_STRING',''))
|
|
954
|
|
955 def getKategory(self,url):
|
|
956 """kategorie"""
|
|
957 splitted=url.split("/")
|
|
958 return splitted[4]
|
|
959
|
|
960 def isType(self,object,meta_type):
|
|
961 """teste ob ein object vom meta_type ist."""
|
|
962 return (object.meta_type==meta_type)
|
|
963
|
|
964
|
|
965 # TODO: remove
|
|
966 def replaceNotEmpty(self,format,field):
|
|
967 """replace not empty"""
|
|
968 if field and (not field.lstrip()==''):
|
|
969 return format%field
|
|
970 #return self.decode(format%field)
|
|
971 else:
|
|
972 return ""
|
|
973
|
|
974
|
|
975 def urlQuote(self,str):
|
|
976 """quote"""
|
|
977 return urllib.quote(str)
|
|
978
|
|
979 def urlUnQuote(self,str):
|
|
980 """quote"""
|
|
981 return urllib.unquote(str)
|
|
982
|
|
983 def updateInstitutsbiliography(self):
|
|
984 """update the Institutsbibliogrpahy"""
|
|
985 self.upDateSQL('personalwww.xml')
|
|
986 return "<html><body>DONE</body></html>"
|
|
987
|
|
988
|
|
989
|
|
990
|
|
991
|
|
992
|
|
993 def getAllMembers(self):
|
|
994 #ret=[]
|
|
995
|
|
996 def sorter(x,y):
|
|
997 return cmp(x[0].lower(),y[0].lower())
|
|
998
|
|
999 results=self.MembersCatalog({'isPublished':True})
|
|
1000
|
|
1001 ret=[(unicodify(", ".join([proj.lastName, proj.firstName])), proj.getKey) for proj in results]
|
|
1002
|
|
1003 ret.sort(sorter)
|
|
1004 return ret
|
|
1005
|
|
1006
|
|
1007 def printAllMembers(self):
|
|
1008 """print"""
|
|
1009 members=self.getAllMembers()
|
|
1010 ret=""
|
|
1011 for x in members:
|
|
1012 ret+="<p>%s</p>"%x
|
|
1013 return ret
|
|
1014
|
|
1015
|
|
1016 def makeList(self,entry):
|
|
1017 """makes a list out of one entry or repeat a list"""
|
|
1018 if type(entry) is StringType:
|
|
1019 return [entry]
|
|
1020 else:
|
|
1021 return entry
|
|
1022
|
|
1023 def getTreeRSS(self,dep=None,date=None,onlyActive=1,onlyArchived=0):
|
|
1024 """generateTree"""
|
|
1025 rss="""<?xml version="1.0" encoding="utf-8"?>
|
|
1026 <rss version="2.0">
|
|
1027 <channel>"""
|
|
1028
|
|
1029 for obj in self.getTree(dep, date, onlyActive, onlyArchived):
|
|
1030 linkStr="""<link>http://www.mpiwg-berlin.mpg.de/en/research/projects/%s</link>"""
|
|
1031 rss+="""<item>"""
|
|
1032 rss+=linkStr%obj[3].getId()
|
|
1033 rss+="""</item>"""
|
|
1034 if hasattr(obj[3],'publicationList'):
|
|
1035 rss+="""<item>"""
|
|
1036 rss+=linkStr%(obj[3].getId()+"/publicationList");
|
|
1037 rss+="""</item>"""
|
|
1038 rss+="""</channel>
|
|
1039 </rss>"""
|
|
1040
|
|
1041 return rss
|
|
1042
|
|
1043
|
|
1044 def getRelativeUrlFromPerson(self,list):
|
|
1045 """get urls to person list"""
|
|
1046 ret=[]
|
|
1047 persons=list.split(";")
|
|
1048 for person in persons:
|
|
1049
|
|
1050 if len(person)>1: #nicht nur Trennzeichen
|
|
1051 splitted=person.split(",")
|
|
1052 if len(splitted)==1:
|
|
1053 splitted=person.split(" ")
|
|
1054 splittedNew=[re.sub(r'\s(.*)','$1',split) for split in splitted]
|
|
1055 if splittedNew[0]=='':
|
|
1056 del splittedNew[0]
|
|
1057 search=string.join(splittedNew,' AND ')
|
|
1058
|
|
1059 if not search=='':
|
|
1060
|
|
1061 try:
|
|
1062 proj=self.MembersCatalog({'title':search})
|
|
1063 except:
|
|
1064 proj=None
|
|
1065
|
|
1066 if proj:
|
|
1067 #ret.append("<a href=%s >%s</a>"%(proj[0].absolute_url,person.encode('utf-8')))
|
|
1068 ret.append("<a href=%s >%s</a>"%('members/'+proj[0].id+'/index.html',person))
|
|
1069 else:
|
|
1070 #ret.append("%s"%person.encode('utf-8'))
|
|
1071 ret.append("%s"%person)
|
|
1072 return string.join(ret,";")
|
|
1073
|
|
1074 def getMemberIdFromKey(self,key):
|
|
1075 """gibt die ensprechende id im members Ordner zum key"""
|
|
1076
|
|
1077 if key=="":
|
|
1078 return ""
|
|
1079 try:
|
|
1080 key=utf8ify(key)
|
|
1081 catalogged=self.MembersCatalog({'getKey':key})
|
|
1082 if len(catalogged)==0:
|
|
1083 return ""
|
|
1084 else:
|
|
1085 return catalogged[0].getObject().getId()
|
|
1086
|
|
1087 except:
|
|
1088 return ""
|
|
1089
|
|
1090 def subNavStatic(self,obj):
|
|
1091 """subnav" von self"""
|
|
1092 subs=self.ZopeFind(obj,obj_metatypes=['MPIWGTemplate','MPIWGLink'])
|
|
1093 subret=[]
|
|
1094
|
|
1095 for x in subs:
|
|
1096 if not(x[1].title==""):
|
|
1097 subret.append(x)
|
|
1098 subret.sort(sortWeight)
|
|
1099 return subret
|
|
1100
|
|
1101
|
|
1102 def isActive(self,name):
|
|
1103 """teste ob subnavigation aktiv"""
|
|
1104 for part in self.REQUEST['URL'].split("/"):
|
|
1105 if part==name:
|
|
1106 return True
|
|
1107 return False
|
|
1108
|
|
1109
|
|
1110 def getSectionStyle(self, name, style=""):
|
|
1111 """returns a string with the given style + '-sel' if the current section == name"""
|
|
1112 if self.getSection() == name:
|
|
1113 return style + '-sel'
|
|
1114 else:
|
|
1115 return style
|
|
1116
|
|
1117
|