--- MPIWGWeb/MPIWGStaff.py 2005/10/10 08:42:48 1.10.2.2 +++ MPIWGWeb/MPIWGStaff.py 2005/10/11 13:14:01 1.10.2.4 @@ -1,4 +1,8 @@ """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: auswahl der ausgewaehlten publication auf der ersten seite der homepage + from OFS.Folder import Folder from Products.ZSQLExtend.ZSQLExtend import ZSQLExtendFolder from Products.PageTemplates.PageTemplateFile import PageTemplateFile @@ -8,6 +12,8 @@ import os import bibliography from Globals import package_home from Products.PythonScripts.standard import sql_quote +from types import * + def getTemplate(self, tpName): """get a template file either form the instance or from the product""" @@ -128,7 +134,7 @@ class MPIWGStaff(CatalogAware,ZSQLExtend 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) @@ -195,30 +201,132 @@ class MPIWGStaff(CatalogAware,ZSQLExtend 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) + + 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 + 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 + + def editBibliography(self): + """edit the bibliography""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editBibliographyEntry.zpt')).__of__(self) + return pt() + + + 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 + + def changePublications(self): """change the publication list""" - self.changeResearch(noredirect=True) + + #self.updatePublicationDB(personId=self.getDBId()) self.REQUEST.RESPONSE.redirect(self.REQUEST['HTTP_REFERER']) + - def addPublications(self): + def addPublications(self,submit=None,REQUEST=None,noredirect=None): """add publications""" - pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addPublications.zpt')).__of__(self) - return pt() - + #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) " + query+="VALUES ('%s','%s')" %(sql_quote(self.getDBId()),sql_quote(bibId)) + + 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()) + if search: + return search[0].id + else: + return None + + + formatBiblHelp=bibliography.formatBiblHelp - def sortPriority(self,list): - tmp=[x for x in list] + def sortBibliography(self,list): + 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) @@ -231,9 +339,31 @@ class MPIWGStaff(CatalogAware,ZSQLExtend return cmp(xInt,yInt) - tmp.sort(sort) + 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)