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/"
|
7
|
65 personproviderURL="http://127.0.0.1:8280/MetaDataManagerRestlet/person/"
|
|
66 #personproviderURL="http://virtuoso.mpiwg-berlin.mpg.de:8080/MetaDataManagerRestlet/person/"
|
|
67 #PERSONS_LOOKUP_URL="http://127.0.0.1:8280/MetaDataManagerRestlet/search/persons"
|
|
68 PERSONS_LOOKUP_URL="http://127.0.0.1:8280/MetaDataManagerRestlet/persons"
|
8
|
69 EDIT_URL="http://127.0.0.1:8280/MetaDataManagerRestlet/edit?id="
|
|
70 #PERSONS_LOOKUP_URL="http://virtuoso.mpiwg-berlin.mpg.de:8080/MetaDataManagerRestlet/person/"
|
7
|
71
|
0
|
72 additionalNamesGraphURL="file://newpersonsFromProjects"
|
|
73
|
|
74 #virtuosoServer="http://ontologies.mpiwg-berlin.mpg.de"
|
|
75 virtuosoServer="http://virtuoso.mpiwg-berlin.mpg.de:8890"
|
|
76 virtuosoDAV="/DAV/home/websiteuser/"
|
|
77 virtuosoDAVUser="websiteuser"
|
|
78 virtuosoDAVPW="w3s45us3"
|
|
79 virtuosoGraph="file://newpersonsFromProjects"
|
|
80
|
1
|
81 #BTrees fuer die Tags
|
|
82
|
7
|
83 projectPersons= OOBTree() #project --> personen IDs
|
0
|
84 projectObjects= OOBTree()
|
|
85 projectHistoricalPlaces= OOBTree()
|
|
86 projectSuggestedTags= OOBTree()
|
7
|
87 persons2Projects= OOBTree() #personenID --> projects
|
3
|
88 objects2Projects=OOBTree()
|
0
|
89 historicalPlaces2Projects=OOBTree()
|
|
90 suggestedTags2Projects=OOBTree()
|
4
|
91 personIDtoNames=OOBTree() # weist den personenIDs Klartextnamen aus dem Triplestore zu
|
5
|
92 personsIDForSort=[] # liste personenID sortiert nach dem tupel (nachname,vorname)
|
|
93 personsIDForSortFull=[] # liste (personenID,(nachname,vorname)) nicht sortiert!
|
|
94
|
0
|
95 suggestedPersons= OOBTree(); #TODO: das sollte die ueberfluessig werde und nur im triple store stehen.
|
|
96
|
|
97 tagList=[]
|
1
|
98
|
|
99 #default liste fuer tags, wird ueber das Managementinterface ueberschrieben
|
0
|
100 approachesTxt="""A
|
|
101 ---
|
|
102 ent1
|
|
103 ---
|
|
104 B
|
|
105 ---
|
|
106 enta
|
|
107 entb
|
|
108 entc
|
|
109 """
|
|
110
|
|
111 disciplines=[]
|
|
112 disciplinesTxt="""A
|
|
113 B
|
|
114 C
|
|
115 """
|
|
116
|
|
117 periods=[]
|
|
118 periodsTxt="""PA
|
|
119 PB
|
|
120 PC
|
|
121 """
|
|
122
|
|
123 spaces=[]
|
|
124 spacesTxt="""SPA
|
|
125 ---
|
|
126 sPent1
|
|
127 ---
|
|
128 SPB
|
|
129 ---
|
|
130 SPenta
|
|
131 SPentb
|
|
132 SPentc
|
|
133 """
|
|
134 technologies=[]
|
|
135 technologiesTxt="""TPA
|
|
136 ---
|
|
137 TPent1
|
|
138 ---
|
|
139 TPB
|
|
140 ---
|
|
141 TPenta
|
|
142 TPentb
|
|
143 TPentc
|
|
144 """
|
|
145
|
|
146 knowledgeTransfers=[]
|
|
147 knowledgeTransfersTxt="""KTPA
|
|
148 ---
|
|
149 TPent1
|
|
150 ---
|
|
151 TPB
|
|
152 ---
|
|
153 TPenta
|
|
154 TPentb
|
|
155 TPentc
|
|
156 """
|
|
157
|
|
158
|
|
159
|
|
160
|
|
161
|
|
162
|
|
163 manage_options = Folder.manage_options+(
|
1
|
164 {'label':'Thesaurus entries','action':'changeMPIWGThesaurusForm'},
|
|
165 {'label':'Manage Thesaurus','action':'manageMPIWGThesaurus'},
|
0
|
166 #{'label':'Change Publications Special','action':'changePublications_specialForm'},
|
|
167 )
|
|
168
|
|
169 def __init__(self,id):
|
|
170 """init"""
|
|
171 self.id=id
|
|
172
|
|
173
|
|
174 def index_html(self):
|
|
175 """index file"""
|
1
|
176
|
0
|
177 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','index.html')).__of__(self)
|
|
178 return pt()
|
|
179
|
2
|
180 security.declareProtected('View management screens','changeMPIWGThesaurusForm')
|
0
|
181 def changeMPIWGThesaurusForm(self):
|
|
182 """form for changing the project"""
|
|
183 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeMPIWGThesaurusForm.zpt')).__of__(self)
|
|
184 return pt()
|
|
185
|
2
|
186 security.declareProtected('View management screens','manageMPIWGThesaurus')
|
1
|
187 def manageMPIWGThesaurus(self):
|
|
188 """form for changing the project"""
|
|
189 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','manageMPIWGThesaurus.zpt')).__of__(self)
|
|
190 return pt()
|
|
191
|
2
|
192 security.declareProtected('View management screens','changeMPIWGThesaurus')
|
0
|
193 def changeMPIWGThesaurus(self,approachesTxt,disciplinesTxt,periodsTxt,spacesTxt,technologiesTxt,knowledgeTransfersTxt,RESPONSE=None):
|
|
194 """change it"""
|
|
195 self.approachesTxt=approachesTxt
|
|
196 self.disciplinesTxt=disciplinesTxt
|
|
197 self.periodsTxt=periodsTxt
|
|
198 self.spacesTxt=spacesTxt
|
|
199 self.technologiesTxt=technologiesTxt
|
|
200 self.knowledgeTransfersTxt=knowledgeTransfersTxt
|
|
201
|
|
202 if RESPONSE is not None:
|
|
203 redirect(RESPONSE,'manage_main')
|
|
204
|
|
205 #In der Anzeige soll der Name der zitierten Personen in Klartext angezeigt werden, ausserdem die Varianten, wie sie tatsaechlich
|
|
206 #in den Projekten benutzt werden
|
2
|
207
|
5
|
208
|
|
209 def addPersonAndFirstNameFromTripleStore(self, personID):
|
|
210 mainName, sortName = self.getMainNameFromTripleStore(personID) # hole die hauptbezeichnung aus dem triplestore
|
|
211 personNames = []
|
7
|
212 logging.debug("get person:"+ personID)
|
|
213 logging.debug("names:"+repr(mainName)+":"+ repr(sortName))
|
|
214
|
|
215 projects=self.persons2Projects.get(personID)
|
|
216 logging.debug(repr(projects))
|
|
217 if projects is None:
|
|
218 projects=[]
|
|
219
|
|
220 for project in projects: #hole die personen aus dem projekte
|
5
|
221 logging.debug("Found:project:" + project)
|
|
222 namesInProject = self.projectPersons.get(project)
|
|
223 for nameInProjectTuple in namesInProject:
|
|
224 logging.debug(repr(nameInProjectTuple))
|
|
225 nameInProject = nameInProjectTuple[1]
|
|
226 logging.debug(nameInProjectTuple[0] + "??" + personID)
|
|
227 if nameInProjectTuple[0] == personID:
|
|
228 logging.debug("changing")
|
|
229 if mainName == "": # es gibt keinen Eintrag im Triplestore fuer name (sollte eigentlich nicht sein, ist dann ein Fehler dort)
|
|
230 mainName = nameInProject #nimm dann aber den ersten aus den projekten
|
|
231 if nameInProject != mainName:
|
|
232 personNames.append(nameInProject)
|
|
233
|
|
234 logging.debug(str(mainName) + "- foundalso :" + ",".join(personNames))
|
|
235 self.personIDtoNames.update({personID:(mainName, personNames)})
|
|
236 self.personsIDForSortFull.append((personID, sortName))
|
|
237
|
|
238
|
|
239
|
|
240 def generateSortingOrderForPersonIDs(self):
|
|
241 def sort(x,y):
|
|
242 logging.debug("sort:")
|
|
243 logging.debug((x[1][0],y[1][0]))
|
|
244 return cmp(x[1][0],y[1][0])
|
|
245
|
|
246 self.personsIDForSortFull.sort(cmp=sort)
|
|
247
|
|
248 self.personsIDForSort=[x[0] for x in self.personsIDForSortFull]
|
|
249
|
|
250 self.personIDtoNames=self.personIDtoNames # make clear that it has changed #TODO: change this to variablen with names _p
|
|
251
|
4
|
252 security.declareProtected('View management screens','collectPersonNamesToIds')
|
0
|
253 def collectPersonNamesToIds(self):
|
1
|
254 """Ordne Namen aus dem Triplestore bzw. die vergebenenden Label den Personen-Ids zu."""
|
5
|
255 #sollte z.B. gemacht werden, wenn im Triplestore editiert wurde.
|
4
|
256 self.personIDtoNames=OOBTree() # loesche alle
|
|
257 self.personsIDForSort=[]
|
5
|
258 self.personsIDForSortFull=[]
|
0
|
259 for personID in self.persons2Projects:
|
6
|
260 self.addPersonAndFirstNameFromTripleStore(personID)
|
4
|
261
|
|
262
|
|
263
|
|
264
|
|
265 #sortiere personIDs nach erstmal nach Nachnamene TODO: sortiere nach name,vorname
|
5
|
266
|
|
267 self.generateSortingOrderForPersonIDs();
|
|
268 # def sort(x,y):
|
|
269 # logging.debug("sort:")
|
|
270 # logging.debug((x[1][0],y[1][0]))
|
|
271 # return cmp(x[1][0],y[1][0])
|
|
272 #
|
|
273 # self.personsIDForSortFull.sort(cmp=sort)
|
|
274 #
|
|
275 # self.personsIDForSort=[x[0] for x in self.personsIDForSortFull]
|
|
276 #
|
|
277 # self.personIDtoNames=self.personIDtoNames # make clear that it has changed #TODO: change this to variablen with names _p
|
|
278 #
|
1
|
279 #Hole die Namen, die einer personID zugeordnet sind.
|
0
|
280 def getNamesFromID(self,personID):
|
7
|
281 personID=personID.rstrip().lstrip() #make sure no spaces
|
|
282 logging.debug("<"+personID+">")
|
0
|
283 retStr=""
|
7
|
284
|
|
285 retStr+=self.personIDtoNames.get(personID,[personID])[0] # hole die Hauptbezeichnung, falls keine angeben ist, wird die ID ausgegeben, das is jedoch ein Felher in den Daten!!
|
8
|
286 #additionalNames = self.personIDtoNames.get(personID,['',[]])[1]
|
|
287 #if len(additionalNames)>0:
|
|
288 # retStr+=" ("+",".join(additionalNames)+","+")"
|
0
|
289 return retStr
|
|
290
|
|
291
|
1
|
292 #Hole die Hauptnamemsansetzung aus dem Triplestore ),falls vorhanden, wenn nicht ist der String leer.
|
4
|
293 #ausserdem einen Namen zum sortieren, = Tupel(nachname, vorname)
|
0
|
294 def getMainNameFromTripleStore(self,personID):
|
|
295
|
|
296
|
|
297 cmdString ="""select * where { <%s> <http://xmlns.com/foaf/0.1/name> ?name}"""%personID
|
|
298
|
4
|
299 names= self.callSparql(cmdString)
|
|
300
|
|
301 cmdString ="""select * where { <%s> <http://xmlns.com/foaf/0.1/lastName> ?name}"""%personID
|
|
302
|
|
303 lastName= self.callSparql(cmdString)
|
|
304
|
|
305 cmdString ="""select * where { <%s> <http://xmlns.com/foaf/0.1/firstName> ?name}"""%personID
|
|
306
|
|
307 firstName= self.callSparql(cmdString)
|
|
308
|
|
309 return names,(lastName,firstName)
|
|
310
|
|
311
|
7
|
312 def callSparqlAll(self,cmdString):
|
|
313 """list of results"""
|
|
314 auth_handler = urllib2.HTTPBasicAuthHandler()
|
|
315 auth_handler.add_password(realm='sparql',
|
|
316 uri=self.virtuosoServer+"/sparql",
|
|
317 user=self.virtuosoDAVUser,
|
|
318 passwd=self.virtuosoDAVPW)
|
|
319
|
|
320 opener = urllib2.build_opener(auth_handler)
|
|
321 opener.addheaders = [('Content-Type','application/sparql-query')]
|
|
322
|
|
323 logging.debug(cmdString)
|
|
324 try:
|
|
325 logging.debug(self.virtuosoServer+"/sparql?" + urllib.urlencode({'query':cmdString,'default-graph-uri':self.virtuosoGraph,'named-graph-uri':'','format':'text/csv'}))
|
|
326 #r= opener.open(self.virtuosoServer+"/sparql", urllib.urlencode({'query':cmdString,'default-graph-uri':self.virtuosoGraph,'named-graph-uri':'','format':'text/csv'}))
|
|
327 r= opener.open(self.virtuosoServer+"/sparql", urllib.urlencode({'query':cmdString,'default-graph-uri':'','named-graph-uri':'','format':'text/csv'}))
|
|
328 namesTxt=r.read()
|
|
329 except urllib2.URLError, e:
|
|
330 logging.error(e.code)
|
|
331 logging.error(e.read())
|
|
332
|
|
333
|
|
334 return
|
|
335 logging.debug(namesTxt)
|
|
336 names=namesTxt.split("\n")
|
|
337 if len(names) < 2: #in der ersten Zeile stehen bei der Rückgabe die Spaltennamen, <2 heiss also es gibt keinen Eintrag
|
|
338 return []
|
|
339
|
|
340 ret=[]
|
|
341 for name in names[1:]:
|
|
342 line=[]
|
|
343 for entry in name.split("\",\""):
|
|
344
|
|
345 line.append(entry.replace('"',''));
|
|
346 ret.append(line);
|
|
347 return ret;
|
|
348
|
4
|
349 def callSparql(self,cmdString):
|
0
|
350
|
|
351 auth_handler = urllib2.HTTPBasicAuthHandler()
|
|
352 auth_handler.add_password(realm='sparql',
|
|
353 uri=self.virtuosoServer+"/sparql",
|
|
354 user=self.virtuosoDAVUser,
|
|
355 passwd=self.virtuosoDAVPW)
|
|
356
|
|
357 opener = urllib2.build_opener(auth_handler)
|
|
358 opener.addheaders = [('Content-Type','application/sparql-query')]
|
|
359
|
|
360 logging.debug(cmdString)
|
|
361 try:
|
4
|
362 logging.debug(self.virtuosoServer+"/sparql?" + urllib.urlencode({'query':cmdString,'default-graph-uri':self.virtuosoGraph,'named-graph-uri':'','format':'text/csv'}))
|
|
363 #r= opener.open(self.virtuosoServer+"/sparql", urllib.urlencode({'query':cmdString,'default-graph-uri':self.virtuosoGraph,'named-graph-uri':'','format':'text/csv'}))
|
|
364 r= opener.open(self.virtuosoServer+"/sparql", urllib.urlencode({'query':cmdString,'default-graph-uri':'','named-graph-uri':'','format':'text/csv'}))
|
0
|
365 namesTxt=r.read()
|
|
366 except urllib2.URLError, e:
|
|
367 logging.error(e.code)
|
|
368 logging.error(e.read())
|
4
|
369
|
|
370
|
0
|
371 return
|
4
|
372 logging.debug(namesTxt)
|
0
|
373 names=namesTxt.split("\n")
|
|
374 if len(names) < 2: #in der ersten Zeile stehen bei der Rückgabe die Spaltennamen, <2 heiss also es gibt keinen Eintrag
|
|
375 return
|
|
376
|
|
377 return names[1].replace('"','') # wir nehmen nur den ersten treffer
|
|
378
|
|
379
|
2
|
380 security.declareProtected('View management screens','changeTags')
|
0
|
381 def changeTags(self,projectID,approaches=[],disciplines=[],periods=[],spaces=[],technologies=[],transfers=[],RESPONSE=None):
|
|
382 """change tags"""
|
|
383 self.changeTagFromList(projectID,"approaches", approaches)
|
|
384 self.changeTagFromList(projectID,"disciplines", disciplines)
|
|
385 self.changeTagFromList(projectID,"periods", periods)
|
|
386 self.changeTagFromList(projectID,"spaces", spaces)
|
|
387 self.changeTagFromList(projectID,"technologies", technologies)
|
|
388 self.changeTagFromList(projectID,"transfers", transfers)
|
|
389
|
|
390 self.projectObjects=self.projectObjects #necessesary to make the object persistent after the first call
|
|
391 self.projectHistoricalPlaces=self.projectHistoricalPlaces #necessesary to make the object persistent after the first call
|
|
392 self.projectPersons=self.projectPersons #necessesary to make the object persistent after the first call
|
|
393 self.projectSuggestedTags=self.projectSuggestedTags
|
|
394
|
|
395 self.persons2Projects=self.persons2Projects
|
3
|
396 self.objects2Projects=self.objects2Projects
|
0
|
397 self.historicalPlaces2Projects=self.historicalPlaces2Projects
|
|
398 self.suggestedTags2Projects=self.suggestedTags2Projects;
|
|
399
|
|
400 self.suggestedPersons=self.suggestedPersons;
|
|
401
|
2
|
402 security.declareProtected('View management screens','deleteAllTags')
|
0
|
403 def deleteAllTags(self):
|
|
404 """deleteAllTags - TODO: take this out!!,"""
|
|
405 setattr(self,"tags",None)
|
|
406
|
|
407 return "DONE!"
|
|
408
|
2
|
409 security.declareProtected('View management screens','deleteAllPersons')
|
0
|
410 def deleteAllPersons(self):
|
|
411 """deleteAllTags - TODO: take this out!!,"""
|
|
412 self.projectPersons= OOBTree()
|
|
413 self.persons2Projects= OOBTree()
|
|
414 self.personIDtoNames=OOBTree()
|
|
415 self.suggestedPersons= OOBTree(); #TODO: das sollte die ueberfluessig werde und nur im triple store stehen.
|
|
416
|
|
417
|
|
418 return "DONE!"
|
2
|
419
|
3
|
420 security.declareProtected('View management screens','deleteAllObjects')
|
|
421 def deleteAllObjects(self):
|
|
422 """deleteAllTags - TODO: take this out!!,"""
|
|
423 logging.debug("delete all objects")
|
|
424 self.projectObjects= OOBTree()
|
|
425 self.objects2Projects=OOBTree()
|
|
426
|
|
427
|
|
428 return "DONE!"
|
|
429
|
0
|
430 def changeTagFromList(self,projectID,tagType,tagList):
|
|
431
|
|
432 logging.debug("changing:"+projectID)
|
|
433 logging.debug("asking tag::"+tagType)
|
|
434 if type(tagList) is not ListType:
|
|
435 tagList=[tagList]
|
|
436
|
|
437
|
|
438 tags = getattr(self,"tags",None)
|
|
439 if tags is None:
|
|
440 logging.debug("Create new tags")
|
|
441 tags=OOBTree()
|
|
442 setattr(self,"tags",tags)
|
|
443
|
|
444
|
|
445 tagsStored=tags.get(tagType,None)
|
|
446 if tagsStored is None:
|
|
447 tagsStored=OOBTree();
|
|
448
|
|
449
|
|
450
|
|
451 for tag in tagsStored.keys(): #gehe durch alle gespeichteren tags
|
|
452 logging.debug("checking:"+tag)
|
|
453 currentApproach = tagsStored.get(tag,None)
|
|
454 logging.debug(currentApproach)
|
|
455 if currentApproach is None:
|
|
456 currentApproach=OOSet()
|
|
457
|
|
458 if tag in tagList: #dieser ist getagged
|
|
459 currentApproach.update([projectID]);
|
|
460 tagList.remove(tag);
|
|
461 else:
|
|
462 if currentApproach.has_key(projectID):
|
|
463 currentApproach.remove(projectID);
|
|
464
|
|
465 tagsStored.update({tag:currentApproach});
|
|
466
|
|
467 for tag in tagList: # alle die nich nicht abearbeitet worden muessen noch angelegt werden
|
|
468 logging.debug("adding:"+tag)
|
|
469 newApproach=OOSet()
|
|
470 newApproach.update([projectID]);
|
|
471 tagsStored.insert(tag, newApproach);
|
|
472
|
|
473 tags.update({tagType:tagsStored})
|
|
474
|
|
475 transaction.commit()
|
|
476
|
|
477 def getTitle(self,entry):
|
|
478 return entry.title
|
|
479
|
|
480 def getEntries(self,entry):
|
|
481 return entry.entries
|
|
482
|
1
|
483 #nimmt ein eine Text der Form
|
|
484 # TAG1
|
|
485 # ---
|
|
486 # SUBTAG1_1
|
|
487 # SUBTAG1_2
|
|
488 # ---
|
|
489 # TAG2
|
|
490 # ---
|
|
491 # SUBTAG2_1
|
|
492 # SUBTAG2_2
|
|
493 #....
|
|
494 # und erzeugt daraus eine entsprechende Liste von Entries
|
0
|
495 def getEntriesFromTxt(self,txt):
|
|
496 apps=[]
|
|
497 lines=txt.split("\n");
|
|
498 level=False
|
|
499 for line in lines:
|
|
500 line=line.rstrip().lstrip()
|
|
501 if line=="":
|
|
502 continue
|
|
503 if line=="---":
|
|
504
|
|
505 if level:
|
|
506 level=False
|
|
507 else:
|
|
508 level=True
|
|
509 else:
|
|
510 if not level:
|
|
511 entry=Entry(line,[])
|
|
512 apps.append(entry)
|
|
513 else:
|
|
514 entry.entries.append(Entry(line))
|
|
515
|
|
516 return apps[0:]
|
|
517
|
|
518 def getApproaches(self):
|
|
519
|
|
520 self.tagList=self.getEntriesFromTxt(self.approachesTxt)
|
|
521 return self.tagList
|
|
522
|
2
|
523
|
0
|
524 def getTagsJSON(self,projectID,tagType,RESPONSE=None):
|
|
525 """get all selected tagList"""
|
|
526 logging.debug("asking:"+projectID)
|
|
527 logging.debug("asking tag::"+tagType)
|
|
528 retList=[]
|
|
529 tags = getattr(self,"tags",None)
|
|
530 if tags is None:
|
|
531 return;
|
|
532
|
|
533 tagsStored=tags.get(tagType,None)
|
|
534 if tagsStored is None:
|
|
535 return;
|
|
536
|
|
537 for tag in tagsStored.keys(): #gehe durch alle gespeichteren approached
|
|
538 logging.debug("checking:"+tag)
|
|
539 currentTag = tagsStored.get(tag,None)
|
|
540 if currentTag is None:
|
|
541 continue
|
|
542 if currentTag.has_key(projectID):
|
|
543 retList.append(""" "%s" """%tag)
|
|
544
|
|
545 if RESPONSE:
|
|
546 RESPONSE.setHeader('Content-Type', "application/json")
|
|
547
|
|
548 logging.debug(retList)
|
|
549 return "["+",".join(retList)+"]"
|
|
550
|
|
551 def getDisciplines(self):
|
|
552
|
|
553 self.disciplines=self.getEntriesFromTxt(self.disciplinesTxt)
|
|
554 return self.disciplines
|
|
555
|
|
556
|
|
557 def getObjectsJSON(self,term="",RESPONSE=None):
|
|
558 """ get all stored objects as json list starting with term"""
|
|
559 term=term.lower();
|
|
560 logging.debug("Asking:"+term)
|
|
561 #objectList=["baus","berg","lurg"]
|
|
562 objects = self.objects2Projects;
|
|
563
|
|
564 objectList= [x for x in objects.keys()]
|
|
565
|
|
566 logging.debug("Create:"+repr(objectList))
|
|
567 retList=[]
|
|
568 for object in objectList:
|
|
569 if object.find(term)>-1:
|
|
570 retList.append(""" "%s" """%object)
|
|
571 ret="["
|
|
572 ret+=",".join(retList)
|
|
573 ret+="]"
|
|
574 logging.debug("Objects:"+ret)
|
|
575 if RESPONSE:
|
|
576 RESPONSE.setHeader('Content-Type', "application/json")
|
|
577 return ret
|
|
578
|
|
579
|
|
580 def getHistoricalPlacesJSON(self,term="",RESPONSE=None):
|
|
581 """ get all stored historicalPlaces as json list starting with term"""
|
|
582 term=term.lower();
|
|
583 logging.debug("Asking:"+term)
|
|
584 #historicalPlaceList=["baus","berg","lurg"]
|
|
585 historicalPlaces = self.historicalPlaces2Projects;
|
|
586
|
|
587 historicalPlaceList= [x for x in historicalPlaces.keys()]
|
|
588
|
|
589 logging.debug("Create:"+repr(historicalPlaceList))
|
|
590 retList=[]
|
|
591 for historicalPlace in historicalPlaceList:
|
|
592 if historicalPlace.find(term)>-1:
|
|
593 retList.append(""" "%s" """%historicalPlace)
|
|
594 ret="["
|
|
595 ret+=",".join(retList)
|
|
596 ret+="]"
|
|
597 logging.debug("historicalPlaces:"+ret)
|
|
598 if RESPONSE:
|
|
599 RESPONSE.setHeader('Content-Type', "application/json")
|
|
600 return ret
|
|
601
|
|
602
|
|
603 def getPeriods(self):
|
|
604
|
|
605 self.periodes=self.getEntriesFromTxt(self.periodsTxt)
|
|
606 return self.periodes
|
|
607
|
|
608 def getSpaces(self):
|
|
609
|
|
610 self.spaces=self.getEntriesFromTxt(self.spacesTxt)
|
|
611 return self.spaces
|
|
612
|
|
613 def getTechnologies(self):
|
|
614
|
|
615 self.technologies=self.getEntriesFromTxt(self.technologiesTxt)
|
|
616 return self.technologies
|
|
617
|
|
618 def getKnowledgeTransfers(self):
|
|
619
|
|
620 self.knowledgeTransfers=self.getEntriesFromTxt(self.knowledgeTransfersTxt)
|
|
621 return self.knowledgeTransfers
|
|
622
|
|
623
|
|
624 def getObjectsFromProject(self,projectID):
|
|
625 return self.getFromProject(self.projectObjects,projectID);
|
|
626
|
|
627 def getHistoricalPlacesFromProject(self,projectID):
|
|
628 return self.getFromProject(self.projectHistoricalPlaces,projectID);
|
|
629
|
|
630 def getSuggestedTagsFromProject(self,projectID):
|
|
631 return self.getFromProject(self.projectSuggestedTags,projectID);
|
|
632
|
|
633
|
|
634 def getPersonsFromProject(self,projectID):
|
5
|
635 #hole alle personenID die zu einem Projekt gehoeren.
|
|
636 #zurueckgegeben wird ein OOSet()
|
0
|
637 return self.getFromProject(self.projectPersons,projectID);
|
|
638
|
5
|
639 def getFromProject(self,objects,projectID):
|
|
640 #holt die zu projectID gehoerigen objekte aus dem objects-set.
|
|
641 #oder legt einen neuen leeren Satz zu dieser ProjektID an.
|
|
642 #zuruecgegeben wird ein OOSet()
|
|
643 if objects.has_key(projectID): #wenn zu der ProjektID schon etwas abgespeichter ist, gieb es zurueck
|
0
|
644 logging.debug("key exists:"+projectID)
|
|
645 persons=objects.get(projectID);
|
5
|
646 else: # andernfalls lege einen neuen Satz an.
|
0
|
647 persons=OOSet()
|
|
648 objects.update({projectID:persons})
|
|
649 logging.debug("key does not exists:"+projectID)
|
|
650
|
|
651
|
|
652 return persons
|
|
653
|
|
654 def getHistoricalPlacesFromProjectAsHTML(self,projectID):
|
|
655 """gertobjects"""
|
|
656 return self.getFromProjectAsHTML(self.projectHistoricalPlaces, projectID, "HistoricalPlace");
|
|
657
|
|
658 def getObjectsFromProjectAsHTML(self,projectID):
|
|
659 """gertobjects"""
|
|
660 return self.getFromProjectAsHTML(self.projectObjects, projectID, "Object");
|
|
661
|
|
662 def getPersonsFromProjectAsHTML(self,projectID):
|
|
663 """getpersons"""
|
|
664 return self.getFromProjectAsHTML(self.projectPersons, projectID, "Person");
|
|
665
|
|
666
|
|
667 def getFromProjectAsHTML(self,objects,projectID,type):
|
|
668 """getpersons"""
|
|
669 ret=""
|
|
670 if objects.has_key(projectID):
|
|
671 persons=objects.get(projectID);
|
|
672 else:
|
|
673 persons=OOSet()
|
|
674
|
|
675
|
|
676 for person in persons:
|
|
677 ret+="""<div class="removeButton">
|
|
678 <span>%s </span><div style="display:inline" class="remove%s"><span style="display:none" class="removeValue">%s</span>remove</div>
|
|
679 </div>"""%(person[1],type,person[0])
|
|
680
|
|
681
|
|
682 # ret+="""<div>
|
|
683 # <input type="checkbox" name="persons_remove"
|
|
684 # value="%s">
|
|
685 # <span>%s</span>
|
|
686 # </div>"""%(person[0],person[1])
|
|
687 #
|
|
688 logging.debug(type+":"+ret)
|
|
689 return ret
|
|
690
|
2
|
691 security.declareProtected('View management screens','removeHistoricalPlaceFromProject')
|
0
|
692 def removeHistoricalPlaceFromProject(self,projectID,value):
|
|
693 """remove"""
|
|
694 logging.debug("removeHP:"+projectID+":"+value);
|
|
695
|
|
696 HistoricalPlaces = self.getHistoricalPlacesFromProject(projectID)
|
|
697 for HistoricalPlace in HistoricalPlaces.keys():
|
|
698
|
|
699 logging.debug("trying:"+repr(HistoricalPlace[0])+"::"+repr(value)+"__")
|
|
700 if HistoricalPlace[0]==value:
|
|
701 logging.debug("---removed!")
|
|
702 HistoricalPlaces.remove(HistoricalPlace)
|
|
703
|
|
704 self.projectHistoricalPlaces.update({projectID:HistoricalPlaces})
|
|
705 retstring = self.getHistoricalPlacesFromProjectAsHTML(projectID)
|
|
706 logging.debug(retstring)
|
|
707 return retstring
|
|
708
|
2
|
709 security.declareProtected('View management screens','removeObjectFromProject')
|
0
|
710 def removeObjectFromProject(self,projectID,value):
|
|
711 """remove"""
|
|
712 logging.debug("remove:"+projectID+":"+value);
|
|
713
|
|
714 objects = self.getObjectsFromProject(projectID)
|
|
715 for object in objects.keys():
|
|
716
|
|
717 logging.debug("trying:"+repr(object[0])+"::"+repr(value)+"__")
|
|
718 if object[0]==value:
|
|
719 logging.debug("---removed!")
|
|
720 objects.remove(object)
|
|
721
|
|
722 self.projectObjects.update({projectID:objects})
|
|
723 retstring = self.getObjectsFromProjectAsHTML(projectID)
|
|
724 logging.debug(retstring)
|
|
725 return retstring
|
|
726
|
2
|
727 security.declareProtected('View management screens','removePersonFromProject')
|
0
|
728 def removePersonFromProject(self,projectID,value):
|
5
|
729 """remove a person from the projeckt"""
|
0
|
730 logging.debug("remove:"+projectID+":"+value);
|
|
731
|
5
|
732 persons = self.getPersonsFromProject(projectID) # hole alle personen die mit dem Projekt verbunden sind.
|
0
|
733 for person in persons.keys():
|
|
734
|
|
735 logging.debug("trying:"+repr(person[0])+"::"+repr(value)+"__")
|
5
|
736 if person[0]==value:#person ist die zuloeschende, dann raus damit
|
|
737
|
0
|
738 logging.debug("---removed!")
|
|
739 persons.remove(person)
|
5
|
740
|
|
741 #now also delete the project from the person.
|
|
742 projectsOfPerson=self.persons2Projects.get(person[0])
|
|
743 logging.debug(projectsOfPerson)
|
|
744 if projectID in list(projectsOfPerson):
|
|
745 projectsOfPerson.remove(projectID)
|
|
746 #self.persons2Projects.update({person:projectsList})
|
|
747 if (len(projectsOfPerson)==0): #loesche person aus der liste wenn keine Projekte dazu existieren.
|
|
748 del self.persons2Projects[person[0]]
|
|
749
|
|
750
|
|
751 #self.projectPersons.update({projectID:persons})
|
0
|
752 retstring = self.getPersonsFromProjectAsHTML(projectID)
|
|
753 logging.debug(retstring)
|
|
754 return retstring
|
|
755
|
|
756 #fuegt die neue Person zur personIDtoNames hinzu, für die spätere Anzeige in der Personenliste
|
|
757 def addNameTOPersonIDNames(self,personID,label):
|
|
758 personName = self.personIDtoNames.get(personID)
|
|
759 if personName==None: # Anlegen falls noch nicht existent
|
|
760 personName=(label,[])
|
|
761 else:
|
|
762 if (not label in personName[1]) and (not label==personName[0]): # hinzufuegen falls der neuen name noch nicht als bezeichnugn fuer personID eingetragen ist
|
|
763 personName[1].append(label)
|
|
764
|
|
765 self.personIDtoNames.update({personID:personName})
|
|
766
|
2
|
767 security.declareProtected('View management screens','addPersonToProject')
|
0
|
768 def addPersonToProject(self,projectID,value,label):
|
|
769 """ add a person so the project"""
|
|
770 persons=self.getPersonsFromProject(projectID);
|
|
771
|
|
772 logging.debug("adding:"+projectID+":"+value+":"+label);
|
|
773
|
|
774 persons.insert([value,label])
|
|
775 self.projectPersons.update({projectID:persons})
|
|
776
|
|
777 for personTuple in persons:
|
|
778 #hole die abgespeicherten Projekte zu einer Person
|
|
779 person=personTuple[0] #hole die ID
|
|
780
|
|
781
|
|
782 if getattr(self,"persons2Projects",None)==None:
|
|
783 setattr(self,"persons2Projects",OOBTree())
|
|
784
|
|
785 projects = self.persons2Projects.get(person,None)
|
7
|
786 logging.debug("found projects:"+ repr(projects))
|
|
787 if projects is None: #person hatte noch keine projekte
|
0
|
788 projects=OOSet();
|
5
|
789
|
0
|
790 projects.insert(projectID )
|
|
791 logging.debug("update:"+person)
|
|
792 self.persons2Projects.update({person:projects})
|
7
|
793
|
|
794 self.addPersonAndFirstNameFromTripleStore(person)
|
|
795 self.generateSortingOrderForPersonIDs();
|
|
796
|
0
|
797 self.addNameTOPersonIDNames(value,label)
|
|
798 retstring = self.getPersonsFromProjectAsHTML(projectID)
|
|
799 logging.debug(retstring)
|
|
800 transaction.commit()
|
|
801 return retstring
|
|
802
|
7
|
803
|
|
804
|
|
805 def rearangePersonIDsHTML(self,REQUEST=None):
|
|
806 """setze neue ID zu personen"""
|
|
807 ret=[]
|
|
808 for personID in self.persons2Projects.keys():
|
|
809 logging.debug(personID)
|
|
810
|
|
811 masterID,name=self.findMasterIDAndName(personID.rstrip().lstrip())
|
|
812 logging.debug(" masterID -appending")
|
|
813 logging.debug(repr(name))
|
|
814 if len(name)==0:
|
|
815 name=['']
|
|
816 ret.append((personID,self.personIDtoNames.get(personID,[''])[0],masterID,self.personIDtoNames.get(masterID,name)[0]))
|
|
817
|
|
818
|
|
819 if REQUEST:
|
|
820 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','rearrangePersons.zpt')).__of__(self)
|
8
|
821 return pt(changeList=ret,lookupUrl=self.PERSONS_LOOKUP_URL,editURL=self.EDIT_URL);
|
7
|
822 else:
|
|
823 return ret;
|
|
824
|
|
825 def rearangePersonIDs(self,REQUEST):
|
|
826 """unify a list of persons"""
|
|
827
|
|
828 argv=REQUEST.form;
|
|
829 logging.debug(repr(argv))
|
|
830 changes=argv['changes']
|
|
831 if isinstance(changes,str):
|
|
832 changes=[changes]
|
|
833
|
|
834 changeList=self.rearangePersonIDsHTML()
|
|
835 personToMaster={}
|
|
836 logging.debug("changelist:"+repr(changeList))
|
|
837 #aendere person2project
|
|
838 for change in changes:
|
|
839 changeItem=changeList[int(change)];
|
|
840 masterID=argv['newID_'+change].lstrip().rstrip() #make sure no spaces
|
|
841 personID=changeItem[0]
|
|
842
|
|
843 personToMaster[personID]=masterID
|
|
844 masterIDProjects = self.persons2Projects.get(masterID,None);
|
|
845 if masterIDProjects==None:
|
|
846 masterIDProjects=OOSet();
|
|
847 #ret.append((personID,self.personIDtoNames.get(personID,[''])[0],masterID,self.personIDtoNames.get(masterID,[''])[0]))
|
|
848
|
|
849 oldProjects= self.persons2Projects.get(personID)
|
|
850 logging.debug("personID:"+repr(personID))
|
|
851 logging.debug("masterID:"+repr(masterID))
|
|
852 logging.debug("keys:"+repr(self.persons2Projects.keys()))
|
|
853 logging.debug("oldProjects:"+repr(oldProjects))
|
|
854 masterIDProjects.update(oldProjects)
|
|
855 self.persons2Projects.update({masterID:masterIDProjects})
|
|
856 self.persons2Projects.pop(personID)
|
|
857
|
|
858 self.addPersonAndFirstNameFromTripleStore(masterID) #addpersontotiplestore
|
|
859
|
|
860 logging.debug("Change:" +personID+":"+ masterID)
|
|
861
|
|
862 if personID!=masterID:
|
|
863 self.addSameAsRelationToTripleStore(personID,masterID)
|
|
864
|
|
865 #aendere nun projectperson
|
|
866 logging.debug(personToMaster)
|
|
867 for project in self.projectPersons.keys():
|
|
868 personsNew=OOSet()
|
|
869
|
|
870 persons=self.projectPersons.get(project)
|
|
871 for person in persons:
|
|
872 personsNew.insert([personToMaster.get(person[0],person[0]),person[1]])
|
|
873 logging.debug("REPLACE in:"+project+":" +repr(person)+" by "+ repr(personToMaster.get(person[0],person[0])))
|
|
874 self.projectPersons.update({project:personsNew})
|
|
875
|
|
876 self.generateSortingOrderForPersonIDs(); #now sort the new names
|
|
877 return personToMaster
|
|
878 #fuehre personen zusammen die ueber owl:sameAs verbunden sind
|
|
879 def getUnifyPersonsList(self,REQUEST=None):
|
|
880 """vereinheitlichung der personen auf eine ID aus der GND, wenn moeglich"""
|
|
881 ret=[]
|
|
882 for personID in self.persons2Projects.keys():
|
|
883 masterID,name=self.findMasterIDAndName(personID)
|
|
884 logging.debug("masterID:"+masterID)
|
|
885 if (masterID is not None) and (masterID is not "") and (not personID==masterID):
|
|
886 #masterIDProjects = self.persons2Projects.get(masterID,None);
|
|
887 ##if masterIDProjects==None:
|
|
888 # masterIDProjects=OOSet();
|
|
889 logging.debug(" masterID -appending")
|
|
890 logging.debug(repr(name))
|
|
891
|
|
892
|
|
893 ret.append((personID,self.personIDtoNames.get(personID,[''])[0],masterID,self.personIDtoNames.get(masterID,name)[0]))
|
|
894 #masterIDProjects.update(self.persons2Projects.get(personID));
|
|
895 #self.persons2Projects.update({masterID:masterIDProjects});
|
|
896
|
|
897
|
|
898 if REQUEST:
|
|
899 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','unifyPersons.zpt')).__of__(self)
|
|
900 return pt(changeList=ret);
|
|
901
|
|
902 else:
|
|
903 return ret;
|
|
904
|
|
905 def unifyPersons(self,changes,REQUEST=None):
|
|
906 """unify a list of persons"""
|
|
907
|
|
908 if isinstance(changes,str):
|
|
909 changes=[changes]
|
|
910
|
|
911 changeList=self.getUnifyPersonsList();
|
|
912 personToMaster={}
|
|
913 logging.debug("changelist:"+repr(changeList))
|
|
914 #aendere person2project
|
|
915 for change in changes:
|
|
916 changeItem=changeList[int(change)];
|
|
917 masterID=changeItem[2]
|
|
918 personID=changeItem[0]
|
|
919
|
|
920 personToMaster[personID]=masterID
|
|
921 masterIDProjects = self.persons2Projects.get(masterID,None);
|
|
922 if masterIDProjects==None:
|
|
923 masterIDProjects=OOSet();
|
|
924 #ret.append((personID,self.personIDtoNames.get(personID,[''])[0],masterID,self.personIDtoNames.get(masterID,[''])[0]))
|
|
925
|
|
926 oldProjects= self.persons2Projects.get(personID)
|
|
927 logging.debug("personID:"+repr(personID))
|
|
928 logging.debug("masterID:"+repr(masterID))
|
|
929 logging.debug("keys:"+repr(self.persons2Projects.keys()))
|
|
930 logging.debug("oldProjects:"+repr(oldProjects))
|
|
931 masterIDProjects.update(oldProjects)
|
|
932 self.persons2Projects.update({masterID:masterIDProjects})
|
|
933 self.persons2Projects.pop(personID)
|
|
934
|
|
935 self.addPersonAndFirstNameFromTripleStore(masterID) #addpersontotiplestore
|
|
936
|
|
937 logging.debug("Change:" +personID+":"+ masterID)
|
|
938
|
|
939 #aendere nun projectperson
|
|
940 logging.debug(personToMaster)
|
|
941 for project in self.projectPersons.keys():
|
|
942 personsNew=OOSet()
|
|
943
|
|
944 persons=self.projectPersons.get(project)
|
|
945 for person in persons:
|
|
946 personsNew.insert([personToMaster.get(person[0],person[0]),person[1]])
|
|
947 logging.debug("REPLACE in:"+project+":" +repr(person)+" by "+ repr(personToMaster.get(person[0],person[0])))
|
|
948 self.projectPersons.update({project:personsNew})
|
|
949
|
|
950 self.generateSortingOrderForPersonIDs(); #now sort the new names
|
|
951 return personToMaster
|
|
952
|
|
953
|
|
954
|
|
955 def findMasterIDAndName(self,ressourceID):
|
|
956 queryString="""select *
|
|
957 FROM <file://mpiwg_persons_dnb.rdf>
|
|
958 FROM <file://mpiwg_persons_2.rdf>
|
|
959 FROM <file:///GND.rdf>
|
|
960 FROM <http://identifiedNames>
|
|
961 where {
|
|
962 ?person <http://www.w3.org/2002/07/owl#sameAs> <%s>.
|
|
963
|
|
964 ?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person.
|
|
965 ?gnd crm:P1_is_identified_by ?ident.
|
|
966
|
|
967 ?gnd <http://RDVocab.info/ElementsGr2/dateOfBirth> ?birthDate.
|
|
968 ?gnd <http://RDVocab.info/ElementsGr2/dateOfDeath> ?deathDate.
|
|
969 ?person <http://xmlns.com/foaf/0.1/name> ?name.
|
|
970 ?person <http://xmlns.com/foaf/0.1/lastName> ?lastName.
|
|
971 ?person <http://xmlns.com/foaf/0.1/firstName> ?firstName.
|
|
972 }
|
|
973 """%ressourceID
|
|
974 entries = self.callSparqlAll(queryString);
|
|
975 if len(entries)>0:
|
|
976 return entries[0][0],entries[0][5:8] #nur den ersten Treffer und nur die personID
|
|
977
|
|
978
|
|
979 return None,None
|
|
980
|
5
|
981 security.declareProtected('View management screens','getPersonsWithProjectIDs')
|
|
982 def getPersonsWithProjectIDs(self,check=False):
|
0
|
983 """holt die getaggted Personen mit Projekten"""
|
|
984 persons = self.persons2Projects;
|
|
985 ret={}
|
4
|
986
|
0
|
987 logging.debug("Check Person:"+repr(persons.keys()))
|
4
|
988 personsList=[x for x in persons.keys()]
|
|
989
|
|
990 def sort(x,y):
|
7
|
991 try:
|
|
992 sortNrx=self.personsIDForSort.index(x)
|
|
993 except:
|
|
994 logging.warn("couldn't find personsIDForSort:"+x)
|
|
995 sortNrx=0
|
|
996
|
|
997 try:
|
|
998 sortNry=self.personsIDForSort.index(y)
|
|
999 except:
|
|
1000 logging.warn("couldn't find personsIDForSort:"+y)
|
|
1001 sortNry=0
|
4
|
1002 #logging.debug("INSORT***")
|
|
1003 #logging.debug((sortNrx,sortNry))
|
|
1004 return cmp(sortNrx,sortNry)
|
|
1005
|
|
1006 logging.debug("SORT***")
|
|
1007 logging.debug(self.personsIDForSort)
|
|
1008 logging.debug("SORT.list")
|
|
1009 logging.debug(personsList)
|
|
1010 personsList.sort(cmp=sort)
|
|
1011 #for person in persons.keys():
|
|
1012 logging.debug("AFTERSORT***")
|
|
1013 logging.debug(personsList)
|
|
1014 for person in personsList:
|
0
|
1015 logging.debug("Check:"+person)
|
4
|
1016 #TODO: person muss duch den namen von provider geholt werden
|
5
|
1017 retlist=[]
|
|
1018 projectsList=persons.get(person)
|
7
|
1019 if projectsList is None:
|
|
1020 projectsList=[]
|
5
|
1021 for projectID in list(projectsList): #list notwendig da projectList in der folgenden iteration veraendert wird.
|
|
1022 if check: #teste ob im Projekt noch ein Verweis auf den Namen steht
|
|
1023 #sollte eigentlich nicht sein.
|
|
1024 personsProjects=self.getPersonsFromProject(projectID)
|
|
1025 logging.debug("persons check mode")
|
|
1026 personsProjectsCheck=[x[0] for x in personsProjects]
|
|
1027 if not person in personsProjectsCheck: #falls es so ist korrigiere die Projektliste der Person
|
|
1028 #loesche die person von projectListe
|
|
1029 projectsList.remove(projectID)
|
|
1030 persons.update({person:projectsList})
|
|
1031
|
|
1032 retlist.append(self.getProjectDetails(projectID))
|
|
1033
|
|
1034 if check and (len(projectsList)==0): #loesche person aus der liste wenn keine Projekte dazu existieren.
|
|
1035 del persons[person]
|
|
1036
|
|
1037 ret[person]=retlist[0:]
|
4
|
1038
|
|
1039 logging.debug("AFTERSORT-ret***")
|
|
1040 logging.debug(ret.keys())
|
|
1041 return ret,personsList
|
0
|
1042
|
|
1043 def getHistoricalPlacesWithProjectIDs(self):
|
|
1044 """holt die getaggted Personen mit Projekten"""
|
|
1045 HistoricalPlaces = self.HistoricalPlaces2Projects;
|
|
1046 ret={}
|
|
1047 logging.debug("Check HistoricalPlace:"+repr(HistoricalPlaces.keys()))
|
|
1048 for HistoricalPlace in HistoricalPlaces.keys():
|
|
1049 logging.debug("Check:"+HistoricalPlace)
|
|
1050 #TODO: HistoricalPlace muss duch den namen von provuder geholt werden
|
|
1051 list=[]
|
|
1052 for projectID in HistoricalPlaces.get(HistoricalPlace):
|
|
1053 list.append(self.getProjectDetails(projectID))
|
|
1054
|
|
1055 ret[HistoricalPlace]=list[0:]
|
|
1056 return ret
|
|
1057
|
|
1058 def getObjectsWithProjectIDs(self):
|
|
1059 """holt die getaggted Personen mit Projekten"""
|
|
1060 objects = self.objects2Projects;
|
|
1061 ret={}
|
|
1062 logging.debug("Check Object:"+repr(objects.keys()))
|
|
1063 for object in objects.keys():
|
|
1064 logging.debug("Check:"+object)
|
|
1065 #TODO: object muss duch den namen von provuder geholt werden
|
|
1066 list=[]
|
|
1067 for projectID in objects.get(object):
|
|
1068 list.append(self.getProjectDetails(projectID))
|
|
1069
|
|
1070 ret[object]=list[0:]
|
|
1071 return ret
|
|
1072
|
2
|
1073 security.declareProtected('View management screens','listAllSuggestedTags')
|
0
|
1074 def listAllSuggestedTags(self):
|
|
1075 """list all tags"""
|
|
1076 ret="<html><body>"
|
|
1077 for projectID in self.projectSuggestedTags:
|
|
1078 ret+="<h3>"+projectID+"</h3><table>"
|
|
1079 for tags in self.projectSuggestedTags.get(projectID):
|
|
1080 ret+="<tr><td>"+tags[0]+"</td><td>"+tags[1].type+"</td><td>"+tags[1].comment+"</td><td>"+tags[1].userName+"</td></tr>"
|
|
1081 ret+="</table>"
|
|
1082 ret+="</body></html>"
|
|
1083 logging.debug(ret);
|
|
1084 return ret
|
2
|
1085
|
|
1086 security.declareProtected('View management screens','suggestTag')
|
0
|
1087 def suggestTag(self,projectID,tagName,tagComment,tagType,tagUserName):
|
|
1088 """suggest a new tag"""
|
|
1089 """ add a person so the project"""
|
|
1090 SuggestedTags=self.getSuggestedTagsFromProject(projectID);
|
|
1091
|
|
1092 logging.debug("suggested:"+projectID+":"+tagName);
|
|
1093
|
|
1094
|
|
1095 #TODO: Im moment noch keine Zuordnung zu einer ID.
|
|
1096 newTag = SuggestedTag(tagName,tagComment,tagType,tagUserName)
|
|
1097 SuggestedTags.insert([tagName,newTag])
|
|
1098 self.projectSuggestedTags.update({projectID:SuggestedTags})
|
|
1099
|
|
1100
|
|
1101
|
|
1102 for SuggestedTagTuple in SuggestedTags:
|
|
1103 #hole die abgespeicherten Projekte zu einer Person
|
|
1104 person=SuggestedTagTuple[0] #hile die ID
|
|
1105
|
|
1106
|
|
1107 if getattr(self,"SuggestedTags2Projects",None)==None:
|
|
1108 setattr(self,"SuggestedTags2Projects",OOBTree())
|
|
1109
|
|
1110 projects = self.SuggestedTags2Projects.get(person,None)
|
|
1111
|
|
1112 if projects==None:
|
|
1113 projects=OOSet();
|
|
1114
|
|
1115 projects.insert(projectID )
|
|
1116 logging.debug("update:"+person)
|
|
1117 self.SuggestedTags2Projects.update({person:projects})
|
|
1118
|
|
1119
|
|
1120
|
|
1121 #retstring = self.getSuggestedTagsFromProjectAsHTML(projectID)
|
|
1122 #logging.debug(retstring)
|
|
1123
|
|
1124
|
|
1125
|
|
1126 #return retstring
|
|
1127
|
2
|
1128 security.declareProtected('View management screens','addHistoricalPlaceToProject')
|
0
|
1129 def addHistoricalPlaceToProject(self,projectID,value):
|
|
1130 """ add a person so the project"""
|
|
1131 HistoricalPlaces=self.getHistoricalPlacesFromProject(projectID);
|
|
1132
|
|
1133 logging.debug("adding:"+projectID+":"+value);
|
|
1134
|
|
1135
|
|
1136 #TODO: Im moment noch keine Zuordnung zu einer ID.
|
|
1137 HistoricalPlaces.insert([value,value])
|
|
1138 self.projectHistoricalPlaces.update({projectID:HistoricalPlaces})
|
|
1139
|
|
1140
|
|
1141
|
|
1142 for HistoricalPlaceTuple in HistoricalPlaces:
|
|
1143 #hole die abgespeicherten Projekte zu einer Person
|
|
1144 person=HistoricalPlaceTuple[0] #hile die ID
|
|
1145
|
|
1146
|
|
1147 if getattr(self,"HistoricalPlaces2Projects",None)==None:
|
|
1148 setattr(self,"HistoricalPlaces2Projects",OOBTree())
|
|
1149
|
|
1150 projects = self.HistoricalPlaces2Projects.get(person,None)
|
|
1151
|
|
1152 if projects==None:
|
|
1153 projects=OOSet();
|
|
1154
|
|
1155 projects.insert(projectID )
|
|
1156 logging.debug("update:"+person)
|
|
1157 self.HistoricalPlaces2Projects.update({person:projects})
|
|
1158
|
|
1159
|
|
1160
|
|
1161 retstring = self.getHistoricalPlacesFromProjectAsHTML(projectID)
|
|
1162 logging.debug(retstring)
|
|
1163
|
|
1164
|
|
1165
|
|
1166 return retstring
|
|
1167
|
2
|
1168 security.declareProtected('View management screens','addObjectToProject')
|
0
|
1169 def addObjectToProject(self,projectID,value):
|
|
1170 """ add a person so the project"""
|
|
1171 objects=self.getObjectsFromProject(projectID);
|
|
1172
|
|
1173 logging.debug("adding:"+projectID+":"+value);
|
|
1174
|
|
1175
|
|
1176 #TODO: Im moment noch keine Zuordnung zu einer ID.
|
|
1177 objects.insert([value,value])
|
|
1178 self.projectObjects.update({projectID:objects})
|
|
1179
|
|
1180
|
|
1181
|
|
1182 for objectTuple in objects:
|
|
1183 #hole die abgespeicherten Projekte zu einer Person
|
|
1184 person=objectTuple[0] #hile die ID
|
|
1185
|
|
1186
|
|
1187 if getattr(self,"objects2Projects",None)==None:
|
|
1188 setattr(self,"objects2Projects",OOBTree())
|
|
1189
|
|
1190 projects = self.objects2Projects.get(person,None)
|
|
1191
|
|
1192 if projects==None:
|
|
1193 projects=OOSet();
|
|
1194
|
|
1195 projects.insert(projectID )
|
|
1196 logging.debug("update:"+person)
|
|
1197 self.objects2Projects.update({person:projects})
|
|
1198
|
|
1199
|
|
1200
|
|
1201 retstring = self.getObjectsFromProjectAsHTML(projectID)
|
|
1202 logging.debug(retstring)
|
|
1203
|
|
1204
|
|
1205
|
|
1206 return retstring
|
|
1207
|
|
1208
|
|
1209 def getProjectsWithTag(self,tagType,tagName):
|
|
1210 tags = getattr(self,"tags",None)
|
|
1211 if tags is None:
|
|
1212 logging.debug("can't find Tags")
|
|
1213 return []
|
|
1214
|
|
1215
|
|
1216
|
|
1217 tagsStored=tags.get(tagType,None)
|
|
1218 if tagsStored is None:
|
|
1219 logging.debug("can't find Tag:"+tagType)
|
|
1220 return []
|
|
1221
|
|
1222 projects = tagsStored.get(tagName,None)
|
|
1223 if projects is None:
|
|
1224 logging.debug("can't find any projects for Tag:"+tagName+"("+tagType+")")
|
|
1225 return []
|
|
1226
|
|
1227 ret=[]
|
|
1228 for project in projects:
|
|
1229 logging.debug("found:"+project)
|
|
1230 ret.append(self.getProjectDetails(project))
|
|
1231
|
|
1232 return ret
|
|
1233
|
|
1234 def getProjectDetails(self,getID):
|
|
1235 project=getattr(self.www_neu.projects,getID,None)
|
|
1236 if project is None:
|
|
1237 logging.debug("no project!! " +getID)
|
|
1238 return
|
|
1239
|
|
1240 link="/en/research/projects/"+getID
|
|
1241
|
|
1242 title=project.getContent("short_title")
|
|
1243 #persons=project.getPersonKeyList()
|
|
1244 persons=project.getContent('xdata_01')
|
|
1245 logging.debug("%s %s %s"%(link,title,persons))
|
|
1246 return link,title,persons
|
|
1247
|
|
1248 # $.post("addNewPerson",{"projectID":
|
|
1249 # $('#projectID').val(),
|
|
1250 # "personName":$("#suggest_newPerson").val(),
|
|
1251 # "personComment":$("#suggest_newPerson_comment").val()}
|
|
1252 #
|
|
1253 # );
|
|
1254 #
|
2
|
1255
|
|
1256 security.declareProtected('View management screens','addAndCreateNewPerson')
|
0
|
1257 def addAndCreateNewPerson(self,projectID,personName,personComment,personUserName):
|
|
1258 """adds anew person to the project which is not in the authority file"""
|
|
1259
|
|
1260 id = random.randint(0, 1000000);
|
|
1261 idstring="http://ontologies.mpiwg-berlin.mpg.de/tempObjects/person/"+str(id)
|
|
1262 while self.suggestedPersons.has_key(idstring):
|
|
1263 id = random.randint(0, 1000000);
|
|
1264 #idstring="http://ontologies.mpiwg-berlin.mpg.de/tempObjects/person/"+str(id);
|
|
1265 idstring=self.TEMP_PERSON_NS+str(id);
|
|
1266
|
|
1267
|
|
1268 self.suggestedPersons.update({idstring:(personName,personComment,projectID,personUserName)})
|
|
1269 self.createTempPersonInVirtuoso(projectID, idstring, personName, personComment) #TODO: add suername to the triplestore
|
|
1270 return self.addPersonToProject(projectID, idstring, personName);
|
2
|
1271
|
7
|
1272 def addSameAsRelationToTripleStore(self,personID,masterID):
|
|
1273 cmdString ="insert in GRAPH <"+self.virtuosoGraph+"> {"
|
|
1274 cmdString +="<%s> <http://www.w3.org/2002/07/owl#sameAs> <%s>."%(personID,masterID)
|
|
1275 cmdString +="<%s> <http://www.w3.org/2002/07/owl#sameAs> <%s>."%(masterID,personID)
|
|
1276 cmdString+="}"
|
|
1277
|
|
1278 auth_handler = urllib2.HTTPBasicAuthHandler()
|
|
1279 auth_handler.add_password(realm='sparql',
|
|
1280 uri=self.virtuosoServer+"/sparql",
|
|
1281 user=self.virtuosoDAVUser,
|
|
1282 passwd=self.virtuosoDAVPW)
|
|
1283
|
|
1284 opener = urllib2.build_opener(auth_handler)
|
|
1285 opener.addheaders = [('Content-Type','application/sparql-query')]
|
|
1286
|
|
1287 logging.debug(cmdString)
|
|
1288 try:
|
|
1289 r= opener.open(self.virtuosoServer+"/sparql", urllib.urlencode({'query':cmdString,'default-graph-uri':self.virtuosoGraph,'named-graph-uri':None}))
|
|
1290 logging.debug(r.read())
|
|
1291 except urllib2.URLError, e:
|
|
1292 logging.error(e.code)
|
|
1293 logging.error(e.read())
|
|
1294 return
|
|
1295
|
|
1296
|
2
|
1297 security.declareProtected('View management screens','createTempPersonInVirtuoso')
|
0
|
1298 def createTempPersonInVirtuoso(self,projectID,personURI, personName,personComment):
|
|
1299 """add a new person to the triple store of tempory persons"""
|
|
1300 triples=[];
|
|
1301 personID="<"+personURI+">"
|
|
1302 triples.append((personID,"<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>","<http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/Person>"))
|
|
1303 triples.append((personID,"<http://erlangen-crm.org/110404/P3_has_note>",'"'+personComment+'"'))
|
|
1304 triples.append((personID,"<http://xmlns.com/foaf/0.1/name>",'"'+personName+'"'))
|
|
1305 triples.append((personID,"<http://ontologies.mpiwg-berlin.mpg.de/general/isMentionedOn>","<http://www.mpiwg-berlin.mpg.de/en/research/projects/"+projectID+">"))
|
|
1306
|
|
1307 cmdString ="insert in GRAPH <"+self.virtuosoGraph+"> {"
|
|
1308 for triple in triples:
|
|
1309 cmdString+=" ".join(triple)+"."
|
|
1310
|
|
1311 cmdString+="}"
|
|
1312
|
|
1313 auth_handler = urllib2.HTTPBasicAuthHandler()
|
|
1314 auth_handler.add_password(realm='sparql',
|
|
1315 uri=self.virtuosoServer+"/sparql",
|
|
1316 user=self.virtuosoDAVUser,
|
|
1317 passwd=self.virtuosoDAVPW)
|
|
1318
|
|
1319 opener = urllib2.build_opener(auth_handler)
|
|
1320 opener.addheaders = [('Content-Type','application/sparql-query')]
|
|
1321
|
|
1322 logging.debug(cmdString)
|
|
1323 try:
|
|
1324 r= opener.open(self.virtuosoServer+"/sparql", urllib.urlencode({'query':cmdString,'default-graph-uri':self.virtuosoGraph,'named-graph-uri':None}))
|
|
1325 logging.debug(r.read())
|
|
1326 except urllib2.URLError, e:
|
|
1327 logging.error(e.code)
|
|
1328 logging.error(e.read())
|
|
1329 return
|
|
1330
|
|
1331 opener2 = urllib2.build_opener()
|
|
1332
|
|
1333
|
|
1334 personIDencoded=urllib.quote(personURI,safe="")
|
|
1335 graphEncoded=urllib.quote(self.additionalNamesGraphURL,safe="")
|
|
1336 url = self.personproviderURL+"id/"+personIDencoded+"/"+graphEncoded
|
|
1337
|
|
1338 try:
|
|
1339 request = urllib2.Request(url);
|
|
1340 request.get_method = lambda : 'PUT'
|
|
1341 r= opener2.open(request);
|
|
1342 logging.debug(r.read())
|
|
1343 except urllib2.URLError, e:
|
|
1344 logging.error(e.code)
|
|
1345 logging.error(e.read())
|
|
1346 return
|
|
1347
|
|
1348
|
|
1349
|
|
1350 return
|
|
1351
|
|
1352 def redirect(RESPONSE,url):
|
|
1353 """mache ein redirect mit einem angehaengten time stamp um ein reload zu erzwingen"""
|
|
1354
|
|
1355 timeStamp=time.time()
|
|
1356
|
|
1357 if url.find("?")>-1: #giebt es schon parameter
|
|
1358 addStr="&time=%s"
|
|
1359 else:
|
|
1360 addStr="?time=%s"
|
|
1361
|
|
1362 RESPONSE.setHeader('Last-Modified',email.Utils.formatdate().split("-")[0]+'GMT')
|
|
1363 logging.error(email.Utils.formatdate()+' GMT')
|
|
1364 RESPONSE.redirect(url+addStr%timeStamp)
|
|
1365
|
|
1366 def manage_addMPIWGThesaurusForm(self):
|
|
1367 """form for adding the project"""
|
|
1368 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMPIWGThesaurusForm.zpt')).__of__(self)
|
|
1369 return pt()
|
|
1370
|
|
1371
|
|
1372
|
|
1373 def manage_addMPIWGThesaurus(self,id,RESPONSE=None):
|
|
1374 """add it"""
|
|
1375 newObj=MPIWGThesaurus(id)
|
|
1376
|
|
1377 self._setObject(id,newObj)
|
|
1378
|
|
1379
|
|
1380 if RESPONSE is not None:
|
|
1381 redirect(RESPONSE,'manage_main') |