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