Mercurial > hg > MPIWGWeb
annotate MPIWGStaff.py @ 100:f4ac675b2031
more members pages.
author | casties |
---|---|
date | Tue, 21 May 2013 18:50:05 +0200 |
parents | 48e88706cfc3 |
children | 7dd264f9b728 |
rev | line source |
---|---|
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1 """This file contains the classes for the organization of the staff""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
2 |
3 | 3 from zExceptions import Redirect |
4 | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
5 from OFS.Folder import Folder |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
6 from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
7 |
3 | 8 from AccessControl import ClassSecurityInfo |
9 from App.class_init import InitializeClass | |
37 | 10 from Products.ExtFile.ExtFile import * |
86 | 11 from Globals import package_home |
12 from Products.PythonScripts.standard import sql_quote | |
13 from Products.ExtFile import ExtFile | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
14 import os |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
15 import logging |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
16 import email |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
17 import re |
86 | 18 |
19 from Products.ZDBInterface.ZDBInterfaceFolder import ZDBInterfaceFolder | |
2 | 20 |
28 | 21 from SrvTxtUtils import getHttpData, getAt, getInt, unicodify, utf8ify |
86 | 22 import MPIWGHelper |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
23 |
86 | 24 # |
25 # compatibility | |
26 # TODO: should be removed when done | |
27 import MPIWGStaff_old | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
28 |
86 | 29 createNewDBEntry = MPIWGStaff_old.createNewDBEntry |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
30 |
86 | 31 class MPIWGStaff(MPIWGStaff_old.MPIWGStaff): |
32 """Staff""" | |
33 pass | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
34 |
86 | 35 manage_addMPIWGStaffForm = MPIWGStaff_old.manage_addMPIWGStaffForm |
36 manage_addMPIWGStaff = MPIWGStaff_old.manage_addMPIWGStaff | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
37 |
3 | 38 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
39 |
2 | 40 class MPIWGStaffFolder(ZDBInterfaceFolder): |
41 """Folder of staff objects""" | |
42 | |
43 meta_type="MPIWGStaffFolder" | |
44 security=ClassSecurityInfo() | |
3 | 45 |
46 # | |
47 # templates | |
48 # | |
49 member_index_html = PageTemplateFile('zpt/staff/member_index_html', globals()) | |
50 | |
51 | |
52 # | |
53 # hook into traversal to create folder of virtual staff objects | |
54 # like /members/$username/index_html | |
55 # | |
56 def __before_publishing_traverse__(self, object, request): | |
57 stack = request.TraversalRequestNameStack | |
58 logging.debug("MPIWGStaffFolder: traverse stack=%s self=%s"%(repr(stack),repr(self))) | |
59 | |
60 # TODO: should we do more checks? | |
61 if stack and len(stack) > 0: | |
62 try: | |
63 # id is the first path component | |
64 id = stack[-1] | |
37 | 65 logging.debug(id) |
66 | |
86 | 67 member = self.getMember(username=id) |
3 | 68 if member is not None: |
37 | 69 member = member.__of__(self) |
3 | 70 request.set('MPIWGStaffMember', member) |
71 stack.pop(-1) | |
72 | |
37 | 73 #weitere parameter |
74 if len(stack)> 0: | |
75 mode = stack[-1] | |
76 request.set('MPIWGStaffMode', mode) | |
77 stack.pop(-1) | |
78 | |
79 | |
3 | 80 except (IndexError, ValueError): |
81 # missing context or not an integer id; perhaps some URL hacking going on? | |
82 logging.error("error traversing user id!") | |
83 raise Redirect(self.absolute_url()) # redirects to `/members`, adjust as needed | |
84 | |
85 | |
57 | 86 |
87 | |
2 | 88 def index_html(self,REQUEST,RESPONSE): |
89 """show homepage""" | |
90 logging.debug("MPIWGStaffFolder: index_html!") | |
3 | 91 member = REQUEST.get('MPIWGStaffMember', None) |
37 | 92 mode = REQUEST.get('MPIWGStaffMode', None) |
3 | 93 if member is not None: |
37 | 94 if mode is not None: |
95 return member.execute(mode,REQUEST); | |
96 | |
3 | 97 logging.debug("member: key=%s"%(member.getKey())) |
98 pt = None | |
99 try: | |
100 # get template /template/member_index_html | |
101 pt = getattr(self.template, 'member_index_html', None) | |
102 except: | |
103 logging.error("No template /template/member_index_html") | |
104 # TODO: error page? | |
105 return "No template /template/member_index_html" | |
106 | |
107 if pt is not None: | |
108 return pt(member=member) | |
109 | |
2 | 110 return REQUEST |
3 | 111 |
112 | |
113 def getMember(self, username=None, key=None): | |
114 """returns a MPIWGStaffMember object if the username exists""" | |
115 member = None | |
116 if username is not None: | |
117 # TODO: we should have a username column | |
118 email = '%s@mpiwg-berlin.mpg.de'%username | |
119 content = self.executeZSQL("select * from personal_www where e_mail = %s", [email]) | |
120 if len(content) > 0: | |
86 | 121 member = MPIWGStaffMember(self, dbresult=content[0]) |
3 | 122 |
123 elif key is not None: | |
40 | 124 # TODO: sometimes key is lowercased (e.g. responsibleScientistsList), we should fix the data |
125 content = self.executeZSQL("select * from personal_www where lower(key) = %s", [key.lower()]) | |
3 | 126 if len(content) > 0: |
86 | 127 member = MPIWGStaffMember(self, dbresult=content[0]) |
3 | 128 |
129 return member | |
130 | |
2 | 131 |
40 | 132 def isActiveMember(self, key): |
133 """returns if member key is active""" | |
134 res = self.executeZSQL("select * from personal_www where lower(key) = %s and publish_the_data = 'yes'", [key.lower()]) | |
135 return len(res) > 0 | |
136 | |
137 | |
93 | 138 def getMemberList(self, department=None, sortBy='last_name', onlyCurrent=False, limit=0): |
86 | 139 """Return the list of members. |
140 | |
141 Returns a list of MPIWGStaffMember objects. | |
142 """ | |
143 members = [] | |
144 query = "select * from personal_www_list where publish_the_data = 'yes' and is_scholar='yes'" | |
93 | 145 args = [] |
146 | |
147 if department is not None: | |
148 query += " and department ilike %s" | |
149 args.append('%%%s%%'%department) | |
86 | 150 |
151 if onlyCurrent: | |
152 query += " and date_from < CURRENT_DATE" | |
153 | |
154 if sortBy == 'last_name': | |
155 query += " order by lower(last_name)" | |
156 elif sortBy == 'date_from': | |
157 query += " order by date_from DESC" | |
158 | |
159 if limit > 0: | |
160 query += " limit %s"%int(limit) | |
161 | |
93 | 162 result = self.executeZSQL(query, args) |
86 | 163 for res in result: |
164 members.append(MPIWGStaffMember(self, dbresult=res)) | |
165 | |
166 return members | |
167 | |
168 | |
37 | 169 def sortPriority(self,list): |
170 def sort(x,y): | |
171 try: | |
172 xInt=int(x.priority) | |
173 except: | |
174 xInt=0 | |
175 try: | |
176 yInt=int(y.priority) | |
177 except: | |
178 yInt=0 | |
179 | |
180 return cmp(xInt,yInt) | |
181 | |
182 if not list: | |
183 return [] | |
184 tmp=[x for x in list] | |
185 tmp.sort(sort) | |
186 | |
187 return tmp | |
188 | |
86 | 189 |
56 | 190 def getPublicationsFromPubman(self,coneId="renn",limit=None,publicationType=None): |
38 | 191 |
46 | 192 logging.debug("coneID:%s"%coneId) |
38 | 193 try: |
47 | 194 pubs=self.mpiwgPubman.getPublications(coneId,limit=limit,publicationType=publicationType) |
46 | 195 |
38 | 196 return pubs |
197 except: | |
198 return [] | |
57 | 199 |
200 | |
2 | 201 def manage_addMPIWGStaffFolderForm(self): |
202 """form for adding the project""" | |
203 pt=PageTemplateFile('zpt/addMPIWGStaffFolderForm', globals()).__of__(self) | |
204 return pt() | |
205 | |
206 def manage_addMPIWGStaffFolder(self,id,title,RESPONSE=None): | |
207 """add it""" | |
208 newObj=MPIWGStaffFolder(id,title) | |
209 | |
210 self._setObject(id,newObj) | |
211 | |
212 if RESPONSE is not None: | |
213 RESPONSE.redirect('manage_main') | |
214 | |
3 | 215 |
37 | 216 class MPIWGStaffMember(Folder): |
3 | 217 """MPIWG staff member object from database""" |
218 | |
219 security = ClassSecurityInfo() | |
65 | 220 |
221 # templates | |
222 mainEditFile=PageTemplateFile('zpt/staff/edit_main', globals()) | |
100 | 223 talks_full_html = PageTemplateFile('zpt/staff/talks_full_html', globals()) |
224 teaching_full_html = PageTemplateFile('zpt/staff/teaching_full_html', globals()) | |
225 | |
3 | 226 |
227 def __init__(self, folder, dbresult): | |
86 | 228 """constructor: takes parent MPIWGStaffFolder and content (DB row)""" |
3 | 229 self.folder = folder |
86 | 230 self.content = dbresult |
3 | 231 |
232 def isValid(self): | |
233 """returns if this member exists""" | |
234 return len(self.content) > 0 | |
235 | |
79 | 236 def isActive(self): |
237 """Return if this member is visible (published).""" | |
238 return (self.content.publish_the_data == 'yes') | |
239 | |
3 | 240 def getKey(self): |
241 """returns the db key""" | |
242 return self.content.key | |
243 | |
244 def getUsername(self): | |
245 """returns the username""" | |
246 id = re.sub('@mpiwg-berlin\.mpg\.de', '', self.content.e_mail) | |
247 return id | |
248 | |
86 | 249 getId = getUsername |
250 | |
46 | 251 def getConeId(self): |
252 """return cone ID""" | |
86 | 253 results= self.folder.executeZSQL("SELECT coneid FROM keys WHERE key_main = %s",[self.content.key]) |
46 | 254 for res in results: |
79 | 255 return res.coneid |
46 | 256 return None |
257 | |
3 | 258 def getPublishedImageUrl(self): |
259 """returns the URL to the image if it is published""" | |
260 if self.content.image_p == 'yes': | |
261 url = 'http://digilib.mpiwg-berlin.mpg.de/digitallibrary/Scaler?fn=permanent/mpiwg/staff/%s'%self.getUsername() | |
262 return url | |
263 | |
264 return None | |
265 | |
266 def getContent(self): | |
267 """returns the db content of this object""" | |
268 return self.content | |
269 | |
37 | 270 |
3 | 271 # TODO: ugly! |
272 security.declarePublic('sortBibliography') | |
79 | 273 def sortBibliography(self, bib, sortingMode=None, max=None): |
3 | 274 """sort bibliography""" |
275 if not sortingMode: | |
276 sortingMode= "priority" | |
277 | |
278 l = [x for x in bib] | |
279 | |
280 if sortingMode == "year": | |
281 l.sort(key=lambda x: getInt(x.year)) | |
282 else: | |
283 l.sort(key=lambda x: getInt(x.priority)) | |
284 | |
285 if max: | |
79 | 286 return l[0:max] |
3 | 287 else: |
288 return l | |
289 | |
37 | 290 |
291 | |
292 def execute(self,mode,REQUEST=None): | |
293 method = getattr(self,mode,None) | |
294 if method is not None: | |
295 return method(REQUEST); | |
296 else: | |
297 return "NOT FOUND" | |
298 | |
86 | 299 |
300 getUrl = MPIWGHelper.getUrl | |
37 | 301 |
100 | 302 def getTalks(self, published=True, sortBy='priority'): |
303 """Return the list of talks""" | |
304 query = "SELECT oid,* FROM talks WHERE key_main = %s" | |
305 if published: | |
306 query += " and published = 'yes'" | |
307 | |
308 if sortBy == 'priority': | |
309 query += " order by priority" | |
310 | |
311 return self.folder.executeZSQL(query, [self.content.key]) | |
37 | 312 |
100 | 313 def getTeaching(self, published=True, sortBy='priority'): |
314 """Return the list of teaching activities""" | |
315 query = "SELECT oid,* FROM teaching WHERE key_main = %s" | |
316 if published: | |
317 query += " AND published = 'yes'" | |
318 | |
319 if sortBy == 'priority': | |
320 query += " ORDER BY priority" | |
321 | |
322 return self.folder.executeZSQL("SELECT oid,* FROM teaching WHERE key_main = %s",[self.content.key]) | |
37 | 323 |
324 | |
325 def getLastUpdateCV(self): | |
326 """getDate of Last Update""" | |
327 try: | |
328 fname="%s_cv.pdf"%self.getUsername().encode('utf-8') | |
329 logging.debug(fname) | |
330 ob=self.folder._getOb("downloadableFiles")._getOb(fname) | |
331 return ob.bobobase_modification_time() | |
332 except: | |
333 return "No file yet!" | |
86 | 334 |
37 | 335 |
336 def getLastUpdatePublications(self): | |
337 """getDate of Last Update""" | |
338 try: | |
339 ob=self.folder._getOb("downloadableFiles")._getOb("%s_publications.pdf"%self.getUsername().encode('utf-8')) | |
340 return ob.bobobase_modification_time() | |
341 except: | |
342 return "No file yet!" | |
343 | |
344 | |
345 def downloadCV(self,REQUEST): | |
346 fname="%s_cv.pdf"%self.getUsername().encode('utf-8') | |
347 logging.debug(fname) | |
348 ob=self.folder._getOb("downloadableFiles")._getOb(fname) | |
349 REQUEST.RESPONSE.redirect(ob.absolute_url()) | |
350 | |
351 def downloadPublications(self,REQUEST): | |
352 ob=self.folder._getOb("downloadableFiles")._getOb("%s_publications.pdf"%self.getUsername().encode('utf-8')) | |
353 REQUEST.RESPONSE.redirect(ob.absolute_url()) | |
354 | |
355 def getAdditionalLinks(self): | |
356 | |
357 return self.folder.executeZSQL("SELECT oid,* FROM additionalLink WHERE key_main = %s",[self.content.key]) | |
358 #return self.folder.ZSQLInlineSearch(_table='talks',key_main=self.content.key) | |
359 | |
360 #return self.folder.ZSQLInlineSearch(_table='talks',key_main=self.content.key) | |
361 | |
362 def getPathStyle(self, path, selected, style=""): | |
363 """returns a string with the given style + 'sel' if path == selected.""" | |
364 | |
365 if path == selected: | |
366 return style + 'sel' | |
367 else: | |
368 return style | |
369 | |
370 | |
371 security.declareProtected('View management screens','edit') | |
372 def edit(self,REQUEST=None): | |
373 """Edit the basic information""" | |
374 | |
375 | |
376 | |
377 if REQUEST: | |
378 argv=REQUEST.form | |
379 | |
380 if argv.has_key('last_name'): #got data to change | |
381 self.invalidate_chache() | |
382 self.changeData(argv); | |
383 | |
384 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff','edit_basic.zpt')).__of__(self) | |
385 return pt() | |
386 | |
387 | |
388 security.declareProtected('View management screens','edit') | |
389 def editShortEntry(self,REQUEST=None): | |
390 """Edit the basic information""" | |
391 | |
392 | |
393 | |
394 if REQUEST: | |
395 argv=REQUEST.form | |
396 | |
397 if argv.has_key('current_work'): #got data to change | |
398 self.invalidate_chache() | |
399 self.changeData(argv); | |
400 | |
401 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff','edit_shortEntry.zpt')).__of__(self) | |
402 return pt() | |
403 | |
404 | |
405 security.declareProtected('View management screens','editProfile') | |
406 def editProfile(self, REQUEST=None): | |
407 """edit Profile, new entry replaces CD, current work and research interests""" | |
408 | |
409 | |
410 if REQUEST: | |
411 kupu=REQUEST.form.get('kupu',None); | |
412 preview=REQUEST.form.get('preview',None); | |
3 | 413 |
37 | 414 |
415 if kupu: | |
416 start=kupu.find("<body>") | |
417 end=kupu.find("</body>") | |
418 | |
419 newcontent= kupu[start+6:end] | |
420 query="UPDATE personal_www SET profile=%s WHERE key='%s'" | |
421 self.executeZSQL(query%(self.ZSQLQuote(newcontent),self.content.key)) | |
422 logging.error("PROFILE:"+query%(self.ZSQLQuote(newcontent),self.content.key)) | |
423 | |
424 if preview: | |
425 pass | |
426 #TODO: not supported yet | |
427 #if RESPONSE: | |
428 # self.redirect(RESPONSE,"editProfile") | |
429 | |
430 #return self.preview(newcontent) | |
431 | |
432 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff','edit_profile.zpt')).__of__(self) | |
433 return pt() | |
434 | |
435 | |
436 | |
437 security.declareProtected('View management screens','editTalks') | |
438 def editTalks(self,REQUEST): | |
439 """edit talks""" | |
440 | |
441 | |
442 if REQUEST: | |
443 argv=REQUEST.form | |
444 | |
445 if argv.has_key('main_fields'): #got data to change | |
446 self.invalidate_chache() | |
447 self.changeAdditionalData(argv); | |
448 | |
449 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff','edit_talks.zpt')).__of__(self) | |
450 return pt() | |
451 | |
452 | |
453 security.declareProtected('View management screens','editTeaching') | |
454 def editTeaching(self,REQUEST): | |
455 """edit teaching""" | |
456 | |
457 | |
458 if REQUEST: | |
459 argv=REQUEST.form | |
460 | |
461 if argv.has_key('main_fields'): #got data to change | |
462 self.invalidate_chache() | |
463 self.changeAdditionalData(argv); | |
464 | |
465 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff','edit_teaching.zpt')).__of__(self) | |
466 return pt() | |
467 | |
468 | |
469 security.declareProtected('View management screens','editAdditionalLinks.zpt') | |
470 def editAdditionalLinks(self,REQUEST): | |
471 """editiere die additiona link von der Webseite""" | |
472 | |
473 if REQUEST: | |
474 argv=REQUEST.form | |
475 | |
476 if argv.has_key('main_fields'): #got data to change | |
477 self.invalidate_chache() | |
478 self.changeAdditionalData(argv); | |
479 | |
480 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff','edit_additionalLinks.zpt')).__of__(self) | |
481 return pt() | |
482 | |
483 | |
86 | 484 security.declareProtected('View management screens','editDownloads') |
37 | 485 def editDownloads(self,REQUEST): |
486 """editiere die Downloads von der Webseite""" | |
487 | |
488 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff','edit_downloads.zpt')).__of__(self) | |
489 return pt() | |
490 | |
47 | 491 def editPublications(self,REQUEST): |
492 """editiere die Publications von der Webseite""" | |
493 | |
494 | |
495 data=REQUEST.form | |
496 | |
497 if data.has_key('selectionMode'): | |
498 query="UPDATE personal_www SET publications_mode=%s WHERE key=%s" | |
499 | |
500 self.executeZSQL(query,[data['selectionMode'],self.getKey()]) | |
501 | |
502 self.refresh_content() | |
503 | |
504 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff','edit_publications.zpt')).__of__(self) | |
505 return pt() | |
506 | |
507 | |
508 def refresh_content(self,): | |
509 | |
510 self.content = self.folder.executeZSQL("select * from personal_www where key = %s", [self.getKey()])[0] | |
511 | |
512 | |
37 | 513 def changeDownloads(self,REQUEST): |
514 """"change the downloadable files""" | |
515 self.invalidate_chache(); | |
516 | |
517 data=REQUEST.form | |
518 | |
519 ob = self.folder._getOb("downloadableFiles") | |
520 | |
521 if data.get('cv_publish',None): | |
522 | |
523 self.changeData({'cv_p':data['cv_publish']}) | |
524 | |
525 if data.get('publications_publish',None): | |
526 self.changeData({'publications_p':data['publications_publish']}) | |
527 | |
528 | |
529 if data.get('cv_pdf',None): | |
530 cvName ="%s_cv.pdf"%self.getUsername() | |
531 cvName=cvName.encode('utf-8') | |
532 logging.debug("CCC") | |
533 if not hasattr(ob,cvName): | |
534 | |
535 cvFile = ExtFile(cvName,cvName) | |
536 ob._setObject(cvName,cvFile) | |
537 | |
538 | |
539 cvFile = getattr(ob,cvName) | |
540 | |
541 cvFile.manage_upload(file=data['cv_pdf']) | |
542 | |
543 | |
544 | |
545 | |
546 if data.get('publications_pdf',None): | |
547 | |
548 | |
549 pdfName="%s_publications.pdf"%self.getUsername() | |
550 pdfName=pdfName.encode('utf-8') | |
551 | |
552 if not hasattr(ob,pdfName): | |
553 | |
554 cvFile = ExtFile(pdfName,pdfName) | |
555 ob._setObject(pdfName,cvFile) | |
556 | |
557 | |
558 cvFile = getattr(ob,pdfName) | |
559 | |
560 cvFile.manage_upload(file=data['publications_pdf']) | |
561 | |
562 | |
563 #REQUEST.response.redirect(self.REQUEST['HTTP_REFERER']) | |
564 | |
565 | |
566 | |
567 | |
568 def changeData(self,changeSet): | |
569 """changes the data in the database, changeset expects field --> value.""" | |
570 for field in changeSet.keys(): | |
571 if hasattr(self.content,field): | |
572 logging.debug("Changing: %s"%field) | |
573 | |
574 | |
575 results = self.folder.executeZSQL("update personal_www set "+field+" = %s where key = %s ", [changeSet.get(field),self.getKey().encode('utf-8')]); | |
576 | |
577 logging.debug(results) | |
578 | |
579 | |
580 security.declareProtected('View management screens','changeAdditionalData') | |
581 def changeAdditionalData(self,data): | |
582 """change the research entries""" | |
583 | |
584 self.invalidate_chache(); | |
585 | |
586 newEntries={} | |
587 | |
588 | |
589 mainfieldL=data['main_fields'].split(",") #fields to be changed | |
590 # format DATABASE__FIELDNAME | |
591 | |
592 mainfield={} | |
593 for x in mainfieldL: | |
594 tmp=x.split('__') | |
595 mainfield[tmp[0]]=tmp[1] | |
596 for field in data: | |
597 splittedField=field.split("__") | |
598 if len(splittedField)<3: | |
599 pass #kein datenbank eintrag | |
600 | |
601 elif splittedField[2]=='new': # store new entries | |
602 if not newEntries.has_key(splittedField[0]): | |
603 newEntries[splittedField[0]]={} | |
604 | |
605 newEntries[splittedField[0]][splittedField[1]]=data[field] | |
606 | |
607 else: | |
608 query="UPDATE %s "%splittedField[0] | |
609 query+="SET %s = '%s' "%(splittedField[1],sql_quote(data[field])) | |
610 query+="WHERE oid = '%s' "%sql_quote(splittedField[2]) | |
611 | |
612 self.executeZSQL(query) | |
613 | |
614 | |
615 #new entries | |
616 for newEntry in newEntries.keys(): | |
617 query="INSERT INTO %s "%newEntry | |
618 keys=['key_main'] | |
619 values=["'"+sql_quote(self.getKey())+"'"] | |
620 for key in newEntries[newEntry].keys(): | |
621 keys.append(key) | |
622 values.append("'"+sql_quote(newEntries[newEntry][key])+"'") | |
623 | |
624 | |
625 keystring=",".join(keys) | |
626 | |
627 valuestring=",".join(values) | |
628 | |
629 query+=" (%s) "%keystring | |
630 query+="VALUES (%s)"%valuestring | |
631 if not (newEntries[newEntry][mainfield[newEntry]].lstrip().rstrip()==""): | |
632 self.executeZSQL(query) | |
633 | |
634 | |
38 | 635 |
37 | 636 |
637 | |
638 def deleteField(self,REQUEST): | |
639 """delete entry""" | |
640 | |
641 | |
642 table = REQUEST.form.get('table',None); | |
643 oid = REQUEST.form.get('oid',None); | |
644 | |
645 if table is None or oid is None: | |
646 return | |
647 | |
648 query="DELETE FROM %s WHERE oid = '%s'"%(table,oid) | |
649 | |
650 self.executeZSQL(query) | |
651 REQUEST.response.redirect(self.REQUEST['HTTP_REFERER']) | |
652 | |
653 | |
40 | 654 def invalidate_cache(self): |
37 | 655 #TODO: How to invalidate the varnish cache from the member object |
656 pass; | |
657 | |
79 | 658 |
659 # TODO: compat, is this used? | |
660 getStaffURL = getUsername | |
37 | 661 |
56 | 662 def getPublicationsFromPubman(self,limit=None,publicationType=None): |
47 | 663 |
664 | |
665 if self.content.publications_mode=="year" or publicationType is not None: | |
666 coneId = self.getConeId(); | |
667 if coneId: | |
56 | 668 pubs= self.folder.getPublicationsFromPubman(coneId,limit=limit,publicationType=publicationType) |
47 | 669 return pubs |
38 | 670 |
47 | 671 elif self.content.publications_mode=="priority": |
672 selPubs= self.getSelectedPublications() | |
673 | |
674 pubs=[] | |
73 | 675 count =0 |
47 | 676 for selPub in selPubs: |
73 | 677 if limit and count >= limit: |
678 break | |
679 count+=1 | |
53 | 680 logging.debug("searchFor:%s"%selPub.escidocid) |
47 | 681 pubs.append((selPub.escidocid,self.mpiwgPubman.getEntryFromPubman(selPub.escidocid))) |
682 | |
46 | 683 return pubs |
47 | 684 return {} |
685 | |
686 | |
100 | 687 def publications_full_html(self, REQUEST): |
47 | 688 """show publication""" |
100 | 689 pt=PageTemplateFile('zpt/staff/pubman/show_publications.zpt', globals()).__of__(self) |
47 | 690 return pt(member=self.content) |
691 | |
692 | |
693 def addPublicationsFromPubman(self,REQUEST): | |
694 """addPublications from pubman""" | |
695 | |
696 data=REQUEST.form | |
38 | 697 |
47 | 698 if data.get("method",None) is None: |
699 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff/pubman','add_publications.zpt')).__of__(self) | |
700 return pt() | |
701 | |
37 | 702 |
703 | |
47 | 704 if data.get("method") == "search": |
73 | 705 |
706 | |
707 | |
708 entries= self.mpiwgPubman.search(data,contexts=["escidoc:85274","escidoc:38279"]) | |
47 | 709 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff/pubman','add_publications.zpt')).__of__(self) |
710 | |
711 | |
712 return pt(values=entries) | |
713 | |
714 | |
715 | |
716 if data.get("method") == "add": | |
717 | |
718 return self.addEntriesToPublicationList(data) | |
719 #pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff/pubman','add_publications.zpt')).__of__(self) | |
720 | |
721 | |
722 | |
723 def addEntriesToPublicationList(self,data): | |
724 """fuege eintrage aus data zur publications liste, | |
725 @param data Map mit escidocID --> value | |
726 value muss "add" sein damit hinzugefuegt wird""" | |
727 | |
728 for key in data.keys(): | |
729 | |
56 | 730 if key.startswith('escidoc:'): |
731 | |
47 | 732 |
56 | 733 query="INSERT INTO pubmanbiblio (key_main,escidocId) values (%s,%s)" |
47 | 734 |
56 | 735 if data.get(key)=="add": |
736 self.executeZSQL(query,[self.getKey(),key]) | |
737 | |
47 | 738 |
739 | |
56 | 740 #selectedPublications = self.getSelectedPublications() |
741 | |
742 #pt = PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff/pubman','change_publications.zpt')).__of__(self) | |
47 | 743 |
56 | 744 #return pt() |
745 if hasattr(self,'REQUEST'): | |
746 return self.REQUEST.response.redirect("changePublications") | |
47 | 747 |
748 | |
749 def changePublications(self,REQUEST): | |
750 """change published publications""" | |
751 | |
752 data=REQUEST.form | |
753 | |
754 | |
755 if data.get("method","change"): | |
756 for key in data.keys(): | |
757 splitted=key.split("__") #format escidoc_id__p fuer priority, nur escidocid | |
758 value=data[key] | |
759 if len(splitted)==1: | |
760 self.deleteFromPublicationList(key); | |
761 | |
762 elif(splitted[1]) == "p": | |
763 self.setPublicationPriority(splitted[0],value); | |
764 | |
765 | |
766 pt = PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff/pubman','change_publications.zpt')).__of__(self) | |
767 return pt() | |
768 | |
769 | |
770 def deleteFromPublicationList(self,escidocid): | |
771 """Loessche publication with escidoc id from publication list""" | |
772 | |
773 query ="DELETE FROM pubmanbiblio WHERE escidocid=%s and key_main=%s" | |
774 | |
775 self.executeZSQL(query,[escidocid,self.getKey()]); | |
776 | |
777 | |
778 def setPublicationPriority(self,escidocid,value): | |
56 | 779 try: |
780 query="update pubmanbiblio set priority=%s where escidocid=%s and key_main=%s" | |
781 | |
782 self.executeZSQL(query,[value,escidocid,self.getKey()]); | |
783 | |
784 except: | |
785 logging.error("couldn't change:") | |
786 logging.error(escidocid) | |
787 logging.error(value) | |
788 | |
80 | 789 |
47 | 790 def getSelectedPublications(self): |
791 """hole publications aus der datenbank""" | |
100 | 792 query="select * from pubmanbiblio where lower(key_main) = lower(%s) order by priority ASC" |
47 | 793 return self.executeZSQL(query,[self.getKey()]) |
68 | 794 |
795 | |
86 | 796 def getProfile(self,REQUEST): |
797 """get the profile""" | |
798 self.REQUEST.RESPONSE.setHeader('Last-Modified',email.Utils.formatdate().split("-")[0]+'GMT') | |
799 | |
800 | |
801 html="""<html><body>%s</body></html>""" | |
802 if self.content.profile and self.content.profile != "": | |
803 | |
804 return html%self.content.profile | |
805 else: | |
806 | |
807 return html%"" | |
808 | |
809 | |
68 | 810 def generateProfileForPerson(self,REQUEST=None): |
811 """erzeugt ein automatisches Profil aus den alten Eintraegen CV, Current work, und research interests""" | |
812 | |
813 ret="" | |
814 #founds=self.ZSQLInlineSearch(_table='research_interest',key_main=person.getKeyUTF8()) | |
80 | 815 founds=self.executeZSQL('select * from research_interest where lower(key_main) = %s', [self.getKey().lower()]) |
68 | 816 if founds: |
817 ret="<p class=\"bio_section_header\">Research interests: </p><br/>" | |
818 for found in self.sortPriority(founds): | |
819 ret+=found.interest+"<br/>" | |
820 if (self.content.current_work) and (not self.content.current_work==""): | |
821 ret+="<p class=\"bio_section_header\">Current work: </p><br/>" | |
80 | 822 ret+=self.content.current_work+"<br/>" |
68 | 823 if (self.content.cv) and (not self.content.cv==""): |
824 ret+="<p class=\"bio_section_header\">Curriculum Vitae: </p><br/>" | |
825 ret+=self.formatAscii(self.content.cv) | |
826 | |
827 return ret | |
47 | 828 |
3 | 829 InitializeClass(MPIWGStaffMember) |