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