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