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