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