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