1
|
1 #Klasse zum Taggen und Anzeigen der Tags von Projekte bzw. allgemein Webseiten des Institutes
|
|
2 #Tags werden in der Instanz abgespeichert
|
|
3 #Personenname kommen aus dem Virtuoso-Triplestore , lokal erzeugte zusaetliche Name werden dort abgespeichert
|
|
4 #Fuer die Suche über die Personenname wird das MetaDataManagerRestlet benoetigt.
|
|
5 #TODO: Zur Zeit werden die entsprechenden Server URLs hier in der Klasse definiert.
|
|
6
|
|
7
|
0
|
8 # TODO: generell verwaltung der tags im triple store und nicht in zope.
|
1
|
9 # TODO: mache server und namespaces konfigurierbar im project
|
|
10
|
|
11
|
0
|
12 from OFS.Folder import Folder
|
|
13 from Globals import package_home
|
|
14 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
|
|
15 from BTrees.OOBTree import OOBTree
|
|
16 from BTrees.OOBTree import OOSet
|
2
|
17 from AccessControl import ClassSecurityInfo
|
|
18
|
0
|
19 #import os
|
|
20 import os.path
|
|
21 import logging
|
|
22 import time
|
|
23 import email.Utils
|
|
24 from types import ListType
|
|
25 import transaction
|
|
26 import random
|
|
27 import urllib2
|
|
28 import urllib
|
|
29
|
1
|
30 #Entry beschreibt jeweils einen Tag mit dem Namen "title", entries enthaelt eine Liste von Subtags (der Klasse Entry), die diesem Tag untergeordnet sind.
|
0
|
31 class Entry:
|
|
32 """publicClass"""
|
1
|
33
|
|
34 #===========================================================================
|
|
35 # __init__
|
|
36 #===========================================================================
|
0
|
37 def __init__(self,title,entries=[]):
|
|
38 self.title=title
|
|
39 self.entries=entries
|
|
40
|
|
41 def getTitle(self):
|
|
42 """getTitle"""
|
|
43 return self.title
|
|
44
|
1
|
45 #Beschriebt einen von einem Benutzer vorgeschlagenen Tag
|
0
|
46 class SuggestedTag:
|
|
47 """publicClass"""
|
|
48 type=""
|
|
49 userName=""
|
|
50 def __init__(self,name,comment,type,userName):
|
|
51 self.name=name
|
|
52 self.comment=comment
|
|
53 self.type=type
|
|
54 self.userName=userName
|
|
55
|
|
56
|
|
57 class MPIWGThesaurus(Folder):
|
|
58 """MPIWGThesaurus main folder"""
|
2
|
59 security=ClassSecurityInfo()
|
|
60
|
0
|
61 meta_type="MPIWGThesaurus"
|
|
62
|
|
63 TMP_PERSON_NS="http://ontologies.mpiwg-berlin.mpg.de/tempObjects/person/"
|
|
64 ONTOLOGY_NS="http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/"
|
|
65 #personproviderURL="http://127.0.0.1:8280/MetaDataManagerRestlet/person/"
|
|
66 personproviderURL="http://virtuoso.mpiwg-berlin.mpg.de:8080/MetaDataManagerRestlet/person/"
|
|
67 additionalNamesGraphURL="file://newpersonsFromProjects"
|
|
68
|
|
69 #virtuosoServer="http://ontologies.mpiwg-berlin.mpg.de"
|
|
70 virtuosoServer="http://virtuoso.mpiwg-berlin.mpg.de:8890"
|
|
71 virtuosoDAV="/DAV/home/websiteuser/"
|
|
72 virtuosoDAVUser="websiteuser"
|
|
73 virtuosoDAVPW="w3s45us3"
|
|
74 virtuosoGraph="file://newpersonsFromProjects"
|
|
75
|
1
|
76 #BTrees fuer die Tags
|
|
77
|
0
|
78 projectPersons= OOBTree()
|
|
79 projectObjects= OOBTree()
|
|
80 projectHistoricalPlaces= OOBTree()
|
|
81 projectSuggestedTags= OOBTree()
|
|
82 persons2Projects= OOBTree()
|
3
|
83 objects2Projects=OOBTree()
|
0
|
84 historicalPlaces2Projects=OOBTree()
|
|
85 suggestedTags2Projects=OOBTree()
|
4
|
86 personIDtoNames=OOBTree() # weist den personenIDs Klartextnamen aus dem Triplestore zu
|
|
87 personsIDForSort=[] # liste (personenID,(nachname,vorname) sortiert nach dem tupel (nachname,vorname)
|
0
|
88 suggestedPersons= OOBTree(); #TODO: das sollte die ueberfluessig werde und nur im triple store stehen.
|
|
89
|
|
90 tagList=[]
|
1
|
91
|
|
92 #default liste fuer tags, wird ueber das Managementinterface ueberschrieben
|
0
|
93 approachesTxt="""A
|
|
94 ---
|
|
95 ent1
|
|
96 ---
|
|
97 B
|
|
98 ---
|
|
99 enta
|
|
100 entb
|
|
101 entc
|
|
102 """
|
|
103
|
|
104 disciplines=[]
|
|
105 disciplinesTxt="""A
|
|
106 B
|
|
107 C
|
|
108 """
|
|
109
|
|
110 periods=[]
|
|
111 periodsTxt="""PA
|
|
112 PB
|
|
113 PC
|
|
114 """
|
|
115
|
|
116 spaces=[]
|
|
117 spacesTxt="""SPA
|
|
118 ---
|
|
119 sPent1
|
|
120 ---
|
|
121 SPB
|
|
122 ---
|
|
123 SPenta
|
|
124 SPentb
|
|
125 SPentc
|
|
126 """
|
|
127 technologies=[]
|
|
128 technologiesTxt="""TPA
|
|
129 ---
|
|
130 TPent1
|
|
131 ---
|
|
132 TPB
|
|
133 ---
|
|
134 TPenta
|
|
135 TPentb
|
|
136 TPentc
|
|
137 """
|
|
138
|
|
139 knowledgeTransfers=[]
|
|
140 knowledgeTransfersTxt="""KTPA
|
|
141 ---
|
|
142 TPent1
|
|
143 ---
|
|
144 TPB
|
|
145 ---
|
|
146 TPenta
|
|
147 TPentb
|
|
148 TPentc
|
|
149 """
|
|
150
|
|
151
|
|
152
|
|
153
|
|
154
|
|
155
|
|
156 manage_options = Folder.manage_options+(
|
1
|
157 {'label':'Thesaurus entries','action':'changeMPIWGThesaurusForm'},
|
|
158 {'label':'Manage Thesaurus','action':'manageMPIWGThesaurus'},
|
0
|
159 #{'label':'Change Publications Special','action':'changePublications_specialForm'},
|
|
160 )
|
|
161
|
|
162 def __init__(self,id):
|
|
163 """init"""
|
|
164 self.id=id
|
|
165
|
|
166
|
|
167 def index_html(self):
|
|
168 """index file"""
|
1
|
169
|
0
|
170 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','index.html')).__of__(self)
|
|
171 return pt()
|
|
172
|
2
|
173 security.declareProtected('View management screens','changeMPIWGThesaurusForm')
|
0
|
174 def changeMPIWGThesaurusForm(self):
|
|
175 """form for changing the project"""
|
|
176 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeMPIWGThesaurusForm.zpt')).__of__(self)
|
|
177 return pt()
|
|
178
|
2
|
179 security.declareProtected('View management screens','manageMPIWGThesaurus')
|
1
|
180 def manageMPIWGThesaurus(self):
|
|
181 """form for changing the project"""
|
|
182 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','manageMPIWGThesaurus.zpt')).__of__(self)
|
|
183 return pt()
|
|
184
|
2
|
185 security.declareProtected('View management screens','changeMPIWGThesaurus')
|
0
|
186 def changeMPIWGThesaurus(self,approachesTxt,disciplinesTxt,periodsTxt,spacesTxt,technologiesTxt,knowledgeTransfersTxt,RESPONSE=None):
|
|
187 """change it"""
|
|
188 self.approachesTxt=approachesTxt
|
|
189 self.disciplinesTxt=disciplinesTxt
|
|
190 self.periodsTxt=periodsTxt
|
|
191 self.spacesTxt=spacesTxt
|
|
192 self.technologiesTxt=technologiesTxt
|
|
193 self.knowledgeTransfersTxt=knowledgeTransfersTxt
|
|
194
|
|
195 if RESPONSE is not None:
|
|
196 redirect(RESPONSE,'manage_main')
|
|
197
|
|
198 #In der Anzeige soll der Name der zitierten Personen in Klartext angezeigt werden, ausserdem die Varianten, wie sie tatsaechlich
|
|
199 #in den Projekten benutzt werden
|
2
|
200
|
4
|
201 security.declareProtected('View management screens','collectPersonNamesToIds')
|
0
|
202 def collectPersonNamesToIds(self):
|
1
|
203 """Ordne Namen aus dem Triplestore bzw. die vergebenenden Label den Personen-Ids zu."""
|
4
|
204 self.personIDtoNames=OOBTree() # loesche alle
|
|
205 self.personsIDForSort=[]
|
|
206 personsIDForSortTmp=[]
|
0
|
207 for personID in self.persons2Projects:
|
4
|
208 mainName,sortName=self.getMainNameFromTripleStore(personID); # hole die hauptbezeichnung aus dem triplestore
|
0
|
209
|
|
210 personNames=[]
|
|
211 for project in self.persons2Projects.get(personID):
|
|
212 #hole die personen aus dem projekte
|
|
213 logging.debug("Found:project:"+project)
|
|
214 namesInProject = self.projectPersons.get(project)
|
|
215
|
|
216 for nameInProjectTuple in namesInProject:
|
|
217 logging.debug(repr(nameInProjectTuple))
|
|
218 nameInProject=nameInProjectTuple[1]
|
|
219 logging.debug(nameInProjectTuple[0]+"??"+personID)
|
|
220 if nameInProjectTuple[0]==personID:
|
|
221 logging.debug("changing")
|
|
222 if mainName=="": # es gibt keinen Eintrag im Triplestore fuer name (sollte eigentlich nicht sein, ist dann ein Fehler dort)
|
|
223 mainName=nameInProject #nimm dann aber den ersten aus den projekten
|
|
224 if nameInProject!=mainName:
|
|
225 personNames.append(nameInProject)
|
|
226
|
|
227 logging.debug(str(mainName)+"- foundalso :"+",".join(personNames))
|
|
228 self.personIDtoNames.update({personID:(mainName,personNames)})
|
4
|
229 personsIDForSortTmp.append((personID,sortName))
|
|
230
|
|
231
|
|
232
|
|
233
|
|
234 #sortiere personIDs nach erstmal nach Nachnamene TODO: sortiere nach name,vorname
|
|
235 def sort(x,y):
|
|
236 logging.debug("sort:")
|
|
237 logging.debug((x[1][0],y[1][0]))
|
|
238 return cmp(x[1][0],y[1][0])
|
|
239
|
|
240 personsIDForSortTmp.sort(cmp=sort)
|
|
241
|
|
242 self.personsIDForSort=[x[0] for x in personsIDForSortTmp]
|
|
243
|
0
|
244 self.personIDtoNames=self.personIDtoNames # make clear that it has changed #TODO: change this to variablen with names _p
|
|
245
|
1
|
246 #Hole die Namen, die einer personID zugeordnet sind.
|
0
|
247 def getNamesFromID(self,personID):
|
|
248 retStr=""
|
|
249 retStr+=self.personIDtoNames.get(personID)[0] # hole die Hauptbezeichnung
|
|
250 additionalNames = self.personIDtoNames.get(personID)[1]
|
|
251 if len(additionalNames)>0:
|
|
252 retStr+=" ("+",".join(additionalNames)+","+")"
|
|
253 return retStr
|
|
254
|
|
255
|
1
|
256 #Hole die Hauptnamemsansetzung aus dem Triplestore ),falls vorhanden, wenn nicht ist der String leer.
|
4
|
257 #ausserdem einen Namen zum sortieren, = Tupel(nachname, vorname)
|
0
|
258 def getMainNameFromTripleStore(self,personID):
|
|
259
|
|
260
|
|
261 cmdString ="""select * where { <%s> <http://xmlns.com/foaf/0.1/name> ?name}"""%personID
|
|
262
|
4
|
263 names= self.callSparql(cmdString)
|
|
264
|
|
265 cmdString ="""select * where { <%s> <http://xmlns.com/foaf/0.1/lastName> ?name}"""%personID
|
|
266
|
|
267 lastName= self.callSparql(cmdString)
|
|
268
|
|
269 cmdString ="""select * where { <%s> <http://xmlns.com/foaf/0.1/firstName> ?name}"""%personID
|
|
270
|
|
271 firstName= self.callSparql(cmdString)
|
|
272
|
|
273 return names,(lastName,firstName)
|
|
274
|
|
275
|
|
276 def callSparql(self,cmdString):
|
0
|
277
|
|
278 auth_handler = urllib2.HTTPBasicAuthHandler()
|
|
279 auth_handler.add_password(realm='sparql',
|
|
280 uri=self.virtuosoServer+"/sparql",
|
|
281 user=self.virtuosoDAVUser,
|
|
282 passwd=self.virtuosoDAVPW)
|
|
283
|
|
284 opener = urllib2.build_opener(auth_handler)
|
|
285 opener.addheaders = [('Content-Type','application/sparql-query')]
|
|
286
|
|
287 logging.debug(cmdString)
|
|
288 try:
|
4
|
289 logging.debug(self.virtuosoServer+"/sparql?" + urllib.urlencode({'query':cmdString,'default-graph-uri':self.virtuosoGraph,'named-graph-uri':'','format':'text/csv'}))
|
|
290 #r= opener.open(self.virtuosoServer+"/sparql", urllib.urlencode({'query':cmdString,'default-graph-uri':self.virtuosoGraph,'named-graph-uri':'','format':'text/csv'}))
|
|
291 r= opener.open(self.virtuosoServer+"/sparql", urllib.urlencode({'query':cmdString,'default-graph-uri':'','named-graph-uri':'','format':'text/csv'}))
|
0
|
292 namesTxt=r.read()
|
|
293 except urllib2.URLError, e:
|
|
294 logging.error(e.code)
|
|
295 logging.error(e.read())
|
4
|
296
|
|
297
|
0
|
298 return
|
4
|
299 logging.debug(namesTxt)
|
0
|
300 names=namesTxt.split("\n")
|
|
301 if len(names) < 2: #in der ersten Zeile stehen bei der Rückgabe die Spaltennamen, <2 heiss also es gibt keinen Eintrag
|
|
302 return
|
|
303
|
|
304 return names[1].replace('"','') # wir nehmen nur den ersten treffer
|
|
305
|
|
306
|
2
|
307 security.declareProtected('View management screens','changeTags')
|
0
|
308 def changeTags(self,projectID,approaches=[],disciplines=[],periods=[],spaces=[],technologies=[],transfers=[],RESPONSE=None):
|
|
309 """change tags"""
|
|
310 self.changeTagFromList(projectID,"approaches", approaches)
|
|
311 self.changeTagFromList(projectID,"disciplines", disciplines)
|
|
312 self.changeTagFromList(projectID,"periods", periods)
|
|
313 self.changeTagFromList(projectID,"spaces", spaces)
|
|
314 self.changeTagFromList(projectID,"technologies", technologies)
|
|
315 self.changeTagFromList(projectID,"transfers", transfers)
|
|
316
|
|
317 self.projectObjects=self.projectObjects #necessesary to make the object persistent after the first call
|
|
318 self.projectHistoricalPlaces=self.projectHistoricalPlaces #necessesary to make the object persistent after the first call
|
|
319 self.projectPersons=self.projectPersons #necessesary to make the object persistent after the first call
|
|
320 self.projectSuggestedTags=self.projectSuggestedTags
|
|
321
|
|
322 self.persons2Projects=self.persons2Projects
|
3
|
323 self.objects2Projects=self.objects2Projects
|
0
|
324 self.historicalPlaces2Projects=self.historicalPlaces2Projects
|
|
325 self.suggestedTags2Projects=self.suggestedTags2Projects;
|
|
326
|
|
327 self.suggestedPersons=self.suggestedPersons;
|
|
328
|
2
|
329 security.declareProtected('View management screens','deleteAllTags')
|
0
|
330 def deleteAllTags(self):
|
|
331 """deleteAllTags - TODO: take this out!!,"""
|
|
332 setattr(self,"tags",None)
|
|
333
|
|
334 return "DONE!"
|
|
335
|
2
|
336 security.declareProtected('View management screens','deleteAllPersons')
|
0
|
337 def deleteAllPersons(self):
|
|
338 """deleteAllTags - TODO: take this out!!,"""
|
|
339 self.projectPersons= OOBTree()
|
|
340 self.persons2Projects= OOBTree()
|
|
341 self.personIDtoNames=OOBTree()
|
|
342 self.suggestedPersons= OOBTree(); #TODO: das sollte die ueberfluessig werde und nur im triple store stehen.
|
|
343
|
|
344
|
|
345 return "DONE!"
|
2
|
346
|
3
|
347 security.declareProtected('View management screens','deleteAllObjects')
|
|
348 def deleteAllObjects(self):
|
|
349 """deleteAllTags - TODO: take this out!!,"""
|
|
350 logging.debug("delete all objects")
|
|
351 self.projectObjects= OOBTree()
|
|
352 self.objects2Projects=OOBTree()
|
|
353
|
|
354
|
|
355 return "DONE!"
|
|
356
|
0
|
357 def changeTagFromList(self,projectID,tagType,tagList):
|
|
358
|
|
359 logging.debug("changing:"+projectID)
|
|
360 logging.debug("asking tag::"+tagType)
|
|
361 if type(tagList) is not ListType:
|
|
362 tagList=[tagList]
|
|
363
|
|
364
|
|
365 tags = getattr(self,"tags",None)
|
|
366 if tags is None:
|
|
367 logging.debug("Create new tags")
|
|
368 tags=OOBTree()
|
|
369 setattr(self,"tags",tags)
|
|
370
|
|
371
|
|
372 tagsStored=tags.get(tagType,None)
|
|
373 if tagsStored is None:
|
|
374 tagsStored=OOBTree();
|
|
375
|
|
376
|
|
377
|
|
378 for tag in tagsStored.keys(): #gehe durch alle gespeichteren tags
|
|
379 logging.debug("checking:"+tag)
|
|
380 currentApproach = tagsStored.get(tag,None)
|
|
381 logging.debug(currentApproach)
|
|
382 if currentApproach is None:
|
|
383 currentApproach=OOSet()
|
|
384
|
|
385 if tag in tagList: #dieser ist getagged
|
|
386 currentApproach.update([projectID]);
|
|
387 tagList.remove(tag);
|
|
388 else:
|
|
389 if currentApproach.has_key(projectID):
|
|
390 currentApproach.remove(projectID);
|
|
391
|
|
392 tagsStored.update({tag:currentApproach});
|
|
393
|
|
394 for tag in tagList: # alle die nich nicht abearbeitet worden muessen noch angelegt werden
|
|
395 logging.debug("adding:"+tag)
|
|
396 newApproach=OOSet()
|
|
397 newApproach.update([projectID]);
|
|
398 tagsStored.insert(tag, newApproach);
|
|
399
|
|
400 tags.update({tagType:tagsStored})
|
|
401
|
|
402 transaction.commit()
|
|
403
|
|
404 def getTitle(self,entry):
|
|
405 return entry.title
|
|
406
|
|
407 def getEntries(self,entry):
|
|
408 return entry.entries
|
|
409
|
1
|
410 #nimmt ein eine Text der Form
|
|
411 # TAG1
|
|
412 # ---
|
|
413 # SUBTAG1_1
|
|
414 # SUBTAG1_2
|
|
415 # ---
|
|
416 # TAG2
|
|
417 # ---
|
|
418 # SUBTAG2_1
|
|
419 # SUBTAG2_2
|
|
420 #....
|
|
421 # und erzeugt daraus eine entsprechende Liste von Entries
|
0
|
422 def getEntriesFromTxt(self,txt):
|
|
423 apps=[]
|
|
424 lines=txt.split("\n");
|
|
425 level=False
|
|
426 for line in lines:
|
|
427 line=line.rstrip().lstrip()
|
|
428 if line=="":
|
|
429 continue
|
|
430 if line=="---":
|
|
431
|
|
432 if level:
|
|
433 level=False
|
|
434 else:
|
|
435 level=True
|
|
436 else:
|
|
437 if not level:
|
|
438 entry=Entry(line,[])
|
|
439 apps.append(entry)
|
|
440 else:
|
|
441 entry.entries.append(Entry(line))
|
|
442
|
|
443 return apps[0:]
|
|
444
|
|
445 def getApproaches(self):
|
|
446
|
|
447 self.tagList=self.getEntriesFromTxt(self.approachesTxt)
|
|
448 return self.tagList
|
|
449
|
2
|
450
|
0
|
451 def getTagsJSON(self,projectID,tagType,RESPONSE=None):
|
|
452 """get all selected tagList"""
|
|
453 logging.debug("asking:"+projectID)
|
|
454 logging.debug("asking tag::"+tagType)
|
|
455 retList=[]
|
|
456 tags = getattr(self,"tags",None)
|
|
457 if tags is None:
|
|
458 return;
|
|
459
|
|
460 tagsStored=tags.get(tagType,None)
|
|
461 if tagsStored is None:
|
|
462 return;
|
|
463
|
|
464 for tag in tagsStored.keys(): #gehe durch alle gespeichteren approached
|
|
465 logging.debug("checking:"+tag)
|
|
466 currentTag = tagsStored.get(tag,None)
|
|
467 if currentTag is None:
|
|
468 continue
|
|
469 if currentTag.has_key(projectID):
|
|
470 retList.append(""" "%s" """%tag)
|
|
471
|
|
472 if RESPONSE:
|
|
473 RESPONSE.setHeader('Content-Type', "application/json")
|
|
474
|
|
475 logging.debug(retList)
|
|
476 return "["+",".join(retList)+"]"
|
|
477
|
|
478 def getDisciplines(self):
|
|
479
|
|
480 self.disciplines=self.getEntriesFromTxt(self.disciplinesTxt)
|
|
481 return self.disciplines
|
|
482
|
|
483
|
|
484 def getObjectsJSON(self,term="",RESPONSE=None):
|
|
485 """ get all stored objects as json list starting with term"""
|
|
486 term=term.lower();
|
|
487 logging.debug("Asking:"+term)
|
|
488 #objectList=["baus","berg","lurg"]
|
|
489 objects = self.objects2Projects;
|
|
490
|
|
491 objectList= [x for x in objects.keys()]
|
|
492
|
|
493 logging.debug("Create:"+repr(objectList))
|
|
494 retList=[]
|
|
495 for object in objectList:
|
|
496 if object.find(term)>-1:
|
|
497 retList.append(""" "%s" """%object)
|
|
498 ret="["
|
|
499 ret+=",".join(retList)
|
|
500 ret+="]"
|
|
501 logging.debug("Objects:"+ret)
|
|
502 if RESPONSE:
|
|
503 RESPONSE.setHeader('Content-Type', "application/json")
|
|
504 return ret
|
|
505
|
|
506
|
|
507 def getHistoricalPlacesJSON(self,term="",RESPONSE=None):
|
|
508 """ get all stored historicalPlaces as json list starting with term"""
|
|
509 term=term.lower();
|
|
510 logging.debug("Asking:"+term)
|
|
511 #historicalPlaceList=["baus","berg","lurg"]
|
|
512 historicalPlaces = self.historicalPlaces2Projects;
|
|
513
|
|
514 historicalPlaceList= [x for x in historicalPlaces.keys()]
|
|
515
|
|
516 logging.debug("Create:"+repr(historicalPlaceList))
|
|
517 retList=[]
|
|
518 for historicalPlace in historicalPlaceList:
|
|
519 if historicalPlace.find(term)>-1:
|
|
520 retList.append(""" "%s" """%historicalPlace)
|
|
521 ret="["
|
|
522 ret+=",".join(retList)
|
|
523 ret+="]"
|
|
524 logging.debug("historicalPlaces:"+ret)
|
|
525 if RESPONSE:
|
|
526 RESPONSE.setHeader('Content-Type', "application/json")
|
|
527 return ret
|
|
528
|
|
529
|
|
530 def getPeriods(self):
|
|
531
|
|
532 self.periodes=self.getEntriesFromTxt(self.periodsTxt)
|
|
533 return self.periodes
|
|
534
|
|
535 def getSpaces(self):
|
|
536
|
|
537 self.spaces=self.getEntriesFromTxt(self.spacesTxt)
|
|
538 return self.spaces
|
|
539
|
|
540 def getTechnologies(self):
|
|
541
|
|
542 self.technologies=self.getEntriesFromTxt(self.technologiesTxt)
|
|
543 return self.technologies
|
|
544
|
|
545 def getKnowledgeTransfers(self):
|
|
546
|
|
547 self.knowledgeTransfers=self.getEntriesFromTxt(self.knowledgeTransfersTxt)
|
|
548 return self.knowledgeTransfers
|
|
549
|
|
550
|
|
551 def getObjectsFromProject(self,projectID):
|
|
552 return self.getFromProject(self.projectObjects,projectID);
|
|
553
|
|
554 def getHistoricalPlacesFromProject(self,projectID):
|
|
555 return self.getFromProject(self.projectHistoricalPlaces,projectID);
|
|
556
|
|
557 def getSuggestedTagsFromProject(self,projectID):
|
|
558 return self.getFromProject(self.projectSuggestedTags,projectID);
|
|
559
|
|
560
|
|
561 def getPersonsFromProject(self,projectID):
|
|
562 return self.getFromProject(self.projectPersons,projectID);
|
|
563
|
|
564 def getFromProject(self,objects,projectID):
|
|
565 if objects.has_key(projectID):
|
|
566 logging.debug("key exists:"+projectID)
|
|
567 persons=objects.get(projectID);
|
|
568 else:
|
|
569 persons=OOSet()
|
|
570 objects.update({projectID:persons})
|
|
571 logging.debug("key does not exists:"+projectID)
|
|
572
|
|
573
|
|
574 return persons
|
|
575
|
|
576 def getHistoricalPlacesFromProjectAsHTML(self,projectID):
|
|
577 """gertobjects"""
|
|
578 return self.getFromProjectAsHTML(self.projectHistoricalPlaces, projectID, "HistoricalPlace");
|
|
579
|
|
580 def getObjectsFromProjectAsHTML(self,projectID):
|
|
581 """gertobjects"""
|
|
582 return self.getFromProjectAsHTML(self.projectObjects, projectID, "Object");
|
|
583
|
|
584 def getPersonsFromProjectAsHTML(self,projectID):
|
|
585 """getpersons"""
|
|
586 return self.getFromProjectAsHTML(self.projectPersons, projectID, "Person");
|
|
587
|
|
588
|
|
589 def getFromProjectAsHTML(self,objects,projectID,type):
|
|
590 """getpersons"""
|
|
591 ret=""
|
|
592 if objects.has_key(projectID):
|
|
593 persons=objects.get(projectID);
|
|
594 else:
|
|
595 persons=OOSet()
|
|
596
|
|
597
|
|
598 for person in persons:
|
|
599 ret+="""<div class="removeButton">
|
|
600 <span>%s </span><div style="display:inline" class="remove%s"><span style="display:none" class="removeValue">%s</span>remove</div>
|
|
601 </div>"""%(person[1],type,person[0])
|
|
602
|
|
603
|
|
604 # ret+="""<div>
|
|
605 # <input type="checkbox" name="persons_remove"
|
|
606 # value="%s">
|
|
607 # <span>%s</span>
|
|
608 # </div>"""%(person[0],person[1])
|
|
609 #
|
|
610 logging.debug(type+":"+ret)
|
|
611 return ret
|
|
612
|
2
|
613 security.declareProtected('View management screens','removeHistoricalPlaceFromProject')
|
0
|
614 def removeHistoricalPlaceFromProject(self,projectID,value):
|
|
615 """remove"""
|
|
616 logging.debug("removeHP:"+projectID+":"+value);
|
|
617
|
|
618 HistoricalPlaces = self.getHistoricalPlacesFromProject(projectID)
|
|
619 for HistoricalPlace in HistoricalPlaces.keys():
|
|
620
|
|
621 logging.debug("trying:"+repr(HistoricalPlace[0])+"::"+repr(value)+"__")
|
|
622 if HistoricalPlace[0]==value:
|
|
623 logging.debug("---removed!")
|
|
624 HistoricalPlaces.remove(HistoricalPlace)
|
|
625
|
|
626 self.projectHistoricalPlaces.update({projectID:HistoricalPlaces})
|
|
627 retstring = self.getHistoricalPlacesFromProjectAsHTML(projectID)
|
|
628 logging.debug(retstring)
|
|
629 return retstring
|
|
630
|
2
|
631 security.declareProtected('View management screens','removeObjectFromProject')
|
0
|
632 def removeObjectFromProject(self,projectID,value):
|
|
633 """remove"""
|
|
634 logging.debug("remove:"+projectID+":"+value);
|
|
635
|
|
636 objects = self.getObjectsFromProject(projectID)
|
|
637 for object in objects.keys():
|
|
638
|
|
639 logging.debug("trying:"+repr(object[0])+"::"+repr(value)+"__")
|
|
640 if object[0]==value:
|
|
641 logging.debug("---removed!")
|
|
642 objects.remove(object)
|
|
643
|
|
644 self.projectObjects.update({projectID:objects})
|
|
645 retstring = self.getObjectsFromProjectAsHTML(projectID)
|
|
646 logging.debug(retstring)
|
|
647 return retstring
|
|
648
|
2
|
649 security.declareProtected('View management screens','removePersonFromProject')
|
0
|
650 def removePersonFromProject(self,projectID,value):
|
|
651 """remove"""
|
|
652 logging.debug("remove:"+projectID+":"+value);
|
|
653
|
|
654 persons = self.getPersonsFromProject(projectID)
|
|
655 for person in persons.keys():
|
|
656
|
|
657 logging.debug("trying:"+repr(person[0])+"::"+repr(value)+"__")
|
|
658 if person[0]==value:
|
|
659 logging.debug("---removed!")
|
|
660 persons.remove(person)
|
|
661
|
|
662 self.projectPersons.update({projectID:persons})
|
|
663 retstring = self.getPersonsFromProjectAsHTML(projectID)
|
|
664 logging.debug(retstring)
|
|
665 return retstring
|
|
666
|
|
667 #fuegt die neue Person zur personIDtoNames hinzu, für die spätere Anzeige in der Personenliste
|
|
668 def addNameTOPersonIDNames(self,personID,label):
|
|
669 personName = self.personIDtoNames.get(personID)
|
|
670 if personName==None: # Anlegen falls noch nicht existent
|
|
671 personName=(label,[])
|
|
672 else:
|
|
673 if (not label in personName[1]) and (not label==personName[0]): # hinzufuegen falls der neuen name noch nicht als bezeichnugn fuer personID eingetragen ist
|
|
674 personName[1].append(label)
|
|
675
|
|
676 self.personIDtoNames.update({personID:personName})
|
|
677
|
2
|
678 security.declareProtected('View management screens','addPersonToProject')
|
0
|
679 def addPersonToProject(self,projectID,value,label):
|
|
680 """ add a person so the project"""
|
|
681 persons=self.getPersonsFromProject(projectID);
|
|
682
|
|
683 logging.debug("adding:"+projectID+":"+value+":"+label);
|
|
684
|
|
685 persons.insert([value,label])
|
|
686 self.projectPersons.update({projectID:persons})
|
|
687
|
|
688 for personTuple in persons:
|
|
689 #hole die abgespeicherten Projekte zu einer Person
|
|
690 person=personTuple[0] #hole die ID
|
|
691
|
|
692
|
|
693 if getattr(self,"persons2Projects",None)==None:
|
|
694 setattr(self,"persons2Projects",OOBTree())
|
|
695
|
|
696 projects = self.persons2Projects.get(person,None)
|
|
697
|
|
698 if projects==None:
|
|
699 projects=OOSet();
|
|
700
|
|
701 projects.insert(projectID )
|
|
702 logging.debug("update:"+person)
|
|
703 self.persons2Projects.update({person:projects})
|
|
704
|
|
705 self.addNameTOPersonIDNames(value,label)
|
|
706 retstring = self.getPersonsFromProjectAsHTML(projectID)
|
|
707 logging.debug(retstring)
|
|
708 transaction.commit()
|
|
709 return retstring
|
|
710
|
2
|
711
|
0
|
712 def getPersonsWithProjectIDs(self):
|
|
713 """holt die getaggted Personen mit Projekten"""
|
|
714 persons = self.persons2Projects;
|
|
715 ret={}
|
4
|
716
|
0
|
717 logging.debug("Check Person:"+repr(persons.keys()))
|
4
|
718 personsList=[x for x in persons.keys()]
|
|
719
|
|
720 def sort(x,y):
|
|
721 sortNrx=self.personsIDForSort.index(x)
|
|
722 sortNry=self.personsIDForSort.index(y)
|
|
723 #logging.debug("INSORT***")
|
|
724 #logging.debug((sortNrx,sortNry))
|
|
725 return cmp(sortNrx,sortNry)
|
|
726
|
|
727 logging.debug("SORT***")
|
|
728 logging.debug(self.personsIDForSort)
|
|
729 logging.debug("SORT.list")
|
|
730 logging.debug(personsList)
|
|
731 personsList.sort(cmp=sort)
|
|
732 #for person in persons.keys():
|
|
733 logging.debug("AFTERSORT***")
|
|
734 logging.debug(personsList)
|
|
735 for person in personsList:
|
0
|
736 logging.debug("Check:"+person)
|
4
|
737 #TODO: person muss duch den namen von provider geholt werden
|
0
|
738 list=[]
|
|
739 for projectID in persons.get(person):
|
|
740 list.append(self.getProjectDetails(projectID))
|
|
741
|
|
742 ret[person]=list[0:]
|
4
|
743
|
|
744 logging.debug("AFTERSORT-ret***")
|
|
745 logging.debug(ret.keys())
|
|
746 return ret,personsList
|
0
|
747
|
|
748 def getHistoricalPlacesWithProjectIDs(self):
|
|
749 """holt die getaggted Personen mit Projekten"""
|
|
750 HistoricalPlaces = self.HistoricalPlaces2Projects;
|
|
751 ret={}
|
|
752 logging.debug("Check HistoricalPlace:"+repr(HistoricalPlaces.keys()))
|
|
753 for HistoricalPlace in HistoricalPlaces.keys():
|
|
754 logging.debug("Check:"+HistoricalPlace)
|
|
755 #TODO: HistoricalPlace muss duch den namen von provuder geholt werden
|
|
756 list=[]
|
|
757 for projectID in HistoricalPlaces.get(HistoricalPlace):
|
|
758 list.append(self.getProjectDetails(projectID))
|
|
759
|
|
760 ret[HistoricalPlace]=list[0:]
|
|
761 return ret
|
|
762
|
|
763 def getObjectsWithProjectIDs(self):
|
|
764 """holt die getaggted Personen mit Projekten"""
|
|
765 objects = self.objects2Projects;
|
|
766 ret={}
|
|
767 logging.debug("Check Object:"+repr(objects.keys()))
|
|
768 for object in objects.keys():
|
|
769 logging.debug("Check:"+object)
|
|
770 #TODO: object muss duch den namen von provuder geholt werden
|
|
771 list=[]
|
|
772 for projectID in objects.get(object):
|
|
773 list.append(self.getProjectDetails(projectID))
|
|
774
|
|
775 ret[object]=list[0:]
|
|
776 return ret
|
|
777
|
2
|
778 security.declareProtected('View management screens','listAllSuggestedTags')
|
0
|
779 def listAllSuggestedTags(self):
|
|
780 """list all tags"""
|
|
781 ret="<html><body>"
|
|
782 for projectID in self.projectSuggestedTags:
|
|
783 ret+="<h3>"+projectID+"</h3><table>"
|
|
784 for tags in self.projectSuggestedTags.get(projectID):
|
|
785 ret+="<tr><td>"+tags[0]+"</td><td>"+tags[1].type+"</td><td>"+tags[1].comment+"</td><td>"+tags[1].userName+"</td></tr>"
|
|
786 ret+="</table>"
|
|
787 ret+="</body></html>"
|
|
788 logging.debug(ret);
|
|
789 return ret
|
2
|
790
|
|
791 security.declareProtected('View management screens','suggestTag')
|
0
|
792 def suggestTag(self,projectID,tagName,tagComment,tagType,tagUserName):
|
|
793 """suggest a new tag"""
|
|
794 """ add a person so the project"""
|
|
795 SuggestedTags=self.getSuggestedTagsFromProject(projectID);
|
|
796
|
|
797 logging.debug("suggested:"+projectID+":"+tagName);
|
|
798
|
|
799
|
|
800 #TODO: Im moment noch keine Zuordnung zu einer ID.
|
|
801 newTag = SuggestedTag(tagName,tagComment,tagType,tagUserName)
|
|
802 SuggestedTags.insert([tagName,newTag])
|
|
803 self.projectSuggestedTags.update({projectID:SuggestedTags})
|
|
804
|
|
805
|
|
806
|
|
807 for SuggestedTagTuple in SuggestedTags:
|
|
808 #hole die abgespeicherten Projekte zu einer Person
|
|
809 person=SuggestedTagTuple[0] #hile die ID
|
|
810
|
|
811
|
|
812 if getattr(self,"SuggestedTags2Projects",None)==None:
|
|
813 setattr(self,"SuggestedTags2Projects",OOBTree())
|
|
814
|
|
815 projects = self.SuggestedTags2Projects.get(person,None)
|
|
816
|
|
817 if projects==None:
|
|
818 projects=OOSet();
|
|
819
|
|
820 projects.insert(projectID )
|
|
821 logging.debug("update:"+person)
|
|
822 self.SuggestedTags2Projects.update({person:projects})
|
|
823
|
|
824
|
|
825
|
|
826 #retstring = self.getSuggestedTagsFromProjectAsHTML(projectID)
|
|
827 #logging.debug(retstring)
|
|
828
|
|
829
|
|
830
|
|
831 #return retstring
|
|
832
|
2
|
833 security.declareProtected('View management screens','addHistoricalPlaceToProject')
|
0
|
834 def addHistoricalPlaceToProject(self,projectID,value):
|
|
835 """ add a person so the project"""
|
|
836 HistoricalPlaces=self.getHistoricalPlacesFromProject(projectID);
|
|
837
|
|
838 logging.debug("adding:"+projectID+":"+value);
|
|
839
|
|
840
|
|
841 #TODO: Im moment noch keine Zuordnung zu einer ID.
|
|
842 HistoricalPlaces.insert([value,value])
|
|
843 self.projectHistoricalPlaces.update({projectID:HistoricalPlaces})
|
|
844
|
|
845
|
|
846
|
|
847 for HistoricalPlaceTuple in HistoricalPlaces:
|
|
848 #hole die abgespeicherten Projekte zu einer Person
|
|
849 person=HistoricalPlaceTuple[0] #hile die ID
|
|
850
|
|
851
|
|
852 if getattr(self,"HistoricalPlaces2Projects",None)==None:
|
|
853 setattr(self,"HistoricalPlaces2Projects",OOBTree())
|
|
854
|
|
855 projects = self.HistoricalPlaces2Projects.get(person,None)
|
|
856
|
|
857 if projects==None:
|
|
858 projects=OOSet();
|
|
859
|
|
860 projects.insert(projectID )
|
|
861 logging.debug("update:"+person)
|
|
862 self.HistoricalPlaces2Projects.update({person:projects})
|
|
863
|
|
864
|
|
865
|
|
866 retstring = self.getHistoricalPlacesFromProjectAsHTML(projectID)
|
|
867 logging.debug(retstring)
|
|
868
|
|
869
|
|
870
|
|
871 return retstring
|
|
872
|
2
|
873 security.declareProtected('View management screens','addObjectToProject')
|
0
|
874 def addObjectToProject(self,projectID,value):
|
|
875 """ add a person so the project"""
|
|
876 objects=self.getObjectsFromProject(projectID);
|
|
877
|
|
878 logging.debug("adding:"+projectID+":"+value);
|
|
879
|
|
880
|
|
881 #TODO: Im moment noch keine Zuordnung zu einer ID.
|
|
882 objects.insert([value,value])
|
|
883 self.projectObjects.update({projectID:objects})
|
|
884
|
|
885
|
|
886
|
|
887 for objectTuple in objects:
|
|
888 #hole die abgespeicherten Projekte zu einer Person
|
|
889 person=objectTuple[0] #hile die ID
|
|
890
|
|
891
|
|
892 if getattr(self,"objects2Projects",None)==None:
|
|
893 setattr(self,"objects2Projects",OOBTree())
|
|
894
|
|
895 projects = self.objects2Projects.get(person,None)
|
|
896
|
|
897 if projects==None:
|
|
898 projects=OOSet();
|
|
899
|
|
900 projects.insert(projectID )
|
|
901 logging.debug("update:"+person)
|
|
902 self.objects2Projects.update({person:projects})
|
|
903
|
|
904
|
|
905
|
|
906 retstring = self.getObjectsFromProjectAsHTML(projectID)
|
|
907 logging.debug(retstring)
|
|
908
|
|
909
|
|
910
|
|
911 return retstring
|
|
912
|
|
913
|
|
914 def getProjectsWithTag(self,tagType,tagName):
|
|
915 tags = getattr(self,"tags",None)
|
|
916 if tags is None:
|
|
917 logging.debug("can't find Tags")
|
|
918 return []
|
|
919
|
|
920
|
|
921
|
|
922 tagsStored=tags.get(tagType,None)
|
|
923 if tagsStored is None:
|
|
924 logging.debug("can't find Tag:"+tagType)
|
|
925 return []
|
|
926
|
|
927 projects = tagsStored.get(tagName,None)
|
|
928 if projects is None:
|
|
929 logging.debug("can't find any projects for Tag:"+tagName+"("+tagType+")")
|
|
930 return []
|
|
931
|
|
932 ret=[]
|
|
933 for project in projects:
|
|
934 logging.debug("found:"+project)
|
|
935 ret.append(self.getProjectDetails(project))
|
|
936
|
|
937 return ret
|
|
938
|
|
939 def getProjectDetails(self,getID):
|
|
940 project=getattr(self.www_neu.projects,getID,None)
|
|
941 if project is None:
|
|
942 logging.debug("no project!! " +getID)
|
|
943 return
|
|
944
|
|
945 link="/en/research/projects/"+getID
|
|
946
|
|
947 title=project.getContent("short_title")
|
|
948 #persons=project.getPersonKeyList()
|
|
949 persons=project.getContent('xdata_01')
|
|
950 logging.debug("%s %s %s"%(link,title,persons))
|
|
951 return link,title,persons
|
|
952
|
|
953 # $.post("addNewPerson",{"projectID":
|
|
954 # $('#projectID').val(),
|
|
955 # "personName":$("#suggest_newPerson").val(),
|
|
956 # "personComment":$("#suggest_newPerson_comment").val()}
|
|
957 #
|
|
958 # );
|
|
959 #
|
2
|
960
|
|
961 security.declareProtected('View management screens','addAndCreateNewPerson')
|
0
|
962 def addAndCreateNewPerson(self,projectID,personName,personComment,personUserName):
|
|
963 """adds anew person to the project which is not in the authority file"""
|
|
964
|
|
965 id = random.randint(0, 1000000);
|
|
966 idstring="http://ontologies.mpiwg-berlin.mpg.de/tempObjects/person/"+str(id)
|
|
967 while self.suggestedPersons.has_key(idstring):
|
|
968 id = random.randint(0, 1000000);
|
|
969 #idstring="http://ontologies.mpiwg-berlin.mpg.de/tempObjects/person/"+str(id);
|
|
970 idstring=self.TEMP_PERSON_NS+str(id);
|
|
971
|
|
972
|
|
973 self.suggestedPersons.update({idstring:(personName,personComment,projectID,personUserName)})
|
|
974 self.createTempPersonInVirtuoso(projectID, idstring, personName, personComment) #TODO: add suername to the triplestore
|
|
975 return self.addPersonToProject(projectID, idstring, personName);
|
2
|
976
|
|
977 security.declareProtected('View management screens','createTempPersonInVirtuoso')
|
0
|
978 def createTempPersonInVirtuoso(self,projectID,personURI, personName,personComment):
|
|
979 """add a new person to the triple store of tempory persons"""
|
|
980 triples=[];
|
|
981 personID="<"+personURI+">"
|
|
982 triples.append((personID,"<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>","<http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/Person>"))
|
|
983 triples.append((personID,"<http://erlangen-crm.org/110404/P3_has_note>",'"'+personComment+'"'))
|
|
984 triples.append((personID,"<http://xmlns.com/foaf/0.1/name>",'"'+personName+'"'))
|
|
985 triples.append((personID,"<http://ontologies.mpiwg-berlin.mpg.de/general/isMentionedOn>","<http://www.mpiwg-berlin.mpg.de/en/research/projects/"+projectID+">"))
|
|
986
|
|
987 cmdString ="insert in GRAPH <"+self.virtuosoGraph+"> {"
|
|
988 for triple in triples:
|
|
989 cmdString+=" ".join(triple)+"."
|
|
990
|
|
991 cmdString+="}"
|
|
992
|
|
993 auth_handler = urllib2.HTTPBasicAuthHandler()
|
|
994 auth_handler.add_password(realm='sparql',
|
|
995 uri=self.virtuosoServer+"/sparql",
|
|
996 user=self.virtuosoDAVUser,
|
|
997 passwd=self.virtuosoDAVPW)
|
|
998
|
|
999 opener = urllib2.build_opener(auth_handler)
|
|
1000 opener.addheaders = [('Content-Type','application/sparql-query')]
|
|
1001
|
|
1002 logging.debug(cmdString)
|
|
1003 try:
|
|
1004 r= opener.open(self.virtuosoServer+"/sparql", urllib.urlencode({'query':cmdString,'default-graph-uri':self.virtuosoGraph,'named-graph-uri':None}))
|
|
1005 logging.debug(r.read())
|
|
1006 except urllib2.URLError, e:
|
|
1007 logging.error(e.code)
|
|
1008 logging.error(e.read())
|
|
1009 return
|
|
1010
|
|
1011 opener2 = urllib2.build_opener()
|
|
1012
|
|
1013
|
|
1014 personIDencoded=urllib.quote(personURI,safe="")
|
|
1015 graphEncoded=urllib.quote(self.additionalNamesGraphURL,safe="")
|
|
1016 url = self.personproviderURL+"id/"+personIDencoded+"/"+graphEncoded
|
|
1017
|
|
1018 try:
|
|
1019 request = urllib2.Request(url);
|
|
1020 request.get_method = lambda : 'PUT'
|
|
1021 r= opener2.open(request);
|
|
1022 logging.debug(r.read())
|
|
1023 except urllib2.URLError, e:
|
|
1024 logging.error(e.code)
|
|
1025 logging.error(e.read())
|
|
1026 return
|
|
1027
|
|
1028
|
|
1029
|
|
1030 return
|
|
1031
|
|
1032 def redirect(RESPONSE,url):
|
|
1033 """mache ein redirect mit einem angehaengten time stamp um ein reload zu erzwingen"""
|
|
1034
|
|
1035 timeStamp=time.time()
|
|
1036
|
|
1037 if url.find("?")>-1: #giebt es schon parameter
|
|
1038 addStr="&time=%s"
|
|
1039 else:
|
|
1040 addStr="?time=%s"
|
|
1041
|
|
1042 RESPONSE.setHeader('Last-Modified',email.Utils.formatdate().split("-")[0]+'GMT')
|
|
1043 logging.error(email.Utils.formatdate()+' GMT')
|
|
1044 RESPONSE.redirect(url+addStr%timeStamp)
|
|
1045
|
|
1046 def manage_addMPIWGThesaurusForm(self):
|
|
1047 """form for adding the project"""
|
|
1048 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMPIWGThesaurusForm.zpt')).__of__(self)
|
|
1049 return pt()
|
|
1050
|
|
1051
|
|
1052
|
|
1053 def manage_addMPIWGThesaurus(self,id,RESPONSE=None):
|
|
1054 """add it"""
|
|
1055 newObj=MPIWGThesaurus(id)
|
|
1056
|
|
1057 self._setObject(id,newObj)
|
|
1058
|
|
1059
|
|
1060 if RESPONSE is not None:
|
|
1061 redirect(RESPONSE,'manage_main') |