--- MPIWGWeb/MPIWGProjects.py 2006/10/19 07:32:51 1.47.2.61 +++ MPIWGWeb/MPIWGProjects.py 2006/11/08 14:47:13 1.47.2.64 @@ -2,7 +2,7 @@ for organizing and maintaining the different project pages """ -#TODO: mechanismus fur links to personen ueberarbeiten, da jetzt alle e_mails als members auftauchen unabhaengig vom status publish_the_data +#TODO: mechanismus fur links to personen ueberarbeiten, da jetzt alle e_mails als members auftauchen unabhaenig vom status publish_the_data #TODO: was passiert wenn aenderungen von jochen im filemaker nicht mit den aenderungen im sql uebereinstimmen #TODO: in einzelnen projecte steht als pfad auf die bilder noch wwwneu statt www @@ -33,6 +33,7 @@ from Ft.Xml.XPath import Evaluate from Ft.Xml.XPath.Context import Context from Ft.Xml.Domlette import NonvalidatingReader,PrettyPrint, Print from Ft.Xml import EMPTY_NAMESPACE +import copy definedFields=['WEB_title','xdata_01','xdata_02','xdata_03','xdata_04','xdata_05','xdata_06','xdata_07','xdata_08','xdata_09','xdata_10','xdata_11','xdata_12','xdata_13','WEB_project_header','WEB_project_description','WEB_related_pub'] @@ -147,9 +148,9 @@ class MPIWGLink(SimpleItem): else: return self.getObj().weight - manage_options=SimpleItem.manage_options+( + manage_options=( {'label':'main config','action':'changeLinkForm'}, - ) + )+SimpleItem.manage_options def changeLinkForm(self): @@ -324,6 +325,35 @@ class MPIWGRoot(ZSQLExtendFolder): return str + + def browserCheck(self): + """check the browsers request to find out the browser type""" + bt = {} + ua = self.REQUEST.get_header("HTTP_USER_AGENT") + bt['ua'] = ua + bt['isIE'] = False + bt['isN4'] = False + if string.find(ua, 'MSIE') > -1: + bt['isIE'] = True + else: + bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1) + + try: + nav = ua[string.find(ua, '('):] + ie = string.split(nav, "; ")[1] + if string.find(ie, "MSIE") > -1: + bt['versIE'] = string.split(ie, " ")[1] + except: pass + + bt['isMac'] = string.find(ua, 'Macintosh') > -1 + bt['isWin'] = string.find(ua, 'Windows') > -1 + bt['isIEWin'] = bt['isIE'] and bt['isWin'] + bt['isIEMac'] = bt['isIE'] and bt['isMac'] + bt['staticHTML'] = False + + return bt + + def versionHeaderEN(self): """version header text""" @@ -453,6 +483,30 @@ class MPIWGRoot(ZSQLExtendFolder): return True return False + def getSection(self): + """returns the current section name""" + root = self.absolute_url() + url = self.REQUEST['URL'] + path = string.replace(url, root, '') + paths = path.split('/') + if len(paths) > 0: + sec = paths[1] + if sec.find('.') < 0: + return sec + else: + return None + return None + + def getSectionStyle(self, name, style=""): + """returns a string with the given style + '-sel' if the current section == name""" + if self.getSection() == name: + return style + '-sel' + else: + return style + + def MPIWGrootURL(self): + """returns the URL to the root""" + return self.absolute_url() def upDateSQL(self,fileName): """updates SQL databases using fm.jar""" @@ -585,86 +639,7 @@ class MPIWGRoot(ZSQLExtendFolder): """quote""" return urllib.unquote(str) - def harvestHistoricalPersons(self): - """erstelle liste aller erwaehnten actors""" - - def normalize(str): - """loesche fuhrendes space""" - if (len(str)>1) and (str[0]==" "): - ret=str[1:] - else: - ret=str - return ret - - list={} - projects=self.ZopeFind(self.projects,obj_metatypes=['MPIWGProject']) - - for project in projects: - lg=len(project[1].xdata_03[0])-1 - - if (lg>1) and (project[1].xdata_03[0][lg]==";"): - project[1].xdata_03[0]=project[1].xdata_03[0][0:lg] - - - - - try: - if len(project[1].xdata_03[0].split(";"))>1: # guess if separator is ; - for person in project[1].xdata_03[0].split(";"): - personNormal=normalize(person) - if personNormal in list.keys(): - list[urllib.quote(personNormal)][1].append(project[1]) - else: - list[urllib.quote(personNormal)]=(personNormal,[project[1]]) - else: #guess , is sepeator - for person in project[1].xdata_03[0].split(","): - personNormal=normalize(person) - if urllib.quote(personNormal) in list.keys(): - list[urllib.quote(personNormal)][1].append(project[1]) - else: - list[urllib.quote(personNormal)]=(personNormal,[project[1]]) - - except: - zLOG.LOG("MPIWG Web (harvestHistoricalPerson)",zLOG.ERROR,"cannot analyize: %s"%repr(project)) - - - return list - - def storeHistoricalPersons(self,RESPONSE=None): - """store persons""" - self.personDict={} - personDict=self.harvestHistoricalPersons() - for person in personDict.keys(): - for project in personDict[person][1]: - if person in self.personDict.keys(): - self.personDict[person][1].append((project.absolute_url(),project.WEB_title[0],project.xdata_01[0])) - else: - self.personDict[person]=(personDict[person][0],[(project.absolute_url(),project.WEB_title[0],project.xdata_01[0])]) - - if RESPONSE is not None: - RESPONSE.redirect("showHistoricalPersons") - - - def getPersonDict(self,name): - """name von dict""" - - try: - return self.personDict[name][0].encode('utf-8') - except: - return self.personDict[name][0] - return self.personDict[name][0].decode('latin-1').encode('utf-8') - - - def showHistoricalPersons(self): - """show persons""" - pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','showHistoricalPersons')).__of__(self) - return pt() - - def editHistoricalPersonsForm(self): - """edit historical persons for consistency""" - pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editHistoricalPersonsForm')).__of__(self) - return pt() def getProjectsByFieldContent(self,fieldName,fieldContentsEntry, date=None): """gib alle Projekte aus mit Value von field mit fieldName enthält ein Element der Liste fieldContents""" @@ -861,7 +836,7 @@ class MPIWGRoot(ZSQLExtendFolder): RESPONSE.write("\n") RESPONSE.write("Update Institutsbibliography\n") ret=self.upDateSQL('personalwww.xml') - RESPONSE.write("done Insitutsbibliography:%s\n"%ret) + RESPONSE.write("done Insitutsbibliography:%s\n"%ret) url="http://itgroup.mpiwg-berlin.mpg.de:8050/FMPro?-db=personal-www&-format=-dso_xml&-lay=sql_export&-max=20000&-findall" dom = NonvalidatingReader.parseUri(url) #fh=urllib.urlopen(url) @@ -1302,7 +1277,11 @@ class MPIWGRoot(ZSQLExtendFolder): if person =="Otto Sibum" : person="H. Otto Sibum" if person =="Norton Wise" : person="M. Norton Wise" #ret.append("%s"%(proj[0].absolute_url,person.encode('utf-8'))) - ret.append("%s"%(proj[0].absolute_url+"/index.html",person)) + if self.MPIWGrootURL().split("/")[-1]=='en': + tmpPath="/en/staff/members/" + else: + tmpPath="/de/mitarbeiter/members/" + ret.append("%s"%(tmpPath+proj[0].getObject().getId()+"/index.html",person)) else: #ret.append("%s"%person.encode('utf-8')) ret.append("%s"%person) @@ -1502,6 +1481,100 @@ class MPIWGRoot(ZSQLExtendFolder): self.nameIndex=results return results + def editNameIndexHTML(self): + """edit the name index""" + if not hasattr(self,'nameIndexEdited'): # falls editierter index noch nicht existiert, kopiere automatisch erstellten + self.nameIndexEdited=copy.copy(self.nameIndex) + print "huh" + #self.nameIndexEdited=copy.copy(self.nameIndex) + #print self.nameIndexEdited + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editHistoricalNames.zpt')).__of__(self) + return pt() + + def getNamesInProject(self,projectId): + """get all names ofnameIndexEdited which are references in projec with projectId""" + + ret=[] + for name in self.nameIndexEdited.keys(): + if projectId in self.nameIndexEdited[name]: + ret.append(name) + + return ret + + def editNameIndex(self,RESPONSE=None,name=None,occurrances=None,submit=None): + """edit the index""" + nI=self.nameIndexEdited # mI introduced to make sure that changes to nameIndexEdited are know to ZODB + if submit=="delete": + + + dh=getattr(self,'deletedHistoricalNames',{}) + if not dh.has_key(name): + dh=occurrances.split("\n") + else: + dh+=occurrances.split("\n") + + self.deletedHistoricalNames=dh + + del self.nameIndexEdited[name] + + + elif (submit=="change"): + + nI[name]=occurrances.split("\n")[0:] + + elif (submit=="add"): + if not nI.has_key(name): + nI[name]=occurrances.split("\n") + else: + nI[name]+=occurrances.split("\n") + + self.nameIndexEdited=nI + + + if RESPONSE is not None: + RESPONSE.redirect('editNameIndexHTML') + + + + def restoreIndex(self): + """restore""" + self.nameIndexEdited=self.nameIndex + return "done" + + def changeHistoricalNames(self,projId,nameListTmp): + """add resp change nameIndexEdited b + y adding/changing names menitionen in project projId""" + + #clear namelist from blanks + nameList=[x.lstrip().rstrip() for x in nameListTmp] + + nI=self.nameIndexEdited + for name in nameList: + if not nI.has_key(name): #neuer Name + nI[name]=[projId] + + for name in nI.keys(): + + if name in nameList: #checke if name in name List + + if not(projId in nI[name]): #nicht in listt -> hinzufuegen + + nI[name].append(projId) + + """loesche falls projekt in nI list aber der name nicht mehr + in der namensliste des projectes auftaucht + """ + + for pr in nI[name]: + + if (pr==projId) and (not name in nameList): + + nI[name].remove(pr) + + self.nameIndexEdited=nI + + + def manage_addMPIWGRootForm(self): """form for adding the root""" pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMPIWGRootForm.zpt')).__of__(self) @@ -2356,6 +2429,8 @@ class MPIWGProject(CatalogAware,Folder): setattr(self,x,[self.REQUEST[x].decode('utf-8')]) + self.en.changeHistoricalNames(self.getId(),self.REQUEST['historicalNames'].split("\n")) + if self.REQUEST.has_key('active'): self.setActiveFlag(True) else: @@ -2496,4 +2571,4 @@ def manage_addMPIWGProject(self,id,RESPO if RESPONSE is not None: - RESPONSE.redirect('manage_main') \ No newline at end of file + RESPONSE.redirect('manage_main')