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
|
12
|
480 def getEntriesFormatted(self,entries,type):
|
|
481 errorString="<H1>template with name <em>levelFormatted</em> does not exist in the thesaurus folder!"
|
|
482 if not hasattr(self,'levelFormatted'):
|
13
|
483 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','levelFormatted.zpt')).__of__(self)
|
|
484 return pt(level1_entries=entries,type=type)
|
|
485
|
12
|
486
|
|
487 return self.levelFormatted(level1_entries=entries,type=type)
|
|
488
|
0
|
489 def getEntries(self,entry):
|
|
490 return entry.entries
|
|
491
|
1
|
492 #nimmt ein eine Text der Form
|
|
493 # TAG1
|
|
494 # ---
|
|
495 # SUBTAG1_1
|
|
496 # SUBTAG1_2
|
|
497 # ---
|
|
498 # TAG2
|
|
499 # ---
|
|
500 # SUBTAG2_1
|
|
501 # SUBTAG2_2
|
|
502 #....
|
|
503 # und erzeugt daraus eine entsprechende Liste von Entries
|
0
|
504 def getEntriesFromTxt(self,txt):
|
|
505 apps=[]
|
|
506 lines=txt.split("\n");
|
|
507 level=False
|
|
508 for line in lines:
|
|
509 line=line.rstrip().lstrip()
|
|
510 if line=="":
|
|
511 continue
|
|
512 if line=="---":
|
|
513
|
|
514 if level:
|
|
515 level=False
|
|
516 else:
|
|
517 level=True
|
|
518 else:
|
|
519 if not level:
|
|
520 entry=Entry(line,[])
|
|
521 apps.append(entry)
|
|
522 else:
|
|
523 entry.entries.append(Entry(line))
|
|
524
|
|
525 return apps[0:]
|
|
526
|
|
527 def getApproaches(self):
|
|
528
|
|
529 self.tagList=self.getEntriesFromTxt(self.approachesTxt)
|
|
530 return self.tagList
|
|
531
|
2
|
532
|
0
|
533 def getTagsJSON(self,projectID,tagType,RESPONSE=None):
|
|
534 """get all selected tagList"""
|
|
535 logging.debug("asking:"+projectID)
|
|
536 logging.debug("asking tag::"+tagType)
|
|
537 retList=[]
|
|
538 tags = getattr(self,"tags",None)
|
|
539 if tags is None:
|
|
540 return;
|
|
541
|
|
542 tagsStored=tags.get(tagType,None)
|
|
543 if tagsStored is None:
|
|
544 return;
|
|
545
|
|
546 for tag in tagsStored.keys(): #gehe durch alle gespeichteren approached
|
|
547 logging.debug("checking:"+tag)
|
|
548 currentTag = tagsStored.get(tag,None)
|
|
549 if currentTag is None:
|
|
550 continue
|
|
551 if currentTag.has_key(projectID):
|
|
552 retList.append(""" "%s" """%tag)
|
|
553
|
|
554 if RESPONSE:
|
|
555 RESPONSE.setHeader('Content-Type', "application/json")
|
|
556
|
|
557 logging.debug(retList)
|
|
558 return "["+",".join(retList)+"]"
|
|
559
|
|
560 def getDisciplines(self):
|
|
561
|
|
562 self.disciplines=self.getEntriesFromTxt(self.disciplinesTxt)
|
|
563 return self.disciplines
|
|
564
|
|
565
|
|
566 def getObjectsJSON(self,term="",RESPONSE=None):
|
|
567 """ get all stored objects as json list starting with term"""
|
|
568 term=term.lower();
|
|
569 logging.debug("Asking:"+term)
|
|
570 #objectList=["baus","berg","lurg"]
|
|
571 objects = self.objects2Projects;
|
|
572
|
|
573 objectList= [x for x in objects.keys()]
|
|
574
|
|
575 logging.debug("Create:"+repr(objectList))
|
|
576 retList=[]
|
|
577 for object in objectList:
|
|
578 if object.find(term)>-1:
|
|
579 retList.append(""" "%s" """%object)
|
|
580 ret="["
|
|
581 ret+=",".join(retList)
|
|
582 ret+="]"
|
|
583 logging.debug("Objects:"+ret)
|
|
584 if RESPONSE:
|
|
585 RESPONSE.setHeader('Content-Type', "application/json")
|
|
586 return ret
|
|
587
|
|
588
|
|
589 def getHistoricalPlacesJSON(self,term="",RESPONSE=None):
|
|
590 """ get all stored historicalPlaces as json list starting with term"""
|
|
591 term=term.lower();
|
|
592 logging.debug("Asking:"+term)
|
|
593 #historicalPlaceList=["baus","berg","lurg"]
|
|
594 historicalPlaces = self.historicalPlaces2Projects;
|
|
595
|
|
596 historicalPlaceList= [x for x in historicalPlaces.keys()]
|
|
597
|
|
598 logging.debug("Create:"+repr(historicalPlaceList))
|
|
599 retList=[]
|
|
600 for historicalPlace in historicalPlaceList:
|
|
601 if historicalPlace.find(term)>-1:
|
|
602 retList.append(""" "%s" """%historicalPlace)
|
|
603 ret="["
|
|
604 ret+=",".join(retList)
|
|
605 ret+="]"
|
|
606 logging.debug("historicalPlaces:"+ret)
|
|
607 if RESPONSE:
|
|
608 RESPONSE.setHeader('Content-Type', "application/json")
|
|
609 return ret
|
|
610
|
|
611
|
|
612 def getPeriods(self):
|
|
613
|
|
614 self.periodes=self.getEntriesFromTxt(self.periodsTxt)
|
|
615 return self.periodes
|
|
616
|
|
617 def getSpaces(self):
|
|
618
|
|
619 self.spaces=self.getEntriesFromTxt(self.spacesTxt)
|
|
620 return self.spaces
|
|
621
|
|
622 def getTechnologies(self):
|
|
623
|
|
624 self.technologies=self.getEntriesFromTxt(self.technologiesTxt)
|
|
625 return self.technologies
|
|
626
|
|
627 def getKnowledgeTransfers(self):
|
|
628
|
|
629 self.knowledgeTransfers=self.getEntriesFromTxt(self.knowledgeTransfersTxt)
|
|
630 return self.knowledgeTransfers
|
|
631
|
|
632
|
|
633 def getObjectsFromProject(self,projectID):
|
|
634 return self.getFromProject(self.projectObjects,projectID);
|
|
635
|
|
636 def getHistoricalPlacesFromProject(self,projectID):
|
|
637 return self.getFromProject(self.projectHistoricalPlaces,projectID);
|
|
638
|
|
639 def getSuggestedTagsFromProject(self,projectID):
|
|
640 return self.getFromProject(self.projectSuggestedTags,projectID);
|
|
641
|
|
642
|
|
643 def getPersonsFromProject(self,projectID):
|
5
|
644 #hole alle personenID die zu einem Projekt gehoeren.
|
|
645 #zurueckgegeben wird ein OOSet()
|
0
|
646 return self.getFromProject(self.projectPersons,projectID);
|
|
647
|
5
|
648 def getFromProject(self,objects,projectID):
|
|
649 #holt die zu projectID gehoerigen objekte aus dem objects-set.
|
|
650 #oder legt einen neuen leeren Satz zu dieser ProjektID an.
|
|
651 #zuruecgegeben wird ein OOSet()
|
|
652 if objects.has_key(projectID): #wenn zu der ProjektID schon etwas abgespeichter ist, gieb es zurueck
|
0
|
653 logging.debug("key exists:"+projectID)
|
|
654 persons=objects.get(projectID);
|
5
|
655 else: # andernfalls lege einen neuen Satz an.
|
0
|
656 persons=OOSet()
|
|
657 objects.update({projectID:persons})
|
|
658 logging.debug("key does not exists:"+projectID)
|
|
659
|
|
660
|
|
661 return persons
|
|
662
|
|
663 def getHistoricalPlacesFromProjectAsHTML(self,projectID):
|
|
664 """gertobjects"""
|
|
665 return self.getFromProjectAsHTML(self.projectHistoricalPlaces, projectID, "HistoricalPlace");
|
|
666
|
|
667 def getObjectsFromProjectAsHTML(self,projectID):
|
|
668 """gertobjects"""
|
|
669 return self.getFromProjectAsHTML(self.projectObjects, projectID, "Object");
|
|
670
|
|
671 def getPersonsFromProjectAsHTML(self,projectID):
|
|
672 """getpersons"""
|
|
673 return self.getFromProjectAsHTML(self.projectPersons, projectID, "Person");
|
|
674
|
|
675
|
|
676 def getFromProjectAsHTML(self,objects,projectID,type):
|
|
677 """getpersons"""
|
|
678 ret=""
|
|
679 if objects.has_key(projectID):
|
|
680 persons=objects.get(projectID);
|
|
681 else:
|
|
682 persons=OOSet()
|
|
683
|
|
684
|
|
685 for person in persons:
|
|
686 ret+="""<div class="removeButton">
|
|
687 <span>%s </span><div style="display:inline" class="remove%s"><span style="display:none" class="removeValue">%s</span>remove</div>
|
|
688 </div>"""%(person[1],type,person[0])
|
|
689
|
|
690
|
|
691 # ret+="""<div>
|
|
692 # <input type="checkbox" name="persons_remove"
|
|
693 # value="%s">
|
|
694 # <span>%s</span>
|
|
695 # </div>"""%(person[0],person[1])
|
|
696 #
|
|
697 logging.debug(type+":"+ret)
|
|
698 return ret
|
|
699
|
2
|
700 security.declareProtected('View management screens','removeHistoricalPlaceFromProject')
|
0
|
701 def removeHistoricalPlaceFromProject(self,projectID,value):
|
|
702 """remove"""
|
|
703 logging.debug("removeHP:"+projectID+":"+value);
|
|
704
|
|
705 HistoricalPlaces = self.getHistoricalPlacesFromProject(projectID)
|
|
706 for HistoricalPlace in HistoricalPlaces.keys():
|
|
707
|
|
708 logging.debug("trying:"+repr(HistoricalPlace[0])+"::"+repr(value)+"__")
|
|
709 if HistoricalPlace[0]==value:
|
|
710 logging.debug("---removed!")
|
|
711 HistoricalPlaces.remove(HistoricalPlace)
|
|
712
|
|
713 self.projectHistoricalPlaces.update({projectID:HistoricalPlaces})
|
|
714 retstring = self.getHistoricalPlacesFromProjectAsHTML(projectID)
|
|
715 logging.debug(retstring)
|
|
716 return retstring
|
|
717
|
2
|
718 security.declareProtected('View management screens','removeObjectFromProject')
|
0
|
719 def removeObjectFromProject(self,projectID,value):
|
|
720 """remove"""
|
|
721 logging.debug("remove:"+projectID+":"+value);
|
|
722
|
|
723 objects = self.getObjectsFromProject(projectID)
|
|
724 for object in objects.keys():
|
|
725
|
|
726 logging.debug("trying:"+repr(object[0])+"::"+repr(value)+"__")
|
|
727 if object[0]==value:
|
|
728 logging.debug("---removed!")
|
|
729 objects.remove(object)
|
|
730
|
|
731 self.projectObjects.update({projectID:objects})
|
|
732 retstring = self.getObjectsFromProjectAsHTML(projectID)
|
|
733 logging.debug(retstring)
|
|
734 return retstring
|
|
735
|
2
|
736 security.declareProtected('View management screens','removePersonFromProject')
|
0
|
737 def removePersonFromProject(self,projectID,value):
|
5
|
738 """remove a person from the projeckt"""
|
0
|
739 logging.debug("remove:"+projectID+":"+value);
|
|
740
|
5
|
741 persons = self.getPersonsFromProject(projectID) # hole alle personen die mit dem Projekt verbunden sind.
|
0
|
742 for person in persons.keys():
|
|
743
|
|
744 logging.debug("trying:"+repr(person[0])+"::"+repr(value)+"__")
|
5
|
745 if person[0]==value:#person ist die zuloeschende, dann raus damit
|
|
746
|
0
|
747 logging.debug("---removed!")
|
|
748 persons.remove(person)
|
5
|
749
|
|
750 #now also delete the project from the person.
|
|
751 projectsOfPerson=self.persons2Projects.get(person[0])
|
|
752 logging.debug(projectsOfPerson)
|
|
753 if projectID in list(projectsOfPerson):
|
|
754 projectsOfPerson.remove(projectID)
|
|
755 #self.persons2Projects.update({person:projectsList})
|
|
756 if (len(projectsOfPerson)==0): #loesche person aus der liste wenn keine Projekte dazu existieren.
|
|
757 del self.persons2Projects[person[0]]
|
|
758
|
|
759
|
|
760 #self.projectPersons.update({projectID:persons})
|
0
|
761 retstring = self.getPersonsFromProjectAsHTML(projectID)
|
|
762 logging.debug(retstring)
|
|
763 return retstring
|
|
764
|
11
|
765
|
|
766 #fuegt die neue Person zur personIDtoNames hinzu, fuer die spaetere Anzeige in der Personenliste
|
0
|
767 def addNameTOPersonIDNames(self,personID,label):
|
|
768 personName = self.personIDtoNames.get(personID)
|
|
769 if personName==None: # Anlegen falls noch nicht existent
|
|
770 personName=(label,[])
|
|
771 else:
|
|
772 if (not label in personName[1]) and (not label==personName[0]): # hinzufuegen falls der neuen name noch nicht als bezeichnugn fuer personID eingetragen ist
|
|
773 personName[1].append(label)
|
|
774
|
|
775 self.personIDtoNames.update({personID:personName})
|
|
776
|
2
|
777 security.declareProtected('View management screens','addPersonToProject')
|
0
|
778 def addPersonToProject(self,projectID,value,label):
|
|
779 """ add a person so the project"""
|
|
780 persons=self.getPersonsFromProject(projectID);
|
|
781
|
|
782 logging.debug("adding:"+projectID+":"+value+":"+label);
|
|
783
|
|
784 persons.insert([value,label])
|
|
785 self.projectPersons.update({projectID:persons})
|
|
786
|
|
787 for personTuple in persons:
|
|
788 #hole die abgespeicherten Projekte zu einer Person
|
|
789 person=personTuple[0] #hole die ID
|
|
790
|
|
791
|
|
792 if getattr(self,"persons2Projects",None)==None:
|
|
793 setattr(self,"persons2Projects",OOBTree())
|
|
794
|
|
795 projects = self.persons2Projects.get(person,None)
|
7
|
796 logging.debug("found projects:"+ repr(projects))
|
|
797 if projects is None: #person hatte noch keine projekte
|
0
|
798 projects=OOSet();
|
5
|
799
|
0
|
800 projects.insert(projectID )
|
|
801 logging.debug("update:"+person)
|
|
802 self.persons2Projects.update({person:projects})
|
7
|
803
|
|
804 self.addPersonAndFirstNameFromTripleStore(person)
|
|
805 self.generateSortingOrderForPersonIDs();
|
|
806
|
0
|
807 self.addNameTOPersonIDNames(value,label)
|
|
808 retstring = self.getPersonsFromProjectAsHTML(projectID)
|
|
809 logging.debug(retstring)
|
|
810 transaction.commit()
|
|
811 return retstring
|
|
812
|
7
|
813
|
|
814
|
|
815 def rearangePersonIDsHTML(self,REQUEST=None):
|
|
816 """setze neue ID zu personen"""
|
|
817 ret=[]
|
|
818 for personID in self.persons2Projects.keys():
|
|
819 logging.debug(personID)
|
|
820
|
|
821 masterID,name=self.findMasterIDAndName(personID.rstrip().lstrip())
|
|
822 logging.debug(" masterID -appending")
|
|
823 logging.debug(repr(name))
|
|
824 if len(name)==0:
|
|
825 name=['']
|
|
826 ret.append((personID,self.personIDtoNames.get(personID,[''])[0],masterID,self.personIDtoNames.get(masterID,name)[0]))
|
|
827
|
|
828
|
|
829 if REQUEST:
|
|
830 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','rearrangePersons.zpt')).__of__(self)
|
8
|
831 return pt(changeList=ret,lookupUrl=self.PERSONS_LOOKUP_URL,editURL=self.EDIT_URL);
|
7
|
832 else:
|
|
833 return ret;
|
|
834
|
|
835 def rearangePersonIDs(self,REQUEST):
|
|
836 """unify a list of persons"""
|
|
837
|
|
838 argv=REQUEST.form;
|
|
839 logging.debug(repr(argv))
|
|
840 changes=argv['changes']
|
|
841 if isinstance(changes,str):
|
|
842 changes=[changes]
|
|
843
|
|
844 changeList=self.rearangePersonIDsHTML()
|
|
845 personToMaster={}
|
|
846 logging.debug("changelist:"+repr(changeList))
|
|
847 #aendere person2project
|
|
848 for change in changes:
|
|
849 changeItem=changeList[int(change)];
|
|
850 masterID=argv['newID_'+change].lstrip().rstrip() #make sure no spaces
|
|
851 personID=changeItem[0]
|
|
852
|
|
853 personToMaster[personID]=masterID
|
|
854 masterIDProjects = self.persons2Projects.get(masterID,None);
|
|
855 if masterIDProjects==None:
|
|
856 masterIDProjects=OOSet();
|
|
857 #ret.append((personID,self.personIDtoNames.get(personID,[''])[0],masterID,self.personIDtoNames.get(masterID,[''])[0]))
|
|
858
|
|
859 oldProjects= self.persons2Projects.get(personID)
|
|
860 logging.debug("personID:"+repr(personID))
|
|
861 logging.debug("masterID:"+repr(masterID))
|
|
862 logging.debug("keys:"+repr(self.persons2Projects.keys()))
|
|
863 logging.debug("oldProjects:"+repr(oldProjects))
|
|
864 masterIDProjects.update(oldProjects)
|
|
865 self.persons2Projects.update({masterID:masterIDProjects})
|
|
866 self.persons2Projects.pop(personID)
|
|
867
|
|
868 self.addPersonAndFirstNameFromTripleStore(masterID) #addpersontotiplestore
|
|
869
|
|
870 logging.debug("Change:" +personID+":"+ masterID)
|
|
871
|
|
872 if personID!=masterID:
|
|
873 self.addSameAsRelationToTripleStore(personID,masterID)
|
|
874
|
|
875 #aendere nun projectperson
|
|
876 logging.debug(personToMaster)
|
|
877 for project in self.projectPersons.keys():
|
|
878 personsNew=OOSet()
|
|
879
|
|
880 persons=self.projectPersons.get(project)
|
|
881 for person in persons:
|
|
882 personsNew.insert([personToMaster.get(person[0],person[0]),person[1]])
|
|
883 logging.debug("REPLACE in:"+project+":" +repr(person)+" by "+ repr(personToMaster.get(person[0],person[0])))
|
|
884 self.projectPersons.update({project:personsNew})
|
|
885
|
|
886 self.generateSortingOrderForPersonIDs(); #now sort the new names
|
|
887 return personToMaster
|
|
888 #fuehre personen zusammen die ueber owl:sameAs verbunden sind
|
|
889 def getUnifyPersonsList(self,REQUEST=None):
|
|
890 """vereinheitlichung der personen auf eine ID aus der GND, wenn moeglich"""
|
|
891 ret=[]
|
|
892 for personID in self.persons2Projects.keys():
|
|
893 masterID,name=self.findMasterIDAndName(personID)
|
|
894 logging.debug("masterID:"+masterID)
|
|
895 if (masterID is not None) and (masterID is not "") and (not personID==masterID):
|
|
896 #masterIDProjects = self.persons2Projects.get(masterID,None);
|
|
897 ##if masterIDProjects==None:
|
|
898 # masterIDProjects=OOSet();
|
|
899 logging.debug(" masterID -appending")
|
|
900 logging.debug(repr(name))
|
|
901
|
|
902
|
|
903 ret.append((personID,self.personIDtoNames.get(personID,[''])[0],masterID,self.personIDtoNames.get(masterID,name)[0]))
|
|
904 #masterIDProjects.update(self.persons2Projects.get(personID));
|
|
905 #self.persons2Projects.update({masterID:masterIDProjects});
|
|
906
|
|
907
|
|
908 if REQUEST:
|
|
909 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','unifyPersons.zpt')).__of__(self)
|
|
910 return pt(changeList=ret);
|
|
911
|
|
912 else:
|
|
913 return ret;
|
|
914
|
|
915 def unifyPersons(self,changes,REQUEST=None):
|
|
916 """unify a list of persons"""
|
|
917
|
|
918 if isinstance(changes,str):
|
|
919 changes=[changes]
|
|
920
|
|
921 changeList=self.getUnifyPersonsList();
|
|
922 personToMaster={}
|
|
923 logging.debug("changelist:"+repr(changeList))
|
|
924 #aendere person2project
|
|
925 for change in changes:
|
|
926 changeItem=changeList[int(change)];
|
|
927 masterID=changeItem[2]
|
|
928 personID=changeItem[0]
|
|
929
|
|
930 personToMaster[personID]=masterID
|
|
931 masterIDProjects = self.persons2Projects.get(masterID,None);
|
|
932 if masterIDProjects==None:
|
|
933 masterIDProjects=OOSet();
|
|
934 #ret.append((personID,self.personIDtoNames.get(personID,[''])[0],masterID,self.personIDtoNames.get(masterID,[''])[0]))
|
|
935
|
|
936 oldProjects= self.persons2Projects.get(personID)
|
|
937 logging.debug("personID:"+repr(personID))
|
|
938 logging.debug("masterID:"+repr(masterID))
|
|
939 logging.debug("keys:"+repr(self.persons2Projects.keys()))
|
|
940 logging.debug("oldProjects:"+repr(oldProjects))
|
|
941 masterIDProjects.update(oldProjects)
|
|
942 self.persons2Projects.update({masterID:masterIDProjects})
|
|
943 self.persons2Projects.pop(personID)
|
|
944
|
|
945 self.addPersonAndFirstNameFromTripleStore(masterID) #addpersontotiplestore
|
|
946
|
|
947 logging.debug("Change:" +personID+":"+ masterID)
|
|
948
|
|
949 #aendere nun projectperson
|
|
950 logging.debug(personToMaster)
|
|
951 for project in self.projectPersons.keys():
|
|
952 personsNew=OOSet()
|
|
953
|
|
954 persons=self.projectPersons.get(project)
|
|
955 for person in persons:
|
|
956 personsNew.insert([personToMaster.get(person[0],person[0]),person[1]])
|
|
957 logging.debug("REPLACE in:"+project+":" +repr(person)+" by "+ repr(personToMaster.get(person[0],person[0])))
|
|
958 self.projectPersons.update({project:personsNew})
|
|
959
|
|
960 self.generateSortingOrderForPersonIDs(); #now sort the new names
|
|
961 return personToMaster
|
|
962
|
|
963
|
|
964
|
|
965 def findMasterIDAndName(self,ressourceID):
|
|
966 queryString="""select *
|
|
967 FROM <file://mpiwg_persons_dnb.rdf>
|
|
968 FROM <file://mpiwg_persons_2.rdf>
|
|
969 FROM <file:///GND.rdf>
|
|
970 FROM <http://identifiedNames>
|
|
971 where {
|
|
972 ?person <http://www.w3.org/2002/07/owl#sameAs> <%s>.
|
|
973
|
|
974 ?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person.
|
|
975 ?gnd crm:P1_is_identified_by ?ident.
|
|
976
|
|
977 ?gnd <http://RDVocab.info/ElementsGr2/dateOfBirth> ?birthDate.
|
|
978 ?gnd <http://RDVocab.info/ElementsGr2/dateOfDeath> ?deathDate.
|
|
979 ?person <http://xmlns.com/foaf/0.1/name> ?name.
|
|
980 ?person <http://xmlns.com/foaf/0.1/lastName> ?lastName.
|
|
981 ?person <http://xmlns.com/foaf/0.1/firstName> ?firstName.
|
|
982 }
|
|
983 """%ressourceID
|
|
984 entries = self.callSparqlAll(queryString);
|
|
985 if len(entries)>0:
|
|
986 return entries[0][0],entries[0][5:8] #nur den ersten Treffer und nur die personID
|
|
987
|
|
988
|
|
989 return None,None
|
|
990
|
9
|
991 security.declareProtected('View','getPersonsWithProjectIDs')
|
5
|
992 def getPersonsWithProjectIDs(self,check=False):
|
0
|
993 """holt die getaggted Personen mit Projekten"""
|
|
994 persons = self.persons2Projects;
|
|
995 ret={}
|
4
|
996
|
0
|
997 logging.debug("Check Person:"+repr(persons.keys()))
|
4
|
998 personsList=[x for x in persons.keys()]
|
|
999
|
|
1000 def sort(x,y):
|
7
|
1001 try:
|
|
1002 sortNrx=self.personsIDForSort.index(x)
|
|
1003 except:
|
|
1004 logging.warn("couldn't find personsIDForSort:"+x)
|
|
1005 sortNrx=0
|
|
1006
|
|
1007 try:
|
|
1008 sortNry=self.personsIDForSort.index(y)
|
|
1009 except:
|
|
1010 logging.warn("couldn't find personsIDForSort:"+y)
|
|
1011 sortNry=0
|
4
|
1012 #logging.debug("INSORT***")
|
|
1013 #logging.debug((sortNrx,sortNry))
|
|
1014 return cmp(sortNrx,sortNry)
|
|
1015
|
|
1016 logging.debug("SORT***")
|
|
1017 logging.debug(self.personsIDForSort)
|
|
1018 logging.debug("SORT.list")
|
|
1019 logging.debug(personsList)
|
|
1020 personsList.sort(cmp=sort)
|
|
1021 #for person in persons.keys():
|
|
1022 logging.debug("AFTERSORT***")
|
|
1023 logging.debug(personsList)
|
|
1024 for person in personsList:
|
0
|
1025 logging.debug("Check:"+person)
|
4
|
1026 #TODO: person muss duch den namen von provider geholt werden
|
5
|
1027 retlist=[]
|
|
1028 projectsList=persons.get(person)
|
7
|
1029 if projectsList is None:
|
|
1030 projectsList=[]
|
5
|
1031 for projectID in list(projectsList): #list notwendig da projectList in der folgenden iteration veraendert wird.
|
|
1032 if check: #teste ob im Projekt noch ein Verweis auf den Namen steht
|
|
1033 #sollte eigentlich nicht sein.
|
|
1034 personsProjects=self.getPersonsFromProject(projectID)
|
|
1035 logging.debug("persons check mode")
|
|
1036 personsProjectsCheck=[x[0] for x in personsProjects]
|
|
1037 if not person in personsProjectsCheck: #falls es so ist korrigiere die Projektliste der Person
|
|
1038 #loesche die person von projectListe
|
|
1039 projectsList.remove(projectID)
|
|
1040 persons.update({person:projectsList})
|
|
1041
|
|
1042 retlist.append(self.getProjectDetails(projectID))
|
|
1043
|
|
1044 if check and (len(projectsList)==0): #loesche person aus der liste wenn keine Projekte dazu existieren.
|
|
1045 del persons[person]
|
|
1046
|
|
1047 ret[person]=retlist[0:]
|
4
|
1048
|
|
1049 logging.debug("AFTERSORT-ret***")
|
|
1050 logging.debug(ret.keys())
|
|
1051 return ret,personsList
|
0
|
1052
|
|
1053 def getHistoricalPlacesWithProjectIDs(self):
|
|
1054 """holt die getaggted Personen mit Projekten"""
|
|
1055 HistoricalPlaces = self.HistoricalPlaces2Projects;
|
|
1056 ret={}
|
|
1057 logging.debug("Check HistoricalPlace:"+repr(HistoricalPlaces.keys()))
|
|
1058 for HistoricalPlace in HistoricalPlaces.keys():
|
|
1059 logging.debug("Check:"+HistoricalPlace)
|
|
1060 #TODO: HistoricalPlace muss duch den namen von provuder geholt werden
|
|
1061 list=[]
|
|
1062 for projectID in HistoricalPlaces.get(HistoricalPlace):
|
|
1063 list.append(self.getProjectDetails(projectID))
|
|
1064
|
|
1065 ret[HistoricalPlace]=list[0:]
|
|
1066 return ret
|
|
1067
|
12
|
1068 def getObjectsWithProjectIDsSortedkeys(self):
|
|
1069
|
|
1070 def sortF(x,y):
|
|
1071 return cmp(x.lower(),y.lower())
|
|
1072 keys = [x for x in self.getObjectsWithProjectIDs().keys()]
|
|
1073 keys.sort(sortF)
|
|
1074 return keys
|
|
1075
|
0
|
1076 def getObjectsWithProjectIDs(self):
|
|
1077 """holt die getaggted Personen mit Projekten"""
|
|
1078 objects = self.objects2Projects;
|
|
1079 ret={}
|
|
1080 logging.debug("Check Object:"+repr(objects.keys()))
|
|
1081 for object in objects.keys():
|
|
1082 logging.debug("Check:"+object)
|
|
1083 #TODO: object muss duch den namen von provuder geholt werden
|
|
1084 list=[]
|
|
1085 for projectID in objects.get(object):
|
|
1086 list.append(self.getProjectDetails(projectID))
|
|
1087
|
|
1088 ret[object]=list[0:]
|
|
1089 return ret
|
|
1090
|
2
|
1091 security.declareProtected('View management screens','listAllSuggestedTags')
|
0
|
1092 def listAllSuggestedTags(self):
|
|
1093 """list all tags"""
|
|
1094 ret="<html><body>"
|
|
1095 for projectID in self.projectSuggestedTags:
|
|
1096 ret+="<h3>"+projectID+"</h3><table>"
|
|
1097 for tags in self.projectSuggestedTags.get(projectID):
|
|
1098 ret+="<tr><td>"+tags[0]+"</td><td>"+tags[1].type+"</td><td>"+tags[1].comment+"</td><td>"+tags[1].userName+"</td></tr>"
|
|
1099 ret+="</table>"
|
|
1100 ret+="</body></html>"
|
|
1101 logging.debug(ret);
|
|
1102 return ret
|
2
|
1103
|
|
1104 security.declareProtected('View management screens','suggestTag')
|
0
|
1105 def suggestTag(self,projectID,tagName,tagComment,tagType,tagUserName):
|
|
1106 """suggest a new tag"""
|
|
1107 """ add a person so the project"""
|
|
1108 SuggestedTags=self.getSuggestedTagsFromProject(projectID);
|
|
1109
|
|
1110 logging.debug("suggested:"+projectID+":"+tagName);
|
|
1111
|
|
1112
|
|
1113 #TODO: Im moment noch keine Zuordnung zu einer ID.
|
|
1114 newTag = SuggestedTag(tagName,tagComment,tagType,tagUserName)
|
|
1115 SuggestedTags.insert([tagName,newTag])
|
|
1116 self.projectSuggestedTags.update({projectID:SuggestedTags})
|
|
1117
|
|
1118
|
|
1119
|
|
1120 for SuggestedTagTuple in SuggestedTags:
|
|
1121 #hole die abgespeicherten Projekte zu einer Person
|
|
1122 person=SuggestedTagTuple[0] #hile die ID
|
|
1123
|
|
1124
|
|
1125 if getattr(self,"SuggestedTags2Projects",None)==None:
|
|
1126 setattr(self,"SuggestedTags2Projects",OOBTree())
|
|
1127
|
|
1128 projects = self.SuggestedTags2Projects.get(person,None)
|
|
1129
|
|
1130 if projects==None:
|
|
1131 projects=OOSet();
|
|
1132
|
|
1133 projects.insert(projectID )
|
|
1134 logging.debug("update:"+person)
|
|
1135 self.SuggestedTags2Projects.update({person:projects})
|
|
1136
|
|
1137
|
|
1138
|
|
1139 #retstring = self.getSuggestedTagsFromProjectAsHTML(projectID)
|
|
1140 #logging.debug(retstring)
|
|
1141
|
|
1142
|
|
1143
|
|
1144 #return retstring
|
|
1145
|
2
|
1146 security.declareProtected('View management screens','addHistoricalPlaceToProject')
|
0
|
1147 def addHistoricalPlaceToProject(self,projectID,value):
|
|
1148 """ add a person so the project"""
|
|
1149 HistoricalPlaces=self.getHistoricalPlacesFromProject(projectID);
|
|
1150
|
|
1151 logging.debug("adding:"+projectID+":"+value);
|
|
1152
|
|
1153
|
|
1154 #TODO: Im moment noch keine Zuordnung zu einer ID.
|
|
1155 HistoricalPlaces.insert([value,value])
|
|
1156 self.projectHistoricalPlaces.update({projectID:HistoricalPlaces})
|
|
1157
|
|
1158
|
|
1159
|
|
1160 for HistoricalPlaceTuple in HistoricalPlaces:
|
|
1161 #hole die abgespeicherten Projekte zu einer Person
|
|
1162 person=HistoricalPlaceTuple[0] #hile die ID
|
|
1163
|
|
1164
|
|
1165 if getattr(self,"HistoricalPlaces2Projects",None)==None:
|
|
1166 setattr(self,"HistoricalPlaces2Projects",OOBTree())
|
|
1167
|
|
1168 projects = self.HistoricalPlaces2Projects.get(person,None)
|
|
1169
|
|
1170 if projects==None:
|
|
1171 projects=OOSet();
|
|
1172
|
|
1173 projects.insert(projectID )
|
|
1174 logging.debug("update:"+person)
|
|
1175 self.HistoricalPlaces2Projects.update({person:projects})
|
|
1176
|
|
1177
|
|
1178
|
|
1179 retstring = self.getHistoricalPlacesFromProjectAsHTML(projectID)
|
|
1180 logging.debug(retstring)
|
|
1181
|
|
1182
|
|
1183
|
|
1184 return retstring
|
|
1185
|
2
|
1186 security.declareProtected('View management screens','addObjectToProject')
|
0
|
1187 def addObjectToProject(self,projectID,value):
|
|
1188 """ add a person so the project"""
|
|
1189 objects=self.getObjectsFromProject(projectID);
|
|
1190
|
|
1191 logging.debug("adding:"+projectID+":"+value);
|
|
1192
|
|
1193
|
|
1194 #TODO: Im moment noch keine Zuordnung zu einer ID.
|
|
1195 objects.insert([value,value])
|
|
1196 self.projectObjects.update({projectID:objects})
|
|
1197
|
|
1198
|
|
1199
|
|
1200 for objectTuple in objects:
|
|
1201 #hole die abgespeicherten Projekte zu einer Person
|
|
1202 person=objectTuple[0] #hile die ID
|
|
1203
|
|
1204
|
|
1205 if getattr(self,"objects2Projects",None)==None:
|
|
1206 setattr(self,"objects2Projects",OOBTree())
|
|
1207
|
|
1208 projects = self.objects2Projects.get(person,None)
|
|
1209
|
|
1210 if projects==None:
|
|
1211 projects=OOSet();
|
|
1212
|
|
1213 projects.insert(projectID )
|
|
1214 logging.debug("update:"+person)
|
|
1215 self.objects2Projects.update({person:projects})
|
|
1216
|
|
1217
|
|
1218
|
|
1219 retstring = self.getObjectsFromProjectAsHTML(projectID)
|
|
1220 logging.debug(retstring)
|
|
1221
|
|
1222
|
|
1223
|
|
1224 return retstring
|
|
1225
|
|
1226
|
|
1227 def getProjectsWithTag(self,tagType,tagName):
|
|
1228 tags = getattr(self,"tags",None)
|
|
1229 if tags is None:
|
|
1230 logging.debug("can't find Tags")
|
|
1231 return []
|
|
1232
|
|
1233
|
|
1234
|
|
1235 tagsStored=tags.get(tagType,None)
|
|
1236 if tagsStored is None:
|
|
1237 logging.debug("can't find Tag:"+tagType)
|
|
1238 return []
|
|
1239
|
|
1240 projects = tagsStored.get(tagName,None)
|
|
1241 if projects is None:
|
|
1242 logging.debug("can't find any projects for Tag:"+tagName+"("+tagType+")")
|
|
1243 return []
|
|
1244
|
|
1245 ret=[]
|
|
1246 for project in projects:
|
|
1247 logging.debug("found:"+project)
|
|
1248 ret.append(self.getProjectDetails(project))
|
|
1249
|
|
1250 return ret
|
|
1251
|
|
1252 def getProjectDetails(self,getID):
|
|
1253 project=getattr(self.www_neu.projects,getID,None)
|
|
1254 if project is None:
|
|
1255 logging.debug("no project!! " +getID)
|
|
1256 return
|
|
1257
|
|
1258 link="/en/research/projects/"+getID
|
|
1259
|
|
1260 title=project.getContent("short_title")
|
|
1261 #persons=project.getPersonKeyList()
|
|
1262 persons=project.getContent('xdata_01')
|
|
1263 logging.debug("%s %s %s"%(link,title,persons))
|
|
1264 return link,title,persons
|
|
1265
|
|
1266 # $.post("addNewPerson",{"projectID":
|
|
1267 # $('#projectID').val(),
|
|
1268 # "personName":$("#suggest_newPerson").val(),
|
|
1269 # "personComment":$("#suggest_newPerson_comment").val()}
|
|
1270 #
|
|
1271 # );
|
|
1272 #
|
2
|
1273
|
|
1274 security.declareProtected('View management screens','addAndCreateNewPerson')
|
0
|
1275 def addAndCreateNewPerson(self,projectID,personName,personComment,personUserName):
|
|
1276 """adds anew person to the project which is not in the authority file"""
|
|
1277
|
|
1278 id = random.randint(0, 1000000);
|
|
1279 idstring="http://ontologies.mpiwg-berlin.mpg.de/tempObjects/person/"+str(id)
|
|
1280 while self.suggestedPersons.has_key(idstring):
|
|
1281 id = random.randint(0, 1000000);
|
|
1282 #idstring="http://ontologies.mpiwg-berlin.mpg.de/tempObjects/person/"+str(id);
|
|
1283 idstring=self.TEMP_PERSON_NS+str(id);
|
|
1284
|
|
1285
|
|
1286 self.suggestedPersons.update({idstring:(personName,personComment,projectID,personUserName)})
|
|
1287 self.createTempPersonInVirtuoso(projectID, idstring, personName, personComment) #TODO: add suername to the triplestore
|
|
1288 return self.addPersonToProject(projectID, idstring, personName);
|
2
|
1289
|
7
|
1290 def addSameAsRelationToTripleStore(self,personID,masterID):
|
|
1291 cmdString ="insert in GRAPH <"+self.virtuosoGraph+"> {"
|
|
1292 cmdString +="<%s> <http://www.w3.org/2002/07/owl#sameAs> <%s>."%(personID,masterID)
|
|
1293 cmdString +="<%s> <http://www.w3.org/2002/07/owl#sameAs> <%s>."%(masterID,personID)
|
|
1294 cmdString+="}"
|
|
1295
|
|
1296 auth_handler = urllib2.HTTPBasicAuthHandler()
|
|
1297 auth_handler.add_password(realm='sparql',
|
|
1298 uri=self.virtuosoServer+"/sparql",
|
|
1299 user=self.virtuosoDAVUser,
|
|
1300 passwd=self.virtuosoDAVPW)
|
|
1301
|
|
1302 opener = urllib2.build_opener(auth_handler)
|
|
1303 opener.addheaders = [('Content-Type','application/sparql-query')]
|
|
1304
|
|
1305 logging.debug(cmdString)
|
|
1306 try:
|
|
1307 r= opener.open(self.virtuosoServer+"/sparql", urllib.urlencode({'query':cmdString,'default-graph-uri':self.virtuosoGraph,'named-graph-uri':None}))
|
|
1308 logging.debug(r.read())
|
|
1309 except urllib2.URLError, e:
|
|
1310 logging.error(e.code)
|
|
1311 logging.error(e.read())
|
|
1312 return
|
|
1313
|
|
1314
|
2
|
1315 security.declareProtected('View management screens','createTempPersonInVirtuoso')
|
0
|
1316 def createTempPersonInVirtuoso(self,projectID,personURI, personName,personComment):
|
|
1317 """add a new person to the triple store of tempory persons"""
|
|
1318 triples=[];
|
|
1319 personID="<"+personURI+">"
|
|
1320 triples.append((personID,"<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>","<http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/Person>"))
|
|
1321 triples.append((personID,"<http://erlangen-crm.org/110404/P3_has_note>",'"'+personComment+'"'))
|
|
1322 triples.append((personID,"<http://xmlns.com/foaf/0.1/name>",'"'+personName+'"'))
|
|
1323 triples.append((personID,"<http://ontologies.mpiwg-berlin.mpg.de/general/isMentionedOn>","<http://www.mpiwg-berlin.mpg.de/en/research/projects/"+projectID+">"))
|
|
1324
|
|
1325 cmdString ="insert in GRAPH <"+self.virtuosoGraph+"> {"
|
|
1326 for triple in triples:
|
|
1327 cmdString+=" ".join(triple)+"."
|
|
1328
|
|
1329 cmdString+="}"
|
|
1330
|
|
1331 auth_handler = urllib2.HTTPBasicAuthHandler()
|
|
1332 auth_handler.add_password(realm='sparql',
|
|
1333 uri=self.virtuosoServer+"/sparql",
|
|
1334 user=self.virtuosoDAVUser,
|
|
1335 passwd=self.virtuosoDAVPW)
|
|
1336
|
|
1337 opener = urllib2.build_opener(auth_handler)
|
|
1338 opener.addheaders = [('Content-Type','application/sparql-query')]
|
|
1339
|
|
1340 logging.debug(cmdString)
|
|
1341 try:
|
|
1342 r= opener.open(self.virtuosoServer+"/sparql", urllib.urlencode({'query':cmdString,'default-graph-uri':self.virtuosoGraph,'named-graph-uri':None}))
|
|
1343 logging.debug(r.read())
|
|
1344 except urllib2.URLError, e:
|
|
1345 logging.error(e.code)
|
|
1346 logging.error(e.read())
|
|
1347 return
|
|
1348
|
|
1349 opener2 = urllib2.build_opener()
|
|
1350
|
|
1351
|
|
1352 personIDencoded=urllib.quote(personURI,safe="")
|
|
1353 graphEncoded=urllib.quote(self.additionalNamesGraphURL,safe="")
|
|
1354 url = self.personproviderURL+"id/"+personIDencoded+"/"+graphEncoded
|
|
1355
|
|
1356 try:
|
|
1357 request = urllib2.Request(url);
|
|
1358 request.get_method = lambda : 'PUT'
|
|
1359 r= opener2.open(request);
|
|
1360 logging.debug(r.read())
|
|
1361 except urllib2.URLError, e:
|
|
1362 logging.error(e.code)
|
|
1363 logging.error(e.read())
|
|
1364 return
|
|
1365
|
|
1366
|
|
1367
|
|
1368 return
|
|
1369
|
|
1370 def redirect(RESPONSE,url):
|
|
1371 """mache ein redirect mit einem angehaengten time stamp um ein reload zu erzwingen"""
|
|
1372
|
|
1373 timeStamp=time.time()
|
|
1374
|
|
1375 if url.find("?")>-1: #giebt es schon parameter
|
|
1376 addStr="&time=%s"
|
|
1377 else:
|
|
1378 addStr="?time=%s"
|
|
1379
|
|
1380 RESPONSE.setHeader('Last-Modified',email.Utils.formatdate().split("-")[0]+'GMT')
|
|
1381 logging.error(email.Utils.formatdate()+' GMT')
|
|
1382 RESPONSE.redirect(url+addStr%timeStamp)
|
|
1383
|
|
1384 def manage_addMPIWGThesaurusForm(self):
|
|
1385 """form for adding the project"""
|
|
1386 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMPIWGThesaurusForm.zpt')).__of__(self)
|
|
1387 return pt()
|
|
1388
|
|
1389
|
|
1390
|
|
1391 def manage_addMPIWGThesaurus(self,id,RESPONSE=None):
|
|
1392 """add it"""
|
|
1393 newObj=MPIWGThesaurus(id)
|
|
1394
|
|
1395 self._setObject(id,newObj)
|
|
1396
|
|
1397
|
|
1398 if RESPONSE is not None:
|
|
1399 redirect(RESPONSE,'manage_main') |