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