File:  [Repository] / MPIWGWeb / MPIWGStaff.py
Revision 1.10.2.50: download - view: text, annotated - select for diffs - revision graph
Tue Aug 26 15:01:41 2008 UTC (15 years, 9 months ago) by dwinter
Branches: r2
reload problem und sonderzeichen

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>