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