Annotation of MPIWGWeb/MPIWGStaff.py, revision 1.10.2.73
1.1 dwinter 1: """This file contains the classes for the organization of the staff"""
1.10.2.3 dwinter 2: # TODO: pruefe ob die id der einzelnen tabellen, wie id in publications noch benutzt werden
3: # TODO: pruefe ob die bibliographischen felder in publications noch benutzt werden
1.10.2.5 dwinter 4: # TODO: wird username gebraucht?
1.10.2.3 dwinter 5:
1.1 dwinter 6: from OFS.Folder import Folder
1.3 dwinter 7: from Products.ZSQLExtend.ZSQLExtend import ZSQLExtendFolder
1.1 dwinter 8: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
9: from Products.PageTemplates.PageTemplate import PageTemplate
1.10.2.62 dwinter 10: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
1.9 dwinter 11: from Products.ZCatalog.CatalogPathAwareness import CatalogAware
1.10.2.41 dwinter 12: from Products.versionedFile.extVersionedFile import extVersionedFileFolder
1.10.2.62 dwinter 13: from AccessControl import getSecurityManager
1.10.2.41 dwinter 14:
1.6 casties 15: import os
1.10.2.33 dwinter 16: import logging
1.10.2.2 dwinter 17: import bibliography
1.10.2.51 dwinter 18: import email
1.6 casties 19: from Globals import package_home
1.10.2.2 dwinter 20: from Products.PythonScripts.standard import sql_quote
1.10.2.3 dwinter 21: from types import *
1.10.2.10 dwinter 22: from AccessControl import ClassSecurityInfo
1.10.2.50 dwinter 23: import time
1.10.2.33 dwinter 24: import logging
1.10.2.52 dwinter 25: import email
1.10.2.56 dwinter 26: import re
1.10.2.60 dwinter 27: from OFS.Cache import Cacheable
1.10.2.56 dwinter 28:
1.10.2.55 dwinter 29: from MPIWGHelper import *
1.10.2.33 dwinter 30: #ersetzt logging
31: def logger(txt,method,txt2):
32: """logging"""
33: logging.info(txt+ txt2)
1.10.2.16 dwinter 34:
1.10.2.5 dwinter 35: departmentList="Renn\nRheinberger\nDaston\nKlein\nSibum\nIT\nInstitut\nBibliothek"
36:
1.6 casties 37:
1.10.2.63 dwinter 38:
1.1 dwinter 39:
1.10.2.67 dwinter 40: def createNewDBEntry(self,publish_the_data,key,name,vorname,titles_new,position,e_mail,e_mail_p,date_from,date_to,abteilung,heimat_inst,funded_by="",e_mail2="",txt="",txt_p="no",stay_at_mpiwg="",group="",web_object_created="no",current_work=""):
1.10.2.33 dwinter 41: """lege person in der datenbank an"""
42:
43: if date_to=="": # wenn date_to leer
44: date_to="date_none"
45:
46: if date_from=="": # wenn date_fromleer
47: date_from="date_none"
48: msg=""
49: #test ob id schon existiert
50: if self.ZSQLQuery("select key from personal_www where key='%s'"%id):
51: return False,"ERROR:key%s already exists"%key
52:
53: #eintragen
1.10.2.67 dwinter 54: columnlist="""publish_the_data,key,last_name,first_name,titles_new,status,e_mail,e_mail_p,date_from,date_to,department,home_inst,funded_by,e_mail2,date_stay_at_mpiwg,web_object_created,"group",current_work,current_work_p """
55: insertTuple=(publish_the_data,key,name,vorname,titles_new,position,e_mail,e_mail_p,date_from,date_to,abteilung,heimat_inst,funded_by,e_mail2,stay_at_mpiwg,web_object_created,group,current_work,"yes")
1.10.2.33 dwinter 56:
57: insert=[]
58: for element in insertTuple:
59: if element=="date_none": # date_none eintrag wird zu null uebersetzt
60: insert.append('null')
61: else:
62: insert.append("%s"%self.ZSQLQuote(element))
63:
64: insertStr=",".join(insert)
65: queryStr="INSERT INTO personal_www (%s) VALUES (%s)"%(columnlist,insertStr)
66: self.ZSQLQuery("SET DATESTYLE TO 'German'")
67: self.ZSQLQuery(queryStr)
1.10.2.39 dwinter 68: logging.info("QQQQ %s:"%queryStr)
1.10.2.33 dwinter 69: #currentwork
1.10.2.57 dwinter 70: #if not (current_work==""):
71: # queryStr="INSERT INTO current_work (key_main,current,publish) VALUES ('%s',%s,'%s')"%(key,self.ZSQLQuote(current_work),"yes")
1.10.2.33 dwinter 72:
1.10.2.57 dwinter 73: # self.ZSQLQuery(queryStr)
1.10.2.33 dwinter 74:
75: return True,msg
1.10.2.60 dwinter 76: class MPIWGStaff(CatalogAware,ZSQLExtendFolder,Cacheable):
1.1 dwinter 77: """Staff"""
78:
79: meta_type="MPIWGStaff"
1.9 dwinter 80: default_catalog='MembersCatalog'
1.10.2.5 dwinter 81: departmentList=departmentList
1.10.2.10 dwinter 82: security=ClassSecurityInfo()
1.10.2.5 dwinter 83:
1.10.2.50 dwinter 84: def redirect(self,RESPONSE,url):
85: """mache ein redirect mit einem angehaengten time stamp um ein reload zu erzwingen"""
86:
87: timeStamp=time.time()
88:
89: if url.find("?")>-1: #giebt es schon parameter
90: addStr="&time=%s"
91: else:
92: addStr="?time=%s"
1.10.2.52 dwinter 93:
94: RESPONSE.setHeader('Last-Modified',email.Utils.formatdate().split("-")[0]+'GMT')
95: logging.error(email.Utils.formatdate()+' GMT')
1.10.2.50 dwinter 96: RESPONSE.redirect(url+addStr%timeStamp)
97:
1.10.2.55 dwinter 98: def getKeyUTF8(self):
99: """get db_key utf8"""
100: return utf8ify(self.getKey())
101:
1.10.2.65 dwinter 102: def setKey(self,key):
103: """set key"""
104: self.key=key
105:
1.10.2.33 dwinter 106: def getKey(self):
107: """get database key"""
108: if hasattr(self,'key'):
1.10.2.55 dwinter 109: #logging.error("SAVED KEY:%s"%self.key)
110: return unicodify(self.key.lower())
111: #return self.key.lower()
1.10.2.33 dwinter 112:
113: #fuer alt faelle ohne key
1.10.2.55 dwinter 114: #logging.error("NEW KEY:%s"%(self.firstName+'_'+self.lastName).lower().replace(' ',''))
1.10.2.34 casties 115: return (self.firstName+'_'+self.lastName).lower().replace(' ','')
1.10.2.33 dwinter 116:
1.10.2.61 casties 117: def getConnectionObj(self):
118: """returns connection id (from root)"""
1.10.2.66 dwinter 119: try:
120: root = self.getMPIWGRoot()
121: return root.getConnectionObj()
122: except:
123: return self.en.getConnectionObj()
1.10.2.67 dwinter 124:
1.10.2.7 dwinter 125: def isPublished(self):
126: """gib publications status aus der datenbank aus"""
1.10.2.33 dwinter 127: key=self.getKey()
1.10.2.35 casties 128: query="select count(publish_the_data) from personal_www where lower(key)='%s' and publish_the_data='yes'"%key
1.10.2.7 dwinter 129:
130: res = self.ZSQLQuery(query)
131:
132: if res and res[0].count>0:
133: return True
134: else:
135: return False
136:
1.10.2.33 dwinter 137:
1.10.2.62 dwinter 138:
1.10.2.26 dwinter 139: def updateDBEntry(self,publish_the_data,date_from,date_to,DBid=None,stay_at_mpiwg="",position="",abteilung=""):
1.10.2.6 dwinter 140: """zpddatedb"""
141: if not DBid:
1.10.2.40 dwinter 142: DBid=self.getDBId()
1.10.2.30 casties 143:
144:
1.10.2.6 dwinter 145: self.ZSQLQuery("SET DATESTYLE TO 'German'")
1.10.2.11 dwinter 146:
1.10.2.22 dwinter 147: test=self.ZSQLQuery("select id from personal_www where id='%s' "%DBid)
1.10.2.21 dwinter 148:
1.10.2.22 dwinter 149:
150: if test and (len(test)>0): #dataset exists
1.10.2.33 dwinter 151: logger("MPIWG Web",logging.INFO,'UPDATE: _table="personal_www",_identify="id=%s"'%DBid+',publish_the_data=%s'%publish_the_data+',date_from=%s'%date_from+',date_to=%s'%date_to+',stay_at_mpiwg=%s'%stay_at_mpiwg+',position=%s'%position)
152: self.ZSQLChange(_table="personal_www",_identify="id=%s"%DBid,publish_the_data=publish_the_data,
1.10.2.6 dwinter 153: date_from=date_from,
1.10.2.26 dwinter 154: date_to=date_to,stay_at_mpiwg=stay_at_mpiwg,position=position,abteilung=abteilung)
1.10.2.33 dwinter 155: return True
1.10.2.21 dwinter 156: else:
1.10.2.33 dwinter 157: return False
1.10.2.6 dwinter 158:
1.10.2.5 dwinter 159: def getPublicationSelectionMode(self):
160: """get publication selection mode, default 'priority'"""
161: return getattr(self,'publicationSelectionMode','priority')
162:
163: def changePublicationSelectionMode(self,publicationSelectionMode,RESPONSE=None):
164: """change PublicationSelectionMode"""
165:
166: self.publicationSelectionMode=publicationSelectionMode
1.10.2.62 dwinter 167: self.ZCacheable_invalidate()
1.10.2.5 dwinter 168: if RESPONSE:
1.10.2.59 dwinter 169: self.redirect(RESPONSE,"editPublications")
1.10.2.5 dwinter 170:
1.10.2.41 dwinter 171:
172: def downloadCV(self,RESPONSE):
173: """download cv file"""
174: ob=self._getOb("downloadableFiles")._getOb("cv.pdf")
175:
176: RESPONSE.redirect(ob.absolute_url()+"/download")
177:
178: def getLastUpdateCV(self):
179: """getDate of Last Update"""
1.10.2.42 dwinter 180: try:
181: ob=self._getOb("downloadableFiles")._getOb("cv.pdf")
182: return ob.getLastChangeDate()
183: except:
184: return "No file yet!"
1.10.2.41 dwinter 185: def getLastUpdatePublications(self):
186: """getDate of Last Update"""
1.10.2.42 dwinter 187: try:
188: ob=self._getOb("downloadableFiles")._getOb("publications.pdf")
189: return ob.getLastChangeDate()
190: except:
191: return "No file yet!"
1.10.2.41 dwinter 192: def downloadPublications(self,RESPONSE):
193: """download publications"""
194: ob=self._getOb("downloadableFiles")._getOb("publications.pdf")
195:
196: RESPONSE.redirect(ob.absolute_url()+"/download")
197:
198: def changeDownloads(self,cv_pdf=None,cv_publish=None,publications_pdf=None,publications_publish=None,RESPONSE=None):
199: """"change the downloadable files"""
1.10.2.62 dwinter 200: self.ZCacheable_invalidate()
1.10.2.41 dwinter 201: if not hasattr(self,'downloadableFiles'):
202:
203: extFolder = extVersionedFileFolder()
204: extFolder.id = "downloadableFiles"
205: self._setObject(extFolder.id,extFolder)
206:
207: ob = self._getOb("downloadableFiles")
208:
209: if cv_publish:
210: self.cv_publish=cv_publish
211:
212: if publications_publish:
213: self.publications_publish=publications_publish
214:
215: if cv_pdf:
216: if not hasattr(ob,"cv.pdf"):
217: ob.addFile("",cv_pdf,newName="cv.pdf")
1.10.2.5 dwinter 218:
1.10.2.41 dwinter 219: else:
220: cvFile = getattr(ob,"cv.pdf")
221: cvFile.addContentObject("","",file=cv_pdf)
222:
223: if publications_pdf:
224: if not hasattr(ob,"publications.pdf"):
225: ob.addFile("",cv_pdf,newName="publications.pdf")
226:
227: else:
228: cvFile = getattr(ob,"publications.pdf")
229: cvFile.addContentObject("","",file=publications_pdf)
230:
231: if RESPONSE:
1.10.2.50 dwinter 232: self.redirect(RESPONSE,self.REQUEST['HTTP_REFERER'])
1.10.2.48 dwinter 233:
1.10.2.41 dwinter 234:
1.10.2.5 dwinter 235: def getPublishImage(self):
236: """publish the image??, default no"""
237: return getattr(self,'publishImage','no')
238:
239: def updateImage(self,file,publishImage,rename=None,RESPONSE=None):
240: """update image"""
1.10.2.11 dwinter 241:
242: if file and not(file.filename==""):
243: if self.getImageObj():
1.10.2.40 dwinter 244: self.getImageObj().updateImage(file,_rename=None,RESPONSE=None)
1.10.2.11 dwinter 245: else:
1.10.2.40 dwinter 246: # create new image object
247: xp = file.filename.rfind('.')
248: if xp > 0:
249: ext = file.filename[xp:]
250: #fn = self.getId()+ext
251: fn = self.getId()
252: logger("MPWIG STAFF", logging.INFO, "new filename: %s"%fn)
253: self.getImageFolder().addImage2(file,fileName=fn)
254: else:
255: logger("MPWIG STAFF", logging.ERROR, "uploaded filename %s has no extension!"%file.filename)
1.10.2.5 dwinter 256:
257: self.publishImage=publishImage
258:
259: if RESPONSE:
1.10.2.50 dwinter 260: self.redirect(RESPONSE,"edit")
1.10.2.5 dwinter 261:
262: def getImageFolder(self):
263: """getImageFolder"""
1.10.2.16 dwinter 264: #TODO: make place of staff image folder configurable
265:
266: try:
267: return self.getPhysicalRoot().www_neu.images.staff_images
268: except:
1.10.2.40 dwinter 269: logger("MPWIG STAFF", logging.ERROR, "image folder not found: has to be add /www_neu/staff_images")
1.10.2.16 dwinter 270: return None
271:
1.10.2.5 dwinter 272: def getImageObj(self):
273: """getImage"""
274: imageFolder=self.getImageFolder()
275:
1.10.2.16 dwinter 276: if not imageFolder: return None
277:
1.10.2.5 dwinter 278: image=getattr(imageFolder,self.getId(),None)
279:
280: if not image:
281: for suffix in ['jpg','tif']:
282:
283: image=getattr(imageFolder,self.getId()+"."+suffix,None)
284: if image:
285: break
286: return image
287:
288: def getImageUrl(self):
289: """getImageUrl"""
290: image=self.getImageObj()
291: if not image:
292: return None
293: else:
294: return self.getImageObj().absolute_url()+"/image"
1.9 dwinter 295:
296: def PrincipiaSearchSource(self):
297: """Return cataloguable key for ourselves."""
298: return str(self)
1.1 dwinter 299:
1.6 casties 300: manage_options = Folder.manage_options+(
301: {'label':'Edit','action':'changeMPIWGStaffForm'},
1.10.2.1 dwinter 302: {'label':'Change Publications Special','action':'changePublications_specialForm'},
1.10.2.62 dwinter 303: ) + Cacheable.manage_options
1.6 casties 304:
1.10.2.62 dwinter 305: __manager_id = "ramCache"
1.10.2.33 dwinter 306: def __init__(self,id, lastName,firstName,key):
1.1 dwinter 307: """init"""
308: self.id=id
1.10.2.33 dwinter 309: self.title=key
1.1 dwinter 310: self.lastName=lastName
311: self.firstName=firstName
1.10.2.33 dwinter 312: self.key=key
1.10.2.38 dwinter 313:
314: def getPersonID(self):
315: """gibt den ID fuer die Person zurueck"
316: im Moment ist personID = id, i.e. e-mail
317: """
318: return self.id
1.1 dwinter 319:
1.10.2.56 dwinter 320: def harvest_page_old(self,context=None):
1.10.2.28 dwinter 321: """geharvestete seite = verschlankte version von members_main"""
1.10.2.56 dwinter 322: #pt = getTemplate(self, "harvest_members_main")
323:
324: if not self.isPublished():
325: return ""
326: if not context:
327: context=self
328:
329:
330: ext=getattr(self,"harvest_members_main",None)
331: if ext:
332: return getattr(self,ext.getId())()
333:
334: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','harvest_members_main')).__of__(context)
335:
336:
1.10.2.28 dwinter 337: return pt()
1.10.2.1 dwinter 338:
1.10.2.56 dwinter 339: def harvest_page(self):
340: """harvest"""
341: if not self.isPublished():
342: return ""
1.10.2.67 dwinter 343: st = getattr(self.en.staff.members,self.getId()).index_html()
344: return st
1.10.2.56 dwinter 345:
346:
1.1 dwinter 347: def index_html(self):
1.3 dwinter 348: """show homepage"""
1.10.2.62 dwinter 349:
350: bound_names={}
351: request = self.REQUEST
352: if request is not None:
353: response = request.response
354: if not response.headers.has_key('content-type'):
355: response.setHeader('content-type', 'text/html')
356:
357: security = getSecurityManager()
358: bound_names['user'] = security.getUser()
359:
360: # Retrieve the value from the cache.
361: keyset = None
362: if self.ZCacheable_isCachingEnabled():
363:
364: # Prepare a cache key.
365: keyset = {'here': self}
366:
367: result = self.ZCacheable_get(keywords=keyset)
368:
369: if result is not None:
370: # Got a cached value.
371: return result
1.10.2.71 casties 372:
373: # look for individual page
1.10.2.72 casties 374: if self.hasObject("index.html"):
375: pt = getattr(self, "index.html")
1.10.2.71 casties 376: # else use template
1.10.2.72 casties 377: else:
1.10.2.71 casties 378: pt = getTemplate(self, "members_main")
379: # Execute the template in a new security context.
1.10.2.62 dwinter 380: security.addContext(self)
381:
382: try:
383: result = pt.pt_render(extra_context=bound_names)
384: if keyset is not None:
385: # Store the result in the cache.
386: self.ZCacheable_set(result, keywords=keyset)
387:
388: return result
389: finally:
390: security.removeContext(self)
391:
1.1 dwinter 392:
1.10.2.62 dwinter 393:
1.10.2.1 dwinter 394: def changePublications_specialForm(self):
1.10.2.2 dwinter 395: """Priority publications manual field"""
396: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changePublications_special.zpt')).__of__(self)
1.10.2.1 dwinter 397: return pt()
1.10.2.2 dwinter 398:
1.10.2.1 dwinter 399: def changePublications_special(self,usePublicationsSpecial=None,specialPublicationsField=None,RESPONSE=None):
1.10.2.2 dwinter 400: """change publications special params"""
1.10.2.62 dwinter 401: self.ZCacheable_invalidate()
1.10.2.2 dwinter 402: if usePublicationsSpecial:
1.10.2.1 dwinter 403: self.usePublicationsSpecial=True
1.10.2.2 dwinter 404:
405: else:
406: self.usePublicationsSpecial=False
1.10.2.1 dwinter 407:
1.10.2.2 dwinter 408: self.specialPublicationsField=specialPublicationsField[0:]
1.10.2.1 dwinter 409:
410: if RESPONSE is not None:
1.10.2.50 dwinter 411: self.redirect(RESPONSE,'manage_main')
1.10.2.1 dwinter 412:
1.10.2.2 dwinter 413:
1.3 dwinter 414: def publications_full(self):
415: """show publication"""
1.7 casties 416: pt=getTemplate(self, "publications_full_main")
1.3 dwinter 417: return pt()
418:
419: def talks_full(self):
420: """show talks"""
1.7 casties 421: pt=getTemplate(self, 'talks_full_main')
1.3 dwinter 422: return pt()
423:
424: def teaching_full(self):
425: """show talks"""
1.7 casties 426: pt=getTemplate(self, 'teaching_full_main')
1.3 dwinter 427: return pt()
428:
1.1 dwinter 429: def changeMPIWGStaffForm(self):
430: """change form"""
1.10 dwinter 431: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGStaff.zpt')).__of__(self)
1.1 dwinter 432: return pt()
1.10.2.10 dwinter 433:
434: security.declareProtected('View management screens','changeMPIWGStaff')
1.10.2.36 casties 435: def changeMPIWGStaff(self,lastName,firstName,key=None,RESPONSE=None):
1.1 dwinter 436: """change it"""
1.10.2.62 dwinter 437: self.ZCacheable_invalidate()
1.2 dwinter 438: self.title="%s, %s"%(lastName,firstName)
1.1 dwinter 439: self.lastName=lastName
440: self.firstName=firstName
1.10.2.36 casties 441: if key:
442: self.key = key
1.2 dwinter 443:
444: if RESPONSE is not None:
1.10.2.50 dwinter 445: self.redirect(RESPONSE,'manage_main')
1.10.2.10 dwinter 446:
447: security.declareProtected('View management screens','edit')
1.10.2.2 dwinter 448: def edit(self):
449: """Edit the pages"""
1.10.2.25 dwinter 450: #TODO: zusammenspiel mit apache, redirect auf 18080 rausnehmen bzw. zumindest verallgemeinern
1.10.2.31 casties 451: #if self.REQUEST['SERVER_URL']=="http://www.mpiwg-berlin.mpg.de":
452: # redURL="http://xserve04.mpiwg-berlin.mpg.de:18080/www_neu/de/mitarbeiter/members/%s/edit"%self.getId()
453: #
454: # self.REQUEST.RESPONSE.redirect(redURL)
1.10.2.2 dwinter 455:
456: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editMPIWGStaff.zpt')).__of__(self)
1.10.2.52 dwinter 457:
458:
459: logging.error("XX:"+email.Utils.formatdate().split("-")[0]+'GMT')
1.10.2.2 dwinter 460: return pt()
461:
462: mainEditFile=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editMPIWGStaff_main.zpt'))
1.10.2.47 dwinter 463: addPublicationsBib=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addPublicationsBib.zpt'))
1.10.2.2 dwinter 464:
1.10.2.12 casties 465: def getPathStyle(self, path, selected, style=""):
466: """returns a string with the given style + 'sel' if path == selected."""
467:
468: if path == selected:
469: return style + 'sel'
470: else:
471: return style
472:
1.10.2.41 dwinter 473:
1.10.2.53 casties 474: def getLabel(self):
475: """returns a label for this object"""
476: return self.title
477:
478: def getBreadcrumbs(self):
479: """return list of breadcrumbs from here to the root"""
480: crumbs = []
481: # skip direct parent Folder /members/
482: parent = self.aq_parent.aq_parent
483: # get parents breadcrumbs
484: logging.debug("getbreadcrumbs-: title=%s self=%s parent=%s"%(self.title, repr(self), repr(parent)))
485: if hasattr(parent, 'getBreadcrumbs'):
486: logging.debug("getbreadcrumbs: recurse to %s"%parent)
487: crumbs = parent.getBreadcrumbs()
488:
489: # try to get acquisition URL from parent
490: if hasattr(parent, 'absolute_url'):
491: baseUrl = "%s/%s/"%(parent.absolute_url(), 'members')
492: else:
493: baseUrl = "/en/staff/members/"
494:
495: # add this
496: crumbs.append((self.getLabel(), baseUrl+self.getId(), self))
497:
498: return crumbs
499:
500:
1.10.2.49 dwinter 501: def changeCurrentWork(self,current_work,key,publish="yes",RESPONSE=None):
1.10.2.44 dwinter 502: """change current work"""
503:
504: query="UPDATE personal_www SET current_work =%s WHERE key='%s'"
505:
506: self.ZSQLQuery(query%(self.ZSQLQuote(current_work),key))
507:
508: query="UPDATE personal_www SET current_work_p =%s WHERE key='%s'"
509:
510: self.ZSQLQuery(query%(self.ZSQLQuote(publish),key))
1.10.2.62 dwinter 511: self.ZCacheable_invalidate()
1.10.2.44 dwinter 512: if RESPONSE:
1.10.2.50 dwinter 513: self.redirect(RESPONSE,"edit")
1.10.2.44 dwinter 514:
1.10.2.10 dwinter 515: security.declareProtected('View management screens','changeResearch')
1.10.2.50 dwinter 516: def changeResearch(self,noredirect=None,RESPONSE=None):
1.10.2.2 dwinter 517: """change the research entries"""
1.10.2.62 dwinter 518: self.ZCacheable_invalidate()
1.10.2.2 dwinter 519: newEntries={}
1.10.2.33 dwinter 520: key_main=self.REQUEST.form['key_main']
1.10.2.2 dwinter 521:
522: mainfieldL=self.REQUEST.form['main_fields'].split(",")
523: mainfield={}
524: for x in mainfieldL:
525: tmp=x.split('__')
526: mainfield[tmp[0]]=tmp[1]
527: for field in self.REQUEST.form.keys():
528: splittedField=field.split("__")
529: if len(splittedField)<3:
530: pass #kein datenbank eintrag
531:
532: elif splittedField[2]=='new': # store new entries
533: if not newEntries.has_key(splittedField[0]):
534: newEntries[splittedField[0]]={}
535:
536: newEntries[splittedField[0]][splittedField[1]]=self.REQUEST.form[field]
537:
538: else:
539: query="UPDATE %s "%splittedField[0]
540: query+="SET %s = '%s' "%(splittedField[1],sql_quote(self.REQUEST.form[field]))
541: query+="WHERE oid = '%s' "%sql_quote(splittedField[2])
1.10.2.4 dwinter 542:
1.10.2.2 dwinter 543: self.ZSQLQuery(query)
544:
545:
546: #new entries
547: for newEntry in newEntries.keys():
548: query="INSERT INTO %s "%newEntry
1.10.2.33 dwinter 549: keys=['key_main']
550: values=["'"+sql_quote(key_main)+"'"]
1.10.2.2 dwinter 551: for key in newEntries[newEntry].keys():
552: keys.append(key)
1.10.2.27 dwinter 553: values.append("'"+sql_quote(newEntries[newEntry][key])+"'")
1.10.2.2 dwinter 554:
555:
556: keystring=",".join(keys)
557:
558: valuestring=",".join(values)
559:
560: query+=" (%s) "%keystring
561: query+="VALUES (%s)"%valuestring
562: if not (newEntries[newEntry][mainfield[newEntry]].lstrip().rstrip()==""):
563: self.ZSQLQuery(query)
564:
565: if not noredirect:
1.10.2.50 dwinter 566: self.redirect(RESPONSE,self.REQUEST['HTTP_REFERER'])
1.10.2.10 dwinter 567:
568: security.declareProtected('View management screens','editCV')
1.10.2.2 dwinter 569: def editCV(self,cv=None,oid=None,RESPONSE=None):
570: """edit Cv"""
571:
1.10.2.19 dwinter 572: if (not oid):
1.10.2.2 dwinter 573: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editCV.zpt')).__of__(self)
574: return pt()
575:
1.10.2.20 dwinter 576: query="UPDATE personal_www SET cv =%s WHERE oid='%s'"
1.10.2.62 dwinter 577: self.ZCacheable_invalidate()
1.10.2.20 dwinter 578: self.ZSQLQuery(query%(self.ZSQLQuote(cv),oid))
1.10.2.2 dwinter 579:
580: if RESPONSE:
1.10.2.50 dwinter 581: self.redirect(RESPONSE,"editCV")
1.10.2.43 dwinter 582:
583:
584: def getProfile(self):
585: """get the profile"""
1.10.2.51 dwinter 586: self.REQUEST.RESPONSE.setHeader('Last-Modified',email.Utils.formatdate().split("-")[0]+'GMT')
587:
1.10.2.68 dwinter 588: founds=self.ZSQLInlineSearchU(_table='personal_www',key=self.getKeyUTF8())
1.10.2.43 dwinter 589: html="""<html><body>%s</body></html>"""
590: if founds.profile and founds.profile != "":
591:
592: return html%founds.profile
593: else:
594:
595: return html%self.generateProfileForPerson(founds)
596:
597: def editProfile(self,oid=None,RESPONSE=None, kupu=None, preview=None):
598: """edit Profile, new entry replaces CD, current work and research interests"""
1.10.2.62 dwinter 599:
1.10.2.43 dwinter 600: if (not oid):
601: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editProfile.zpt')).__of__(self)
602: return pt()
603:
1.10.2.62 dwinter 604: self.ZCacheable_invalidate()
1.10.2.43 dwinter 605:
606:
607: if preview:
608: pass
609: #TODO: not supported yet
610: #kupu=preview
611: # find content of body tags
612:
613: start=kupu.find("<body>")
614: end=kupu.find("</body>")
615:
616: newcontent= kupu[start+6:end]
617:
618:
619:
620:
621: if preview:
622: #TODO: not supported yet
623: if RESPONSE:
1.10.2.50 dwinter 624: self.redirect(RESPONSE,"editProfile")
1.10.2.43 dwinter 625:
626: #return self.preview(newcontent)
627:
628: query="UPDATE personal_www SET profile=%s WHERE oid='%s'"
629: self.ZSQLQuery(query%(self.ZSQLQuote(newcontent),oid))
630: logging.error("PROFILE:"+query%(self.ZSQLQuote(newcontent),oid))
631: if RESPONSE:
1.10.2.50 dwinter 632: self.redirect(RESPONSE,"editProfile")
1.10.2.43 dwinter 633:
634:
635:
636: def generateProfileForPerson(self,person):
637: """erzeugt ein automatisches Profil aus den alten Eintraegen CV, Current work, und research interests"""
638:
639: ret=""
1.10.2.73! casties 640: founds=self.ZSQLInlineSearch(_table='research_interest',key_main=person.getKeyUTF8())
1.10.2.43 dwinter 641: if founds:
1.10.2.54 dwinter 642: ret="<p class=\"bio_section_header\">Research interests: </p><br/>"
1.10.2.43 dwinter 643: for found in self.sortPriority(founds):
644: ret+=found.interest+"<br/>"
645:
1.10.2.45 dwinter 646:
1.10.2.46 dwinter 647: if (person.current_work) and (not person.current_work==""):
1.10.2.58 casties 648: ret+="<p class=\"bio_section_header\">Current work: </p><br/>"
1.10.2.45 dwinter 649:
650: ret+=person.current_work+"<br/>"
1.10.2.58 casties 651: if (person.cv) and (not person.cv==""):
652: ret+="<p class=\"bio_section_header\">Curriculum Vitae: </p><br/>"
653: ret+=self.formatAscii(person.cv)
1.10.2.43 dwinter 654:
655: return ret
1.10.2.41 dwinter 656: security.declareProtected('View management screens','editDownloads')
657: def editDownloads(self):
658: """editiere die Downloads von der Webseite"""
659:
660: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editDownloads.zpt')).__of__(self)
661: return pt()
662:
1.10.2.48 dwinter 663: security.declareProtected('View management screens','editAdditionalLinks.zpt')
664: def editAdditionalLinks(self):
665: """editiere die Downloads von der Webseite"""
666:
667: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editAdditionalLinks.zpt')).__of__(self)
668: return pt()
669:
670:
1.10.2.10 dwinter 671: security.declareProtected('View management screens','editAwards')
1.10.2.2 dwinter 672: def editAwards(self,awards=None,oid=None,RESPONSE=None):
673: """edit a awards"""
1.10.2.19 dwinter 674:
675: if (not oid):
1.10.2.2 dwinter 676: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editAwards.zpt')).__of__(self)
677: return pt()
1.10.2.62 dwinter 678: self.ZCacheable_invalidate()
1.10.2.20 dwinter 679: query="UPDATE personal_www SET awards =%s WHERE oid='%s'"
1.10.2.19 dwinter 680:
1.10.2.20 dwinter 681: self.ZSQLQuery(query%(self.ZSQLQuote(awards),oid))
1.10.2.2 dwinter 682:
683: if RESPONSE:
1.10.2.50 dwinter 684: self.redirect(RESPONSE,"editAwards")
1.10.2.2 dwinter 685:
1.10.2.10 dwinter 686: security.declareProtected('View management screens','editTalks')
1.10.2.2 dwinter 687: def editTalks(self):
688: """edit talks"""
689:
690: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editTalks.zpt')).__of__(self)
691: return pt()
692:
1.10.2.10 dwinter 693: security.declareProtected('View management screens','editTeaching')
1.10.2.2 dwinter 694: def editTeaching(self):
695: """edit Teaching"""
696:
697: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editTeaching.zpt')).__of__(self)
698: return pt()
699:
1.10.2.4 dwinter 700: def getDocTypes(self):
701: finds = self.ZopeFind(self.metadata.main.meta.bib,obj_metatypes=["OSAS_MetadataMapping__neu"])
702:
703: list= [x[0] for x in finds]
704: return "\n".join(list)
1.10.2.5 dwinter 705:
1.10.2.10 dwinter 706: security.declareProtected('View management screens','editMainData')
1.10.2.33 dwinter 707: def editMainData(self,REQUEST=None,RESPONSE=None):
1.10.2.5 dwinter 708: """edit main data"""
1.10.2.62 dwinter 709: self.ZCacheable_invalidate()
1.10.2.33 dwinter 710: argv=REQUEST.form
711:
712: if not argv.has_key('last_name'):
1.10.2.5 dwinter 713: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editMainData.zpt')).__of__(self)
714: return pt()
715: else:
1.10.2.70 casties 716: self.ZSQLChange(argv,_table="personal_www",_identify="lower(key)=%s"%utf8ify(self.getKey().lower()),USE_FORM="yes")
1.10.2.5 dwinter 717: if RESPONSE:
1.10.2.50 dwinter 718: self.redirect(RESPONSE,"editMainData")
1.10.2.5 dwinter 719:
1.10.2.10 dwinter 720: security.declareProtected('View management screens','newBibliogrpaphy')
1.10.2.4 dwinter 721: def newBibliography(self,_docType=None, _addEntry=None,RESPONSE=None,**argv):
1.10.2.5 dwinter 722:
1.10.2.4 dwinter 723: """add an entry to the bibliography"""
724: if not _docType: #kein docType
725: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','newBibliographyEntryDocType.zpt')).__of__(self)
726: return pt()
727: elif _docType and not _addEntry: #doctype aber keine daten
728: self.REQUEST['_docType']=_docType
729: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','newBibliographyEntry.zpt')).__of__(self)
730: return pt()
731: else: #doctype und daten
1.10.2.5 dwinter 732: try:
733: newId=self.ZSQLSimpleSearch("select nextval('id_raw')")[0].nextval
734: except:#id_raw existiert nich, dann neu erzeugen
735:
736: self.createOrUpdateId_raw()
737: newId=self.ZSQLSimpleSearch("select nextval('id_raw')")[0].nextval
738:
1.10.2.4 dwinter 739: bookId="b%06i" % newId
740:
741: self.ZSQLAdd(argv,_table="bibliography",reference_type=_docType,id=bookId)
1.10.2.39 dwinter 742:
1.10.2.37 dwinter 743: self.ZSQLAdd(_useRequest=False,_table="publications",id_gen_bib=bookId,key_main=self.getDBId(),publish='yes')
1.10.2.4 dwinter 744: self.updatePublicationDB(personId=self.getDBId())
745:
746:
747: if RESPONSE:
1.10.2.50 dwinter 748: self.redirect(RESPONSE,"editPublications")
1.10.2.4 dwinter 749:
750: return True
751:
1.10.2.10 dwinter 752: security.declareProtected('View management screens','editImage')
1.10.2.5 dwinter 753: def editImage(self):
754: """edit images"""
755: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editImageStaff.zpt')).__of__(self)
756: return pt()
757:
1.10.2.10 dwinter 758: security.declareProtected('View management screens','editBibliography')
1.10.2.3 dwinter 759: def editBibliography(self):
760: """edit the bibliography"""
761: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editBibliographyEntry.zpt')).__of__(self)
762: return pt()
763:
764:
1.10.2.10 dwinter 765: security.declareProtected('View management screens','editPublications')
1.10.2.2 dwinter 766: def editPublications(self):
767: """edit the bibliographie"""
768:
769: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editPublications.zpt')).__of__(self)
770: return pt()
1.10.2.3 dwinter 771:
772: def changeSortingMode(self,sortingMode,RESPONSE=None,REQUEST=None):
773: """change sorting mode"""
1.10.2.62 dwinter 774: self.ZCacheable_invalidate()
1.10.2.3 dwinter 775: self.sortingMode=sortingMode
776:
777: if RESPONSE and REQUEST:
1.10.2.54 dwinter 778: self.redirect(RESPONSE,REQUEST['HTTP_REFERER'])
1.10.2.3 dwinter 779:
780: return True
1.10.2.2 dwinter 781:
1.10.2.3 dwinter 782: def getSortingMode(self):
783: """get sorting mode"""
1.10.2.33 dwinter 784: mode=getattr(self,'sortingMode','priority')
785: if mode=="year":
786: return "year DESC"
787: else:
1.10.2.35 casties 788: return mode
1.10.2.33 dwinter 789:
1.10.2.4 dwinter 790: def integer(self,value):
791: try:
792: return int(value)
793: except:
794: return 0
795:
1.10.2.10 dwinter 796: security.declareProtected('View management screens','changePublications')
1.10.2.50 dwinter 797: def changePublications(self,RESPONSE=None):
1.10.2.2 dwinter 798: """change the publication list"""
799: self.changeResearch(noredirect=True)
1.10.2.62 dwinter 800: self.ZCacheable_invalidate()
1.10.2.4 dwinter 801: #self.updatePublicationDB(personId=self.getDBId())
1.10.2.50 dwinter 802: self.redirect(RESPONSE,self.REQUEST['HTTP_REFERER'])
1.10.2.4 dwinter 803:
1.10.2.2 dwinter 804:
1.10.2.55 dwinter 805:
1.10.2.10 dwinter 806: security.declareProtected('View management screens','addPublications')
1.10.2.50 dwinter 807: def addPublications(self,submit=None,REQUEST=None,noredirect=None,RESPONSE=None):
1.10.2.2 dwinter 808: """add publications"""
809:
1.10.2.3 dwinter 810: #setzte flag ob aufruf aus suchformular
811:
812: if REQUEST.get("QUERY_STRING",None) and (not submit):
813: self.REQUEST.set('fromSearch','1')
814: else:
815: self.REQUEST.set('fromSearch','0')
816:
817: if not submit or (not (submit == "add")):
818: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addPublications.zpt')).__of__(self)
819: return pt()
820:
821: #new entries
822: entries = REQUEST.form.get('addEntries',None)
823: if not (type(entries) is ListType):
824: entries=[entries]
1.10.2.37 dwinter 825:
826:
1.10.2.3 dwinter 827: for bibId in entries:
828: query="INSERT INTO %s " % "publications"
1.10.2.33 dwinter 829: query+="(key_main,id_institutsbibliographie,publish) "
830: query+="VALUES ('%s','%s','yes')" %(sql_quote(self.getKey()),sql_quote(bibId))
1.10.2.18 dwinter 831:
1.10.2.5 dwinter 832: #self.ZSQLAdd(_table="publications",id_institutsbibliographie=bibId,id_main=self.getDBId(),publish='yes')
1.10.2.3 dwinter 833: self.ZSQLQuery(query)
834:
1.10.2.33 dwinter 835: self.updatePublicationDB(personId=self.getKey())
1.10.2.3 dwinter 836:
837: if not noredirect:
838:
1.10.2.50 dwinter 839: self.redirect(RESPONSE,"./editPublications")
1.10.2.3 dwinter 840:
841: return True
842:
843:
844: def getDBId(self):
845: """get id from the personal database"""
1.10.2.33 dwinter 846:
847: #in der neuen version ist definitions gemaess der key der Datenbank gleich dem key im Object.
848: # TODO: remove all occurences of getDBId and replaces it by getKey
849: return self.getKey()
850:
851: # search=self.ZSQLInlineSearch(_table='personal_www',key=self.getKey(),publish_the_data='yes')
852: # if search:#name existiert und published, dann nimm diesen falls es mehrereeventuell nich publizierte datensaetze gibt.
853: # return search[0].id
854: # else:#nicht publiziert dann nimm einen davon
855: # search2=self.ZSQLInlineSearch(_table='personal_www',username=self.getId())
856: # if search2:
857: # return search2[0].id
858: # else:
859: # return None
1.10.2.3 dwinter 860:
861:
862:
1.10.2.2 dwinter 863: formatBiblHelp=bibliography.formatBiblHelp
864:
1.10.2.33 dwinter 865: def sortBibliography(self,list,sortingMode=None,max=None):
1.10.2.5 dwinter 866: if not sortingMode:
867: sortingMode=self.getSortingMode()
868:
1.10.2.3 dwinter 869: if sortingMode == "year":
1.10.2.33 dwinter 870: l= self.sortYear(list)
1.10.2.3 dwinter 871: else:
1.10.2.33 dwinter 872: l=self.sortPriority(list)
873:
874: if max:
875: return l[0:min(len(l),max)]
876: else:
877: return l
1.10.2.2 dwinter 878:
1.10.2.3 dwinter 879: def sortPriority(self,list):
1.10.2.2 dwinter 880: def sort(x,y):
881: try:
882: xInt=int(x.priority)
883: except:
884: xInt=0
885: try:
886: yInt=int(y.priority)
887: except:
888: yInt=0
889:
890: return cmp(xInt,yInt)
891:
1.10.2.33 dwinter 892: if not list:
893: return []
1.10.2.3 dwinter 894: tmp=[x for x in list]
895: tmp.sort(sort)
1.10.2.33 dwinter 896:
1.10.2.2 dwinter 897: return tmp
898:
1.10.2.3 dwinter 899: def sortYear(self,list):
900: #TODO: sort TO APPEAR and TO BE PUBLISHED etc...
901:
902: def sort(x,y):
903: try:
904: xInt=int(x.year)
905: except:
906: xInt=0
907: try:
908: yInt=int(y.year)
909: except:
910: yInt=0
911:
912: return cmp(yInt,xInt)
913:
914:
915: tmp=[x for x in list]
916:
917: tmp.sort(sort)
918: return tmp
919:
1.10.2.54 dwinter 920: def deleteField(self,table,oid,RESPONSE=None):
1.10.2.2 dwinter 921: """delete entry"""
922: query="DELETE FROM %s WHERE oid = '%s'"%(table,oid)
1.10.2.5 dwinter 923:
1.10.2.2 dwinter 924: self.ZSQLQuery(query)
1.10.2.54 dwinter 925: self.redirect(RESPONSE,self.REQUEST['HTTP_REFERER'])
1.10.2.2 dwinter 926:
927:
1.1 dwinter 928: def manage_addMPIWGStaffForm(self):
929: """form for adding the project"""
1.10 dwinter 930: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMPIWGStaffForm.zpt')).__of__(self)
1.1 dwinter 931: return pt()
932:
933: def manage_addMPIWGStaff(self,id,lastName,firstName,RESPONSE=None):
934: """add it"""
935: newObj=MPIWGStaff(id,lastName,firstName)
936:
937: self._setObject(id,newObj)
938:
939:
940: if RESPONSE is not None:
1.10.2.50 dwinter 941: self.redirect(RESPONSE,'manage_main')
1.1 dwinter 942:
943:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>