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