--- MPIWGWeb/MPIWGStaff.py 2004/02/04 10:03:33 1.1 +++ MPIWGWeb/MPIWGStaff.py 2006/07/27 09:01:00 1.10.2.28 @@ -1,14 +1,196 @@ """This file contains the classes for the organization of the staff""" +# TODO: pruefe ob die id der einzelnen tabellen, wie id in publications noch benutzt werden +# TODO: pruefe ob die bibliographischen felder in publications noch benutzt werden +# TODO: wird username gebraucht? from OFS.Folder import Folder +from Products.ZSQLExtend.ZSQLExtend import ZSQLExtendFolder from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplate import PageTemplate +from Products.ZCatalog.CatalogPathAwareness import CatalogAware +import os +import zLOG +import bibliography +from Globals import package_home +from Products.PythonScripts.standard import sql_quote +from types import * +from AccessControl import ClassSecurityInfo -class MPIWGStaff(Folder): +import zLOG + +departmentList="Renn\nRheinberger\nDaston\nKlein\nSibum\nIT\nInstitut\nBibliothek" + + +def getTemplate(self, tpName): + """get a template file either form the instance or from the product""" + ext=self.ZopeFind(self.aq_parent,obj_ids=[tpName]) + if ext: + pt = getattr(self,ext[0][1].getId()) + else: + pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/'+tpName)).__of__(self) + assert(pt) + return pt + +class MPIWGStaff(CatalogAware,ZSQLExtendFolder): """Staff""" meta_type="MPIWGStaff" + default_catalog='MembersCatalog' + departmentList=departmentList + security=ClassSecurityInfo() + + def getConnectionObj(self):#ueberschreibe connection id methode + + return getattr(self.de,self.de.connection_id) + + def isPublished(self): + """gib publications status aus der datenbank aus""" + username=self.getId() + query="select count(publish_the_data) from personal_www where username='%s' and publish_the_data='yes'"%username + + res = self.ZSQLQuery(query) + + if res and res[0].count>0: + return True + else: + return False + + def createNewDBEntry(self,publish_the_data,id,name,vorname,username,title,position,e_mail,e_mail_p,date_from,date_to,abteilung,heimat_inst,funded_by="",e_mail2="",txt="",txt_p="no",stay_at_mpiwg=""): + """lege person in der datenbank an""" + msg="" + #test ob id schon existiert + if self.ZSQLQuery("select id from personal_www where id='%s'"%id): + return False,"ERROR:id %s already exists"%id + + if self.ZSQLQuery("select username from personal_www where username='%s' and publish_the_data='yes'"%username): + + return False,"ERROR:username %s already exists and has data published, id=%s not added (running update again might solve this problem)"%(username,id) + + if self.ZSQLQuery("select username from personal_www where username='%s' and not publish_the_data='yes'"%username): + msg="WARNING:username %s not unique but id=%s added"%(username,id) + #eintragen + columnlist="publish_the_data,id,name,vorname,username,title,position,e_mail,e_mail_p,date_from,date_to,abteilung,heimat_inst,funded_by,e_mail2,stay_at_mpiwg" + insertTuple=(publish_the_data,id,name,vorname,username,title,position,e_mail,e_mail_p,date_from,date_to,abteilung,heimat_inst,funded_by,e_mail2,stay_at_mpiwg) + + insert=[] + for element in insertTuple: + insert.append("'%s'"%element) + + insertStr=",".join(insert) + queryStr="INSERT INTO personal_www (%s) VALUES (%s)"%(columnlist,insertStr) + self.ZSQLQuery("SET DATESTYLE TO 'German'") + self.ZSQLQuery(queryStr) + + #currentwork + if not (txt==""): + queryStr="INSERT INTO current_work (id_main,current,publish) VALUES ('%s','%s','%s')"%(id,txt,txt_p) + + self.ZSQLQuery(queryStr) + + return True,msg + + def updateDBEntry(self,publish_the_data,date_from,date_to,DBid=None,stay_at_mpiwg="",position="",abteilung=""): + """zpddatedb""" + if not DBid: + DBid=self.getDBId() + + self.ZSQLQuery("SET DATESTYLE TO 'German'") + + test=self.ZSQLQuery("select id from personal_www where id='%s' "%DBid) + + + if test and (len(test)>0): #dataset exists + zLOG.LOG("MPIWG Web",zLOG.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) + + self.ZSQLChange(_table="personal_www",_identify="id=%s"%DBid,publish_the_data=publish_the_data, + date_from=date_from, + date_to=date_to,stay_at_mpiwg=stay_at_mpiwg,position=position,abteilung=abteilung) + return True + else: + return False + + def getPublicationSelectionMode(self): + """get publication selection mode, default 'priority'""" + return getattr(self,'publicationSelectionMode','priority') + + def changePublicationSelectionMode(self,publicationSelectionMode,RESPONSE=None): + """change PublicationSelectionMode""" + + self.publicationSelectionMode=publicationSelectionMode + + if RESPONSE: + RESPONSE.redirect("editPublications") + + + def getPublishImage(self): + """publish the image??, default no""" + return getattr(self,'publishImage','no') + + def updateImage(self,file,publishImage,rename=None,RESPONSE=None): + """update image""" + + if file and not(file.filename==""): + if self.getImageObj(): + self.getImageObj().updateImage(file,rename=None,RESPONSE=None) + else: + # create new image object + xp = file.filename.rfind('.') + if xp > 0: + ext = file.filename[xp:] + fn = self.getId()+ext + zLOG.LOG("MPWIG STAFF", zLOG.INFO, "new filename: %s"%fn) + self.getImageFolder().addImage2(file,fileName=fn) + else: + zLOG.LOG("MPWIG STAFF", zLOG.ERROR, "uploaded filename %s has no extension!"%file.filename) + + self.publishImage=publishImage + + if RESPONSE: + RESPONSE.redirect("edit") + + def getImageFolder(self): + """getImageFolder""" + #TODO: make place of staff image folder configurable + + try: + return self.getPhysicalRoot().www_neu.images.staff_images + except: + zLOG.LOG("MPWIG STAFF", zLOG.ERROR, "image folder not found:"," has to be add /www_neu/staff_images") + return None + + def getImageObj(self): + """getImage""" + imageFolder=self.getImageFolder() + + if not imageFolder: return None + + image=getattr(imageFolder,self.getId(),None) + + if not image: + for suffix in ['jpg','tif']: + + image=getattr(imageFolder,self.getId()+"."+suffix,None) + if image: + break + return image + + def getImageUrl(self): + """getImageUrl""" + image=self.getImageObj() + if not image: + return None + else: + return self.getImageObj().absolute_url()+"/image" + + def PrincipiaSearchSource(self): + """Return cataloguable key for ourselves.""" + return str(self) + manage_options = Folder.manage_options+( + {'label':'Edit','action':'changeMPIWGStaffForm'}, + {'label':'Change Publications Special','action':'changePublications_specialForm'}, + ) + def __init__(self,id, lastName,firstName): """init""" self.id=id @@ -16,30 +198,392 @@ class MPIWGStaff(Folder): self.lastName=lastName self.firstName=firstName - manage_options = Folder.manage_options+( - {'label':'Edit','action':'changeMPIWGStaffForm'}, - ) + def harvest_page(self): + """geharvestete seite = verschlankte version von members_main""" + pt = getTemplate(self, "harvest_members_main") + return pt() + def index_html(self): - """show homepage, presently only a redirect""" - red="http://www.mpiwg-berlin.mpg.de/members/"+self.getId() - return self.REQUEST.RESPONSE.redirect(red) + """show homepage""" + pt = getTemplate(self, "members_main") + return pt() + + def changePublications_specialForm(self): + """Priority publications manual field""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changePublications_special.zpt')).__of__(self) + return pt() + + def changePublications_special(self,usePublicationsSpecial=None,specialPublicationsField=None,RESPONSE=None): + """change publications special params""" + if usePublicationsSpecial: + self.usePublicationsSpecial=True + + else: + self.usePublicationsSpecial=False + + self.specialPublicationsField=specialPublicationsField[0:] + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + + + def publications_full(self): + """show publication""" + pt=getTemplate(self, "publications_full_main") + return pt() + + def talks_full(self): + """show talks""" + pt=getTemplate(self, 'talks_full_main') + return pt() + def teaching_full(self): + """show talks""" + pt=getTemplate(self, 'teaching_full_main') + return pt() + def changeMPIWGStaffForm(self): """change form""" - pt=PageTemplateFile('Products/MPIWGWeb/zpt/edit_MPIWGStaff.zpt').__of__(self) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGStaff.zpt')).__of__(self) return pt() - - def changeMPIWGStaff(self): + + security.declareProtected('View management screens','changeMPIWGStaff') + def changeMPIWGStaff(self,lastName,firstName,RESPONSE=None): """change it""" - self.title="%s, %s"%(lastname,firstName) + self.title="%s, %s"%(lastName,firstName) self.lastName=lastName self.firstName=firstName + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + + security.declareProtected('View management screens','edit') + def edit(self): + """Edit the pages""" + #TODO: zusammenspiel mit apache, redirect auf 18080 rausnehmen bzw. zumindest verallgemeinern + if self.REQUEST['SERVER_URL']=="http://www.mpiwg-berlin.mpg.de": + redURL="http://xserve04.mpiwg-berlin.mpg.de:18080/www_neu/de/mitarbeiter/members/%s/edit"%self.getId() + + self.REQUEST.RESPONSE.redirect(redURL) + + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editMPIWGStaff.zpt')).__of__(self) + return pt() + + mainEditFile=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editMPIWGStaff_main.zpt')) + + def getPathStyle(self, path, selected, style=""): + """returns a string with the given style + 'sel' if path == selected.""" + + if path == selected: + return style + 'sel' + else: + return style + + security.declareProtected('View management screens','changeResearch') + def changeResearch(self,noredirect=None): + """change the research entries""" + newEntries={} + id_main=self.REQUEST.form['id_main'] + + mainfieldL=self.REQUEST.form['main_fields'].split(",") + mainfield={} + for x in mainfieldL: + tmp=x.split('__') + mainfield[tmp[0]]=tmp[1] + for field in self.REQUEST.form.keys(): + splittedField=field.split("__") + if len(splittedField)<3: + pass #kein datenbank eintrag + + elif splittedField[2]=='new': # store new entries + if not newEntries.has_key(splittedField[0]): + newEntries[splittedField[0]]={} + + newEntries[splittedField[0]][splittedField[1]]=self.REQUEST.form[field] + + else: + query="UPDATE %s "%splittedField[0] + query+="SET %s = '%s' "%(splittedField[1],sql_quote(self.REQUEST.form[field])) + query+="WHERE oid = '%s' "%sql_quote(splittedField[2]) + + self.ZSQLQuery(query) + + + #new entries + for newEntry in newEntries.keys(): + query="INSERT INTO %s "%newEntry + keys=['id_main'] + values=["'"+sql_quote(id_main)+"'"] + for key in newEntries[newEntry].keys(): + keys.append(key) + values.append("'"+sql_quote(newEntries[newEntry][key])+"'") + + + keystring=",".join(keys) + + valuestring=",".join(values) + + query+=" (%s) "%keystring + query+="VALUES (%s)"%valuestring + if not (newEntries[newEntry][mainfield[newEntry]].lstrip().rstrip()==""): + self.ZSQLQuery(query) + + if not noredirect: + self.REQUEST.RESPONSE.redirect(self.REQUEST['HTTP_REFERER']) + + security.declareProtected('View management screens','editCV') + def editCV(self,cv=None,oid=None,RESPONSE=None): + """edit Cv""" + + if (not oid): + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editCV.zpt')).__of__(self) + return pt() + + query="UPDATE personal_www SET cv =%s WHERE oid='%s'" + + self.ZSQLQuery(query%(self.ZSQLQuote(cv),oid)) + + if RESPONSE: + RESPONSE.redirect("editCV") + + security.declareProtected('View management screens','editAwards') + def editAwards(self,awards=None,oid=None,RESPONSE=None): + """edit a awards""" + + if (not oid): + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editAwards.zpt')).__of__(self) + return pt() + + query="UPDATE personal_www SET awards =%s WHERE oid='%s'" + + self.ZSQLQuery(query%(self.ZSQLQuote(awards),oid)) + + if RESPONSE: + RESPONSE.redirect("editAwards") + + security.declareProtected('View management screens','editTalks') + def editTalks(self): + """edit talks""" + + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editTalks.zpt')).__of__(self) + return pt() + + security.declareProtected('View management screens','editTeaching') + def editTeaching(self): + """edit Teaching""" + + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editTeaching.zpt')).__of__(self) + return pt() + + def getDocTypes(self): + finds = self.ZopeFind(self.metadata.main.meta.bib,obj_metatypes=["OSAS_MetadataMapping__neu"]) + + list= [x[0] for x in finds] + return "\n".join(list) + + security.declareProtected('View management screens','editMainData') + def editMainData(self,REQUEST=None,RESPONSE=None,name=None,**argv): + """edit main data""" + if not name: + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editMainData.zpt')).__of__(self) + return pt() + else: + self.ZSQLChange(argv,_table="personal_www",_identify="id=%s"%self.getDBId(),USE_FORM="yes") + if RESPONSE: + RESPONSE.redirect("editMainData") + + security.declareProtected('View management screens','newBibliogrpaphy') + def newBibliography(self,_docType=None, _addEntry=None,RESPONSE=None,**argv): + + """add an entry to the bibliography""" + if not _docType: #kein docType + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','newBibliographyEntryDocType.zpt')).__of__(self) + return pt() + elif _docType and not _addEntry: #doctype aber keine daten + self.REQUEST['_docType']=_docType + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','newBibliographyEntry.zpt')).__of__(self) + return pt() + else: #doctype und daten + try: + newId=self.ZSQLSimpleSearch("select nextval('id_raw')")[0].nextval + except:#id_raw existiert nich, dann neu erzeugen + + self.createOrUpdateId_raw() + newId=self.ZSQLSimpleSearch("select nextval('id_raw')")[0].nextval + + bookId="b%06i" % newId + + self.ZSQLAdd(argv,_table="bibliography",reference_type=_docType,id=bookId) + self.ZSQLAdd(_table="publications",id_gen_bib=bookId,id_main=self.getDBId(),publish='yes') + self.updatePublicationDB(personId=self.getDBId()) + + + if RESPONSE: + RESPONSE.redirect("editPublications") + + return True + + security.declareProtected('View management screens','editImage') + def editImage(self): + """edit images""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editImageStaff.zpt')).__of__(self) + return pt() + + security.declareProtected('View management screens','editBibliography') + def editBibliography(self): + """edit the bibliography""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editBibliographyEntry.zpt')).__of__(self) + return pt() + + + security.declareProtected('View management screens','editPublications') + def editPublications(self): + """edit the bibliographie""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editPublications.zpt')).__of__(self) + return pt() + + def changeSortingMode(self,sortingMode,RESPONSE=None,REQUEST=None): + """change sorting mode""" + self.sortingMode=sortingMode + + if RESPONSE and REQUEST: + REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER']) + + return True + + def getSortingMode(self): + """get sorting mode""" + return getattr(self,'sortingMode','priority') + + def integer(self,value): + try: + return int(value) + except: + return 0 + + security.declareProtected('View management screens','changePublications') + def changePublications(self): + """change the publication list""" + self.changeResearch(noredirect=True) + + #self.updatePublicationDB(personId=self.getDBId()) + self.REQUEST.RESPONSE.redirect(self.REQUEST['HTTP_REFERER']) + + + security.declareProtected('View management screens','addPublications') + def addPublications(self,submit=None,REQUEST=None,noredirect=None): + """add publications""" + + #setzte flag ob aufruf aus suchformular + + if REQUEST.get("QUERY_STRING",None) and (not submit): + self.REQUEST.set('fromSearch','1') + else: + self.REQUEST.set('fromSearch','0') + + if not submit or (not (submit == "add")): + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addPublications.zpt')).__of__(self) + return pt() + + #new entries + entries = REQUEST.form.get('addEntries',None) + if not (type(entries) is ListType): + entries=[entries] + + for bibId in entries: + query="INSERT INTO %s " % "publications" + query+="(id_main,id_institutsbibliographie,publish) " + query+="VALUES ('%s','%s','yes')" %(sql_quote(self.getDBId()),sql_quote(bibId)) + + #self.ZSQLAdd(_table="publications",id_institutsbibliographie=bibId,id_main=self.getDBId(),publish='yes') + self.ZSQLQuery(query) + + self.updatePublicationDB(personId=self.getDBId()) + + if not noredirect: + + self.REQUEST.RESPONSE.redirect("./editPublications") + + return True + + + def getDBId(self): + """get id from the personal database""" + search=self.ZSQLInlineSearch(_table='personal_www',username=self.getId(),publish_the_data='yes') + if search:#name existiert und published, dann nimm diesen falls es mehrereeventuell nich publizierte datensaetze gibt. + return search[0].id + else:#nicht publiziert dann nimm einen davon + search2=self.ZSQLInlineSearch(_table='personal_www',username=self.getId()) + if search2: + return search2[0].id + else: + return None + + + + formatBiblHelp=bibliography.formatBiblHelp + + def sortBibliography(self,list,sortingMode=None): + if not sortingMode: + sortingMode=self.getSortingMode() + + if sortingMode == "year": + return self.sortYear(list) + else: + return self.sortPriority(list) + + def sortPriority(self,list): + def sort(x,y): + try: + xInt=int(x.priority) + except: + xInt=0 + try: + yInt=int(y.priority) + except: + yInt=0 + + return cmp(xInt,yInt) + + tmp=[x for x in list] + tmp.sort(sort) + return tmp + + def sortYear(self,list): + #TODO: sort TO APPEAR and TO BE PUBLISHED etc... + + def sort(x,y): + try: + xInt=int(x.year) + except: + xInt=0 + try: + yInt=int(y.year) + except: + yInt=0 + + return cmp(yInt,xInt) + + + tmp=[x for x in list] + + tmp.sort(sort) + return tmp + + def deleteField(self,table,oid): + """delete entry""" + query="DELETE FROM %s WHERE oid = '%s'"%(table,oid) + + self.ZSQLQuery(query) + self.REQUEST.RESPONSE.redirect(self.REQUEST['HTTP_REFERER']) + + def manage_addMPIWGStaffForm(self): """form for adding the project""" - pt=PageTemplateFile('Products/MPIWGWeb/zpt/addMPIWGStaffForm.zpt').__of__(self) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMPIWGStaffForm.zpt')).__of__(self) return pt() def manage_addMPIWGStaff(self,id,lastName,firstName,RESPONSE=None):