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
|
11
|
4 #Fuer die Suche ueber die Personenname wird das MetaDataManagerRestlet benoetigt.
|
1
|
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")
|
11
|
337 if len(names) < 2: #in der ersten Zeile stehen bei der Rueckgabe die Spaltennamen, <2 heiss also es gibt keinen Eintrag
|
7
|
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")
|
11
|
374 if len(names) < 2: #in der ersten Zeile stehen bei der Rueckgabe die Spaltennamen, <2 heiss also es gibt keinen Eintrag
|
0
|
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
|
11
|
756
|
|
757 #fuegt die neue Person zur personIDtoNames hinzu, fuer die spaetere Anzeige in der Personenliste
|
0
|
758 def addNameTOPersonIDNames(self,personID,label):
|
|
759 personName = self.personIDtoNames.get(personID)
|
|
760 if personName==None: # Anlegen falls noch nicht existent
|
|
761 personName=(label,[])
|
|
762 else:
|
|
763 if (not label in personName[1]) and (not label==personName[0]): # hinzufuegen falls der neuen name noch nicht als bezeichnugn fuer personID eingetragen ist
|
|
764 personName[1].append(label)
|
|
765
|
|
766 self.personIDtoNames.update({personID:personName})
|
|
767
|
2
|
768 security.declareProtected('View management screens','addPersonToProject')
|
0
|
769 def addPersonToProject(self,projectID,value,label):
|
|
770 """ add a person so the project"""
|
|
771 persons=self.getPersonsFromProject(projectID);
|
|
772
|
|
773 logging.debug("adding:"+projectID+":"+value+":"+label);
|
|
774
|
|
775 persons.insert([value,label])
|
|
776 self.projectPersons.update({projectID:persons})
|
|
777
|
|
778 for personTuple in persons:
|
|
779 #hole die abgespeicherten Projekte zu einer Person
|
|
780 person=personTuple[0] #hole die ID
|
|
781
|
|
782
|
|
783 if getattr(self,"persons2Projects",None)==None:
|
|
784 setattr(self,"persons2Projects",OOBTree())
|
|
785
|
|
786 projects = self.persons2Projects.get(person,None)
|
7
|
787 logging.debug("found projects:"+ repr(projects))
|
|
788 if projects is None: #person hatte noch keine projekte
|
0
|
789 projects=OOSet();
|
5
|
790
|
0
|
791 projects.insert(projectID )
|
|
792 logging.debug("update:"+person)
|
|
793 self.persons2Projects.update({person:projects})
|
7
|
794
|
|
795 self.addPersonAndFirstNameFromTripleStore(person)
|
|
796 self.generateSortingOrderForPersonIDs();
|
|
797
|
0
|
798 self.addNameTOPersonIDNames(value,label)
|
|
799 retstring = self.getPersonsFromProjectAsHTML(projectID)
|
|
800 logging.debug(retstring)
|
|
801 transaction.commit()
|
|
802 return retstring
|
|
803
|
7
|
804
|
|
805
|
|
806 def rearangePersonIDsHTML(self,REQUEST=None):
|
|
807 """setze neue ID zu personen"""
|
|
808 ret=[]
|
|
809 for personID in self.persons2Projects.keys():
|
|
810 logging.debug(personID)
|
|
811
|
|
812 masterID,name=self.findMasterIDAndName(personID.rstrip().lstrip())
|
|
813 logging.debug(" masterID -appending")
|
|
814 logging.debug(repr(name))
|
|
815 if len(name)==0:
|
|
816 name=['']
|
|
817 ret.append((personID,self.personIDtoNames.get(personID,[''])[0],masterID,self.personIDtoNames.get(masterID,name)[0]))
|
|
818
|
|
819
|
|
820 if REQUEST:
|
|
821 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','rearrangePersons.zpt')).__of__(self)
|
8
|
822 return pt(changeList=ret,lookupUrl=self.PERSONS_LOOKUP_URL,editURL=self.EDIT_URL);
|
7
|
823 else:
|
|
824 return ret;
|
|
825
|
|
826 def rearangePersonIDs(self,REQUEST):
|
|
827 """unify a list of persons"""
|
|
828
|
|
829 argv=REQUEST.form;
|
|
830 logging.debug(repr(argv))
|
|
831 changes=argv['changes']
|
|
832 if isinstance(changes,str):
|
|
833 changes=[changes]
|
|
834
|
|
835 changeList=self.rearangePersonIDsHTML()
|
|
836 personToMaster={}
|
|
837 logging.debug("changelist:"+repr(changeList))
|
|
838 #aendere person2project
|
|
839 for change in changes:
|
|
840 changeItem=changeList[int(change)];
|
|
841 masterID=argv['newID_'+change].lstrip().rstrip() #make sure no spaces
|
|
842 personID=changeItem[0]
|
|
843
|
|
844 personToMaster[personID]=masterID
|
|
845 masterIDProjects = self.persons2Projects.get(masterID,None);
|
|
846 if masterIDProjects==None:
|
|
847 masterIDProjects=OOSet();
|
|
848 #ret.append((personID,self.personIDtoNames.get(personID,[''])[0],masterID,self.personIDtoNames.get(masterID,[''])[0]))
|
|
849
|
|
850 oldProjects= self.persons2Projects.get(personID)
|
|
851 logging.debug("personID:"+repr(personID))
|
|
852 logging.debug("masterID:"+repr(masterID))
|
|
853 logging.debug("keys:"+repr(self.persons2Projects.keys()))
|
|
854 logging.debug("oldProjects:"+repr(oldProjects))
|
|
855 masterIDProjects.update(oldProjects)
|
|
856 self.persons2Projects.update({masterID:masterIDProjects})
|
|
857 self.persons2Projects.pop(personID)
|
|
858
|
|
859 self.addPersonAndFirstNameFromTripleStore(masterID) #addpersontotiplestore
|
|
860
|
|
861 logging.debug("Change:" +personID+":"+ masterID)
|
|
862
|
|
863 if personID!=masterID:
|
|
864 self.addSameAsRelationToTripleStore(personID,masterID)
|
|
865
|
|
866 #aendere nun projectperson
|
|
867 logging.debug(personToMaster)
|
|
868 for project in self.projectPersons.keys():
|
|
869 personsNew=OOSet()
|
|
870
|
|
871 persons=self.projectPersons.get(project)
|
|
872 for person in persons:
|
|
873 personsNew.insert([personToMaster.get(person[0],person[0]),person[1]])
|
|
874 logging.debug("REPLACE in:"+project+":" +repr(person)+" by "+ repr(personToMaster.get(person[0],person[0])))
|
|
875 self.projectPersons.update({project:personsNew})
|
|
876
|
|
877 self.generateSortingOrderForPersonIDs(); #now sort the new names
|
|
878 return personToMaster
|
|
879 #fuehre personen zusammen die ueber owl:sameAs verbunden sind
|
|
880 def getUnifyPersonsList(self,REQUEST=None):
|
|
881 """vereinheitlichung der personen auf eine ID aus der GND, wenn moeglich"""
|
|
882 ret=[]
|
|
883 for personID in self.persons2Projects.keys():
|
|
884 masterID,name=self.findMasterIDAndName(personID)
|
|
885 logging.debug("masterID:"+masterID)
|
|
886 if (masterID is not None) and (masterID is not "") and (not personID==masterID):
|
|
887 #masterIDProjects = self.persons2Projects.get(masterID,None);
|
|
888 ##if masterIDProjects==None:
|
|
889 # masterIDProjects=OOSet();
|
|
890 logging.debug(" masterID -appending")
|
|
891 logging.debug(repr(name))
|
|
892
|
|
893
|
|
894 ret.append((personID,self.personIDtoNames.get(personID,[''])[0],masterID,self.personIDtoNames.get(masterID,name)[0]))
|
|
895 #masterIDProjects.update(self.persons2Projects.get(personID));
|
|
896 #self.persons2Projects.update({masterID:masterIDProjects});
|
|
897
|
|
898
|
|
899 if REQUEST:
|
|
900 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','unifyPersons.zpt')).__of__(self)
|
|
901 return pt(changeList=ret);
|
|
902
|
|
903 else:
|
|
904 return ret;
|
|
905
|
|
906 def unifyPersons(self,changes,REQUEST=None):
|
|
907 """unify a list of persons"""
|
|
908
|
|
909 if isinstance(changes,str):
|
|
910 changes=[changes]
|
|
911
|
|
912 changeList=self.getUnifyPersonsList();
|
|
913 personToMaster={}
|
|
914 logging.debug("changelist:"+repr(changeList))
|
|
915 #aendere person2project
|
|
916 for change in changes:
|
|
917 changeItem=changeList[int(change)];
|
|
918 masterID=changeItem[2]
|
|
919 personID=changeItem[0]
|
|
920
|
|
921 personToMaster[personID]=masterID
|
|
922 masterIDProjects = self.persons2Projects.get(masterID,None);
|
|
923 if masterIDProjects==None:
|
|
924 masterIDProjects=OOSet();
|
|
925 #ret.append((personID,self.personIDtoNames.get(personID,[''])[0],masterID,self.personIDtoNames.get(masterID,[''])[0]))
|
|
926
|
|
927 oldProjects= self.persons2Projects.get(personID)
|
|
928 logging.debug("personID:"+repr(personID))
|
|
929 logging.debug("masterID:"+repr(masterID))
|
|
930 logging.debug("keys:"+repr(self.persons2Projects.keys()))
|
|
931 logging.debug("oldProjects:"+repr(oldProjects))
|
|
932 masterIDProjects.update(oldProjects)
|
|
933 self.persons2Projects.update({masterID:masterIDProjects})
|
|
934 self.persons2Projects.pop(personID)
|
|
935
|
|
936 self.addPersonAndFirstNameFromTripleStore(masterID) #addpersontotiplestore
|
|
937
|
|
938 logging.debug("Change:" +personID+":"+ masterID)
|
|
939
|
|
940 #aendere nun projectperson
|
|
941 logging.debug(personToMaster)
|
|
942 for project in self.projectPersons.keys():
|
|
943 personsNew=OOSet()
|
|
944
|
|
945 persons=self.projectPersons.get(project)
|
|
946 for person in persons:
|
|
947 personsNew.insert([personToMaster.get(person[0],person[0]),person[1]])
|
|
948 logging.debug("REPLACE in:"+project+":" +repr(person)+" by "+ repr(personToMaster.get(person[0],person[0])))
|
|
949 self.projectPersons.update({project:personsNew})
|
|
950
|
|
951 self.generateSortingOrderForPersonIDs(); #now sort the new names
|
|
952 return personToMaster
|
|
953
|
|
954
|
|
955
|
|
956 def findMasterIDAndName(self,ressourceID):
|
|
957 queryString="""select *
|
|
958 FROM <file://mpiwg_persons_dnb.rdf>
|
|
959 FROM <file://mpiwg_persons_2.rdf>
|
|
960 FROM <file:///GND.rdf>
|
|
961 FROM <http://identifiedNames>
|
|
962 where {
|
|
963 ?person <http://www.w3.org/2002/07/owl#sameAs> <%s>.
|
|
964
|
|
965 ?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person.
|
|
966 ?gnd crm:P1_is_identified_by ?ident.
|
|
967
|
|
968 ?gnd <http://RDVocab.info/ElementsGr2/dateOfBirth> ?birthDate.
|
|
969 ?gnd <http://RDVocab.info/ElementsGr2/dateOfDeath> ?deathDate.
|
|
970 ?person <http://xmlns.com/foaf/0.1/name> ?name.
|
|
971 ?person <http://xmlns.com/foaf/0.1/lastName> ?lastName.
|
|
972 ?person <http://xmlns.com/foaf/0.1/firstName> ?firstName.
|
|
973 }
|
|
974 """%ressourceID
|
|
975 entries = self.callSparqlAll(queryString);
|
|
976 if len(entries)>0:
|
|
977 return entries[0][0],entries[0][5:8] #nur den ersten Treffer und nur die personID
|
|
978
|
|
979
|
|
980 return None,None
|
|
981
|
9
|
982 security.declareProtected('View','getPersonsWithProjectIDs')
|
5
|
983 def getPersonsWithProjectIDs(self,check=False):
|
0
|
984 """holt die getaggted Personen mit Projekten"""
|
|
985 persons = self.persons2Projects;
|
|
986 ret={}
|
4
|
987
|
0
|
988 logging.debug("Check Person:"+repr(persons.keys()))
|
4
|
989 personsList=[x for x in persons.keys()]
|
|
990
|
|
991 def sort(x,y):
|
7
|
992 try:
|
|
993 sortNrx=self.personsIDForSort.index(x)
|
|
994 except:
|
|
995 logging.warn("couldn't find personsIDForSort:"+x)
|
|
996 sortNrx=0
|
|
997
|
|
998 try:
|
|
999 sortNry=self.personsIDForSort.index(y)
|
|
1000 except:
|
|
1001 logging.warn("couldn't find personsIDForSort:"+y)
|
|
1002 sortNry=0
|
4
|
1003 #logging.debug("INSORT***")
|
|
1004 #logging.debug((sortNrx,sortNry))
|
|
1005 return cmp(sortNrx,sortNry)
|
|
1006
|
|
1007 logging.debug("SORT***")
|
|
1008 logging.debug(self.personsIDForSort)
|
|
1009 logging.debug("SORT.list")
|
|
1010 logging.debug(personsList)
|
|
1011 personsList.sort(cmp=sort)
|
|
1012 #for person in persons.keys():
|
|
1013 logging.debug("AFTERSORT***")
|
|
1014 logging.debug(personsList)
|
|
1015 for person in personsList:
|
0
|
1016 logging.debug("Check:"+person)
|
4
|
1017 #TODO: person muss duch den namen von provider geholt werden
|
5
|
1018 retlist=[]
|
|
1019 projectsList=persons.get(person)
|
7
|
1020 if projectsList is None:
|
|
1021 projectsList=[]
|
5
|
1022 for projectID in list(projectsList): #list notwendig da projectList in der folgenden iteration veraendert wird.
|
|
1023 if check: #teste ob im Projekt noch ein Verweis auf den Namen steht
|
|
1024 #sollte eigentlich nicht sein.
|
|
1025 personsProjects=self.getPersonsFromProject(projectID)
|
|
1026 logging.debug("persons check mode")
|
|
1027 personsProjectsCheck=[x[0] for x in personsProjects]
|
|
1028 if not person in personsProjectsCheck: #falls es so ist korrigiere die Projektliste der Person
|
|
1029 #loesche die person von projectListe
|
|
1030 projectsList.remove(projectID)
|
|
1031 persons.update({person:projectsList})
|
|
1032
|
|
1033 retlist.append(self.getProjectDetails(projectID))
|
|
1034
|
|
1035 if check and (len(projectsList)==0): #loesche person aus der liste wenn keine Projekte dazu existieren.
|
|
1036 del persons[person]
|
|
1037
|
|
1038 ret[person]=retlist[0:]
|
4
|
1039
|
|
1040 logging.debug("AFTERSORT-ret***")
|
|
1041 logging.debug(ret.keys())
|
|
1042 return ret,personsList
|
0
|
1043
|
|
1044 def getHistoricalPlacesWithProjectIDs(self):
|
|
1045 """holt die getaggted Personen mit Projekten"""
|
|
1046 HistoricalPlaces = self.HistoricalPlaces2Projects;
|
|
1047 ret={}
|
|
1048 logging.debug("Check HistoricalPlace:"+repr(HistoricalPlaces.keys()))
|
|
1049 for HistoricalPlace in HistoricalPlaces.keys():
|
|
1050 logging.debug("Check:"+HistoricalPlace)
|
|
1051 #TODO: HistoricalPlace muss duch den namen von provuder geholt werden
|
|
1052 list=[]
|
|
1053 for projectID in HistoricalPlaces.get(HistoricalPlace):
|
|
1054 list.append(self.getProjectDetails(projectID))
|
|
1055
|
|
1056 ret[HistoricalPlace]=list[0:]
|
|
1057 return ret
|
|
1058
|
|
1059 def getObjectsWithProjectIDs(self):
|
|
1060 """holt die getaggted Personen mit Projekten"""
|
|
1061 objects = self.objects2Projects;
|
|
1062 ret={}
|
|
1063 logging.debug("Check Object:"+repr(objects.keys()))
|
|
1064 for object in objects.keys():
|
|
1065 logging.debug("Check:"+object)
|
|
1066 #TODO: object muss duch den namen von provuder geholt werden
|
|
1067 list=[]
|
|
1068 for projectID in objects.get(object):
|
|
1069 list.append(self.getProjectDetails(projectID))
|
|
1070
|
|
1071 ret[object]=list[0:]
|
|
1072 return ret
|
|
1073
|
2
|
1074 security.declareProtected('View management screens','listAllSuggestedTags')
|
0
|
1075 def listAllSuggestedTags(self):
|
|
1076 """list all tags"""
|
|
1077 ret="<html><body>"
|
|
1078 for projectID in self.projectSuggestedTags:
|
|
1079 ret+="<h3>"+projectID+"</h3><table>"
|
|
1080 for tags in self.projectSuggestedTags.get(projectID):
|
|
1081 ret+="<tr><td>"+tags[0]+"</td><td>"+tags[1].type+"</td><td>"+tags[1].comment+"</td><td>"+tags[1].userName+"</td></tr>"
|
|
1082 ret+="</table>"
|
|
1083 ret+="</body></html>"
|
|
1084 logging.debug(ret);
|
|
1085 return ret
|
2
|
1086
|
|
1087 security.declareProtected('View management screens','suggestTag')
|
0
|
1088 def suggestTag(self,projectID,tagName,tagComment,tagType,tagUserName):
|
|
1089 """suggest a new tag"""
|
|
1090 """ add a person so the project"""
|
|
1091 SuggestedTags=self.getSuggestedTagsFromProject(projectID);
|
|
1092
|
|
1093 logging.debug("suggested:"+projectID+":"+tagName);
|
|
1094
|
|
1095
|
|
1096 #TODO: Im moment noch keine Zuordnung zu einer ID.
|
|
1097 newTag = SuggestedTag(tagName,tagComment,tagType,tagUserName)
|
|
1098 SuggestedTags.insert([tagName,newTag])
|
|
1099 self.projectSuggestedTags.update({projectID:SuggestedTags})
|
|
1100
|
|
1101
|
|
1102
|
|
1103 for SuggestedTagTuple in SuggestedTags:
|
|
1104 #hole die abgespeicherten Projekte zu einer Person
|
|
1105 person=SuggestedTagTuple[0] #hile die ID
|
|
1106
|
|
1107
|
|
1108 if getattr(self,"SuggestedTags2Projects",None)==None:
|
|
1109 setattr(self,"SuggestedTags2Projects",OOBTree())
|
|
1110
|
|
1111 projects = self.SuggestedTags2Projects.get(person,None)
|
|
1112
|
|
1113 if projects==None:
|
|
1114 projects=OOSet();
|
|
1115
|
|
1116 projects.insert(projectID )
|
|
1117 logging.debug("update:"+person)
|
|
1118 self.SuggestedTags2Projects.update({person:projects})
|
|
1119
|
|
1120
|
|
1121
|
|
1122 #retstring = self.getSuggestedTagsFromProjectAsHTML(projectID)
|
|
1123 #logging.debug(retstring)
|
|
1124
|
|
1125
|
|
1126
|
|
1127 #return retstring
|
|
1128
|
2
|
1129 security.declareProtected('View management screens','addHistoricalPlaceToProject')
|
0
|
1130 def addHistoricalPlaceToProject(self,projectID,value):
|
|
1131 """ add a person so the project"""
|
|
1132 HistoricalPlaces=self.getHistoricalPlacesFromProject(projectID);
|
|
1133
|
|
1134 logging.debug("adding:"+projectID+":"+value);
|
|
1135
|
|
1136
|
|
1137 #TODO: Im moment noch keine Zuordnung zu einer ID.
|
|
1138 HistoricalPlaces.insert([value,value])
|
|
1139 self.projectHistoricalPlaces.update({projectID:HistoricalPlaces})
|
|
1140
|
|
1141
|
|
1142
|
|
1143 for HistoricalPlaceTuple in HistoricalPlaces:
|
|
1144 #hole die abgespeicherten Projekte zu einer Person
|
|
1145 person=HistoricalPlaceTuple[0] #hile die ID
|
|
1146
|
|
1147
|
|
1148 if getattr(self,"HistoricalPlaces2Projects",None)==None:
|
|
1149 setattr(self,"HistoricalPlaces2Projects",OOBTree())
|
|
1150
|
|
1151 projects = self.HistoricalPlaces2Projects.get(person,None)
|
|
1152
|
|
1153 if projects==None:
|
|
1154 projects=OOSet();
|
|
1155
|
|
1156 projects.insert(projectID )
|
|
1157 logging.debug("update:"+person)
|
|
1158 self.HistoricalPlaces2Projects.update({person:projects})
|
|
1159
|
|
1160
|
|
1161
|
|
1162 retstring = self.getHistoricalPlacesFromProjectAsHTML(projectID)
|
|
1163 logging.debug(retstring)
|
|
1164
|
|
1165
|
|
1166
|
|
1167 return retstring
|
|
1168
|
2
|
1169 security.declareProtected('View management screens','addObjectToProject')
|
0
|
1170 def addObjectToProject(self,projectID,value):
|
|
1171 """ add a person so the project"""
|
|
1172 objects=self.getObjectsFromProject(projectID);
|
|
1173
|
|
1174 logging.debug("adding:"+projectID+":"+value);
|
|
1175
|
|
1176
|
|
1177 #TODO: Im moment noch keine Zuordnung zu einer ID.
|
|
1178 objects.insert([value,value])
|
|
1179 self.projectObjects.update({projectID:objects})
|
|
1180
|
|
1181
|
|
1182
|
|
1183 for objectTuple in objects:
|
|
1184 #hole die abgespeicherten Projekte zu einer Person
|
|
1185 person=objectTuple[0] #hile die ID
|
|
1186
|
|
1187
|
|
1188 if getattr(self,"objects2Projects",None)==None:
|
|
1189 setattr(self,"objects2Projects",OOBTree())
|
|
1190
|
|
1191 projects = self.objects2Projects.get(person,None)
|
|
1192
|
|
1193 if projects==None:
|
|
1194 projects=OOSet();
|
|
1195
|
|
1196 projects.insert(projectID )
|
|
1197 logging.debug("update:"+person)
|
|
1198 self.objects2Projects.update({person:projects})
|
|
1199
|
|
1200
|
|
1201
|
|
1202 retstring = self.getObjectsFromProjectAsHTML(projectID)
|
|
1203 logging.debug(retstring)
|
|
1204
|
|
1205
|
|
1206
|
|
1207 return retstring
|
|
1208
|
|
1209
|
|
1210 def getProjectsWithTag(self,tagType,tagName):
|
|
1211 tags = getattr(self,"tags",None)
|
|
1212 if tags is None:
|
|
1213 logging.debug("can't find Tags")
|
|
1214 return []
|
|
1215
|
|
1216
|
|
1217
|
|
1218 tagsStored=tags.get(tagType,None)
|
|
1219 if tagsStored is None:
|
|
1220 logging.debug("can't find Tag:"+tagType)
|
|
1221 return []
|
|
1222
|
|
1223 projects = tagsStored.get(tagName,None)
|
|
1224 if projects is None:
|
|
1225 logging.debug("can't find any projects for Tag:"+tagName+"("+tagType+")")
|
|
1226 return []
|
|
1227
|
|
1228 ret=[]
|
|
1229 for project in projects:
|
|
1230 logging.debug("found:"+project)
|
|
1231 ret.append(self.getProjectDetails(project))
|
|
1232
|
|
1233 return ret
|
|
1234
|
|
1235 def getProjectDetails(self,getID):
|
|
1236 project=getattr(self.www_neu.projects,getID,None)
|
|
1237 if project is None:
|
|
1238 logging.debug("no project!! " +getID)
|
|
1239 return
|
|
1240
|
|
1241 link="/en/research/projects/"+getID
|
|
1242
|
|
1243 title=project.getContent("short_title")
|
|
1244 #persons=project.getPersonKeyList()
|
|
1245 persons=project.getContent('xdata_01')
|
|
1246 logging.debug("%s %s %s"%(link,title,persons))
|
|
1247 return link,title,persons
|
|
1248
|
|
1249 # $.post("addNewPerson",{"projectID":
|
|
1250 # $('#projectID').val(),
|
|
1251 # "personName":$("#suggest_newPerson").val(),
|
|
1252 # "personComment":$("#suggest_newPerson_comment").val()}
|
|
1253 #
|
|
1254 # );
|
|
1255 #
|
2
|
1256
|
|
1257 security.declareProtected('View management screens','addAndCreateNewPerson')
|
0
|
1258 def addAndCreateNewPerson(self,projectID,personName,personComment,personUserName):
|
|
1259 """adds anew person to the project which is not in the authority file"""
|
|
1260
|
|
1261 id = random.randint(0, 1000000);
|
|
1262 idstring="http://ontologies.mpiwg-berlin.mpg.de/tempObjects/person/"+str(id)
|
|
1263 while self.suggestedPersons.has_key(idstring):
|
|
1264 id = random.randint(0, 1000000);
|
|
1265 #idstring="http://ontologies.mpiwg-berlin.mpg.de/tempObjects/person/"+str(id);
|
|
1266 idstring=self.TEMP_PERSON_NS+str(id);
|
|
1267
|
|
1268
|
|
1269 self.suggestedPersons.update({idstring:(personName,personComment,projectID,personUserName)})
|
|
1270 self.createTempPersonInVirtuoso(projectID, idstring, personName, personComment) #TODO: add suername to the triplestore
|
|
1271 return self.addPersonToProject(projectID, idstring, personName);
|
2
|
1272
|
7
|
1273 def addSameAsRelationToTripleStore(self,personID,masterID):
|
|
1274 cmdString ="insert in GRAPH <"+self.virtuosoGraph+"> {"
|
|
1275 cmdString +="<%s> <http://www.w3.org/2002/07/owl#sameAs> <%s>."%(personID,masterID)
|
|
1276 cmdString +="<%s> <http://www.w3.org/2002/07/owl#sameAs> <%s>."%(masterID,personID)
|
|
1277 cmdString+="}"
|
|
1278
|
|
1279 auth_handler = urllib2.HTTPBasicAuthHandler()
|
|
1280 auth_handler.add_password(realm='sparql',
|
|
1281 uri=self.virtuosoServer+"/sparql",
|
|
1282 user=self.virtuosoDAVUser,
|
|
1283 passwd=self.virtuosoDAVPW)
|
|
1284
|
|
1285 opener = urllib2.build_opener(auth_handler)
|
|
1286 opener.addheaders = [('Content-Type','application/sparql-query')]
|
|
1287
|
|
1288 logging.debug(cmdString)
|
|
1289 try:
|
|
1290 r= opener.open(self.virtuosoServer+"/sparql", urllib.urlencode({'query':cmdString,'default-graph-uri':self.virtuosoGraph,'named-graph-uri':None}))
|
|
1291 logging.debug(r.read())
|
|
1292 except urllib2.URLError, e:
|
|
1293 logging.error(e.code)
|
|
1294 logging.error(e.read())
|
|
1295 return
|
|
1296
|
|
1297
|
2
|
1298 security.declareProtected('View management screens','createTempPersonInVirtuoso')
|
0
|
1299 def createTempPersonInVirtuoso(self,projectID,personURI, personName,personComment):
|
|
1300 """add a new person to the triple store of tempory persons"""
|
|
1301 triples=[];
|
|
1302 personID="<"+personURI+">"
|
|
1303 triples.append((personID,"<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>","<http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/Person>"))
|
|
1304 triples.append((personID,"<http://erlangen-crm.org/110404/P3_has_note>",'"'+personComment+'"'))
|
|
1305 triples.append((personID,"<http://xmlns.com/foaf/0.1/name>",'"'+personName+'"'))
|
|
1306 triples.append((personID,"<http://ontologies.mpiwg-berlin.mpg.de/general/isMentionedOn>","<http://www.mpiwg-berlin.mpg.de/en/research/projects/"+projectID+">"))
|
|
1307
|
|
1308 cmdString ="insert in GRAPH <"+self.virtuosoGraph+"> {"
|
|
1309 for triple in triples:
|
|
1310 cmdString+=" ".join(triple)+"."
|
|
1311
|
|
1312 cmdString+="}"
|
|
1313
|
|
1314 auth_handler = urllib2.HTTPBasicAuthHandler()
|
|
1315 auth_handler.add_password(realm='sparql',
|
|
1316 uri=self.virtuosoServer+"/sparql",
|
|
1317 user=self.virtuosoDAVUser,
|
|
1318 passwd=self.virtuosoDAVPW)
|
|
1319
|
|
1320 opener = urllib2.build_opener(auth_handler)
|
|
1321 opener.addheaders = [('Content-Type','application/sparql-query')]
|
|
1322
|
|
1323 logging.debug(cmdString)
|
|
1324 try:
|
|
1325 r= opener.open(self.virtuosoServer+"/sparql", urllib.urlencode({'query':cmdString,'default-graph-uri':self.virtuosoGraph,'named-graph-uri':None}))
|
|
1326 logging.debug(r.read())
|
|
1327 except urllib2.URLError, e:
|
|
1328 logging.error(e.code)
|
|
1329 logging.error(e.read())
|
|
1330 return
|
|
1331
|
|
1332 opener2 = urllib2.build_opener()
|
|
1333
|
|
1334
|
|
1335 personIDencoded=urllib.quote(personURI,safe="")
|
|
1336 graphEncoded=urllib.quote(self.additionalNamesGraphURL,safe="")
|
|
1337 url = self.personproviderURL+"id/"+personIDencoded+"/"+graphEncoded
|
|
1338
|
|
1339 try:
|
|
1340 request = urllib2.Request(url);
|
|
1341 request.get_method = lambda : 'PUT'
|
|
1342 r= opener2.open(request);
|
|
1343 logging.debug(r.read())
|
|
1344 except urllib2.URLError, e:
|
|
1345 logging.error(e.code)
|
|
1346 logging.error(e.read())
|
|
1347 return
|
|
1348
|
|
1349
|
|
1350
|
|
1351 return
|
|
1352
|
|
1353 def redirect(RESPONSE,url):
|
|
1354 """mache ein redirect mit einem angehaengten time stamp um ein reload zu erzwingen"""
|
|
1355
|
|
1356 timeStamp=time.time()
|
|
1357
|
|
1358 if url.find("?")>-1: #giebt es schon parameter
|
|
1359 addStr="&time=%s"
|
|
1360 else:
|
|
1361 addStr="?time=%s"
|
|
1362
|
|
1363 RESPONSE.setHeader('Last-Modified',email.Utils.formatdate().split("-")[0]+'GMT')
|
|
1364 logging.error(email.Utils.formatdate()+' GMT')
|
|
1365 RESPONSE.redirect(url+addStr%timeStamp)
|
|
1366
|
|
1367 def manage_addMPIWGThesaurusForm(self):
|
|
1368 """form for adding the project"""
|
|
1369 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMPIWGThesaurusForm.zpt')).__of__(self)
|
|
1370 return pt()
|
|
1371
|
|
1372
|
|
1373
|
|
1374 def manage_addMPIWGThesaurus(self,id,RESPONSE=None):
|
|
1375 """add it"""
|
|
1376 newObj=MPIWGThesaurus(id)
|
|
1377
|
|
1378 self._setObject(id,newObj)
|
|
1379
|
|
1380
|
|
1381 if RESPONSE is not None:
|
|
1382 redirect(RESPONSE,'manage_main') |