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