--- MPIWGWeb/MPIWGStaff.py 2005/10/14 17:13:37 1.10.2.10 +++ MPIWGWeb/MPIWGStaff.py 2006/07/27 09:01:00 1.10.2.28 @@ -9,12 +9,15 @@ from Products.PageTemplates.PageTemplate 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 +import zLOG + departmentList="Renn\nRheinberger\nDaston\nKlein\nSibum\nIT\nInstitut\nBibliothek" @@ -52,7 +55,7 @@ class MPIWGStaff(CatalogAware,ZSQLExtend else: return False - def createNewDBEntry(self,publish_the_data,id,name,vorname,username,title,e_mail,e_mail_p,date_from,date_to,abteilung,heimat_inst,funded_by="",e_mail2="",txt="",txt_p="no"): + 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 @@ -66,35 +69,45 @@ class MPIWGStaff(CatalogAware,ZSQLExtend 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,e_mail,e_mail_p,date_from,date_to,abteilung,heimat_inst,funded_by,e_mail2" - insertTuple=(publish_the_data,id,name,vorname,username,title,e_mail,e_mail_p,date_from,date_to,abteilung,heimat_inst,funded_by,e_mail2) + 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,insertTuple) - + 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): + 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'") - self.ZSQLChange(_table="personal_www",_identify="id=%s"%DBid,publish_the_data=publish_the_data, + + 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) - + 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'""" @@ -115,12 +128,20 @@ class MPIWGStaff(CatalogAware,ZSQLExtend 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: - self.getImageFolder().addImage2(file,fileName=self.getId()) + + 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 @@ -129,12 +150,20 @@ class MPIWGStaff(CatalogAware,ZSQLExtend def getImageFolder(self): """getImageFolder""" - return self.getPhysicalRoot().www_neu.images.staff_images - + #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: @@ -169,6 +198,10 @@ class MPIWGStaff(CatalogAware,ZSQLExtend self.lastName=lastName self.firstName=firstName + 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""" @@ -227,17 +260,25 @@ class MPIWGStaff(CatalogAware,ZSQLExtend 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() + #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) + 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""" @@ -272,10 +313,10 @@ class MPIWGStaff(CatalogAware,ZSQLExtend for newEntry in newEntries.keys(): query="INSERT INTO %s "%newEntry keys=['id_main'] - values=["'"+id_main+"'"] + values=["'"+sql_quote(id_main)+"'"] for key in newEntries[newEntry].keys(): keys.append(key) - values.append("'"+newEntries[newEntry][key]+"'") + values.append("'"+sql_quote(newEntries[newEntry][key])+"'") keystring=",".join(keys) @@ -294,13 +335,13 @@ class MPIWGStaff(CatalogAware,ZSQLExtend def editCV(self,cv=None,oid=None,RESPONSE=None): """edit Cv""" - if (not 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%(cv,oid)) + query="UPDATE personal_www SET cv =%s WHERE oid='%s'" + + self.ZSQLQuery(query%(self.ZSQLQuote(cv),oid)) if RESPONSE: RESPONSE.redirect("editCV") @@ -308,14 +349,14 @@ class MPIWGStaff(CatalogAware,ZSQLExtend security.declareProtected('View management screens','editAwards') def editAwards(self,awards=None,oid=None,RESPONSE=None): """edit a awards""" - - if (not 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%(awards,oid)) + query="UPDATE personal_www SET awards =%s WHERE oid='%s'" + + self.ZSQLQuery(query%(self.ZSQLQuote(awards),oid)) if RESPONSE: RESPONSE.redirect("editAwards") @@ -349,8 +390,7 @@ class MPIWGStaff(CatalogAware,ZSQLExtend pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editMainData.zpt')).__of__(self) return pt() else: - - self.ZSQLChange(argv,_table="personal_www",_identify="<%s"%self.getDBId(),USE_FORM="yes") + self.ZSQLChange(argv,_table="personal_www",_identify="id=%s"%self.getDBId(),USE_FORM="yes") if RESPONSE: RESPONSE.redirect("editMainData") @@ -457,7 +497,7 @@ class MPIWGStaff(CatalogAware,ZSQLExtend query="INSERT INTO %s " % "publications" query+="(id_main,id_institutsbibliographie,publish) " query+="VALUES ('%s','%s','yes')" %(sql_quote(self.getDBId()),sql_quote(bibId)) - print "ADD",query + #self.ZSQLAdd(_table="publications",id_institutsbibliographie=bibId,id_main=self.getDBId(),publish='yes') self.ZSQLQuery(query)