--- MPIWGWeb/MPIWGProjects.py 2004/08/10 13:27:25 1.20 +++ MPIWGWeb/MPIWGProjects.py 2004/10/21 14:28:09 1.39 @@ -6,11 +6,12 @@ from Products.PageTemplates.PageTemplate from Products.PageTemplates.PageTemplate import PageTemplate from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate from Products.ZSQLExtend.ZSQLExtend import ZSQLExtendFolder - +from Globals import package_home import urllib import MPIWGStaff import string import re +import os from types import * import xmlhelper # Methoden zur Verwaltung der projekt xmls @@ -57,6 +58,74 @@ def sortI(x,y): except: return cmp(x[1],y[1]) +class MPIWGTemplate(ZopePageTemplate): + """Create a layout Template for different purposes""" + + meta_type="MPIWGTemplate" + + def __init__(self, id, text=None, content_type=None,MPIWGType=None): + self.id = str(id) + + + + self.ZBindings_edit(self._default_bindings) + if text is None: + self._default_content_fn = os.path.join(package_home(globals()), + 'zpt/MPIWG_%s_template_standard.zpt'%MPIWGType) + text = open(self._default_content_fn).read() + self.pt_edit(text, content_type) + + + """change form""" + + +def manage_addMPIWGTemplateForm(self): + """Form for adding""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/AddMPIWGTemplate.zpt')).__of__(self) + return pt() + +from urllib import quote + + +def manage_addMPIWGTemplate(self, MPIWGType,id, title=None,REQUEST=None): + "Add a Page Template with optional file content." + if type(MPIWGType)==StringType: + MPIWGTypes=[MPIWGType] + else: + MPIWGTypes=MPIWGType + + for singleType in MPIWGTypes: + + + if REQUEST is None: + self._setObject(id, MPIWGTemplate(id, text,EchoType=singleType)) + ob = getattr(self, id) + + if title: + ob.pt_setTitle(title) + return ob + else: + file = REQUEST.form.get('file') + headers = getattr(file, 'headers', None) + if headers is None or not file.filename: + zpt = MPIWGTemplate(id,MPIWGType=singleType) + else: + zpt = MPIWGTemplate(id, file, headers.get('content_type')) + + self._setObject(id, zpt) + ob = getattr(self, id) + if title: + ob.pt_setTitle(title) + + try: + u = self.DestinationURL() + except AttributeError: + u = REQUEST['URL1'] + + + REQUEST.RESPONSE.redirect(u+'/manage_main') + return '' + class MPIWGRoot(ZSQLExtendFolder): """Stammordner für den Web-Server""" @@ -69,9 +138,26 @@ class MPIWGRoot(ZSQLExtendFolder): 'xdata_13':'Funding institutions','WEB_project_header':'WEB_project_header', 'WEB_project_description':'WEB_project_description','WEB_related_pub':'WEB_related_pub'} - folders=['MPIWGProject','Folder'] + folders=['MPIWGProject','Folder','ECHO_Navigation'] meta_type='MPIWGRoot' + def upDateSQL(self,fileName): + """updates SQL databases using fm.jar""" + fmJarPath=os.path.join(package_home(globals()), 'updateSQL/fm.jar') + xmlPath=os.path.join(package_home(globals()), "updateSQL/%s"%fileName) + + os.popen("java -classpath %s -Djava.awt.headless=true Convert %s"%(fmJarPath,xmlPath),"r").read() + + return 1 + + def patchProjects(self,RESPONSE): + """patch""" + projects=self.ZopeFind(self.projects,obj_metatypes=['MPIWGProject']) + for project in projects: + tmp=project[1].WEB_project_description[0].replace("/CD/projects/","")[0:] + setattr(project[1],'WEB_project_description',[tmp[0:]]) + RESPONSE.write("

%s

\n"%project[0]) + def replaceNotEmpty(self,format,field): """replace not empty""" if field and (not field==''): @@ -79,25 +165,33 @@ class MPIWGRoot(ZSQLExtendFolder): else: return "" + + def redirectIndex_html(self,request): + #return request['URL1']+'/index_html' + return urllib.urlopen(request['URL1']+'/index_html').read() + + def formatBibliography(self,here,found): """format""" return formatBibliography(here,found) - def getValue(self,field): + def getValue(self,fieldStr): """Inhalt des Feldes""" - - if type(field)==StringType: - try: - if field[len(field)-1]==";": - field=field[0:len(text)-1] - except: - """nothing""" - - return field.encode('utf-8') + if type(fieldStr)==StringType: + field=fieldStr else: - return field[0].encode('utf-8') + field=fieldStr[0] + try: + if field[len(field)-1]==";": + field=field[0:len(field)-1] + except: + + """nothing""" + field=re.sub(r';([^\s])','; \g<1>',field) + return field.encode('utf-8') + def sortedNames(self,list): @@ -297,31 +391,24 @@ class MPIWGRoot(ZSQLExtendFolder): def getProjectFields(self,fieldName,folder=None,sort=None): """getListofFieldNames""" ret=[] - #print "FN",fieldName - if not folder: - folder=self - for object in folder.__dict__: - - obj=getattr(folder,object) - if hasattr(obj,'meta_type'): - #print obj.meta_type - if obj.meta_type=='MPIWGProject': - if fieldName=="WEB_title_or_short": - #print "HI!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" - #print len(obj.getContent('xdata_07')) - if len(obj.getContent('xdata_07'))<3: # hack weil z.Z. manchmal noch ein Trennzeichen ; oder , im Feld statt leer - fieldNameTmp="WEB_title" - else: - fieldNameTmp="xdata_07" - else: - fieldNameTmp=fieldName - - ret.append((obj,obj.getContent(fieldNameTmp))) + + objects=self.ZopeFind(self,obj_metatypes=['MPIWGProject'],search_sub=1) - if obj.meta_type in self.folders: + + for object in objects: + obj=object[1] + if fieldName=="WEB_title_or_short": + + if len(obj.getContent('xdata_07'))<3: # hack weil z.Z. manchmal noch ein Trennzeichen ; oder , im Feld statt leer + fieldNameTmp="WEB_title" + else: + fieldNameTmp="xdata_07" + else: + fieldNameTmp=fieldName - ret += self.getProjectFields(fieldName,obj) + ret.append((obj,obj.getContent(fieldNameTmp))) + if sort=="int": ret.sort(sortI) else: @@ -340,7 +427,7 @@ class MPIWGRoot(ZSQLExtendFolder): manage_options = Folder.manage_options+( - {'label':'Import Persons','action':'importNamesForm'}, + {'label':'Update Personal Homepages','action':'updateHomepages'}, {'label':'Main config','action':'changeMPIWGRootForm'}, {'label':'Edit Historical Persons','action':'editHistoricalPersonsForm'}, {'label':'Store Historical Persons','action':'storeHistoricalPersons'}, @@ -360,20 +447,56 @@ class MPIWGRoot(ZSQLExtendFolder): splitted=line.split(",") - print splitted + # print splitted if not (splitted[0]==""): newObj=MPIWGStaff.MPIWGStaff(splitted[0],splitted[1],splitted[2]) try: project._setObject(splitted[0],newObj) - print "done:",splitted[0] + #print "done:",splitted[0] except: print "not done:",splitted[0] if RESPONSE is not None: RESPONSE.redirect('manage_main') + def updateHomepages(self,RESPONSE): + """lege members an""" + + self.upDateSQL('personalwww.xml') + founds=self.ZSQLInlineSearch(_table='personal_www',publish_the_data='yes') + project=getattr(self,'members') + for found in founds: + + if not (found.e_mail==""): + newObj=MPIWGStaff.MPIWGStaff(found.username,found.name,found.vorname) + + try: + project._setObject(found.username,newObj) + RESPONSE.write("

new:%s

\n"%found.username) + except: + RESPONSE.write("

old:%s (%s,%s)

\n"%(found.username,found.name,found.vorname)) + + + #delete non existing + + + foundUserNames=[x.username for x in founds] + for member in self.ZopeFind(self,obj_metatypes=["MPIWGStaff"],search_sub=1): + + if member[1].getId() not in foundUserNames: + member[1].aq_parent.manage_delObjects(ids=[member[1].getId()]) + RESPONSE.write("

deleted:%s

\n"%member[1].getId()) + + self.MembersCatalog.manage_catalogReindex(self.REQUEST,RESPONSE,self.REQUEST['URL1']) + + + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + + def getAllMembers(self): """give list of all members""" ret=[] @@ -423,16 +546,24 @@ class MPIWGRoot(ZSQLExtendFolder): return returnList + def formatElementForOverview(self,element): """format the element for output in overview""" if element[0]==1: #department - return """

Department %s: %s

"""%(element[3].absolute_url(),element[3].getContent('xdata_05'),element[3].getContent('WEB_title')) + #print element[3].getContent('xdata_05') + if element[3].getContent('xdata_05') == "4": + return """

Ind. Research Group I: %s

"""%(element[3].absolute_url()+"/index.html",element[3].getContent('WEB_title')) + if element[3].getContent('xdata_05') == "5": + return """

Ind. Research Group II: %s

"""%(element[3].absolute_url()+"/index.html",element[3].getContent('WEB_title')) + + return """

Department %s: %s

"""%(element[3].absolute_url()+"/index.html",element[3].getContent('xdata_05'),element[3].getContent('WEB_title')) elif element[0]==2: #mainprojects - return """

%s

"""%(element[3].absolute_url(),element[3].getContent('WEB_title')) + return """

%s

"""%(element[3].absolute_url()+"/index.html",element[3].getContent('WEB_title')) elif element[0]==3: - return """
%s"""%(element[3].absolute_url(),element[3].getContent('WEB_title')) + return """

%s

"""%(element[3].absolute_url()+"/index.html",element[3].getContent('WEB_title')) + def changePosition(self,treeId,select,RESPONSE=None): """Change Postion Entry""" @@ -516,7 +647,7 @@ class MPIWGRoot(ZSQLExtendFolder): if proj: #ret.append("%s"%(proj[0].absolute_url,person.encode('utf-8'))) - ret.append("%s"%('members/'+proj[0].id,person)) + ret.append("%s"%('members/'+proj[0].id+'/index.html',person)) else: #ret.append("%s"%person.encode('utf-8')) ret.append("%s"%person) @@ -532,7 +663,7 @@ class MPIWGRoot(ZSQLExtendFolder): if len(person)>1: #nicht nur Trennzeichen splitted=person.split(",") if len(splitted)==1: - splitted=person.split(" ") + splitted=person.lstrip().rstrip().split(" ") splittedNew=[re.sub(r'\s(.*)','$1',split) for split in splitted] if splittedNew[0]=='': del splittedNew[0] @@ -546,8 +677,10 @@ class MPIWGRoot(ZSQLExtendFolder): proj=None if proj: + 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,person)) + ret.append("%s"%(proj[0].absolute_url+"/index.html",person)) else: #ret.append("%s"%person.encode('utf-8')) ret.append("%s"%person) @@ -574,18 +707,29 @@ class MPIWGRoot(ZSQLExtendFolder): ret=[] splitNeu=[] if email: - members=self.ZopeFind(self.members,obj_metatypes=['MPIWGStaff'],obj_ids=[email]) + #print "IIII:",self.getId() + members=self.ZopeFind(self,obj_metatypes=['MPIWGStaff'],obj_ids=[email],search_sub=1) name = members[0][1].title.decode('utf-8') y=name - splitted=y.split(",") - for s in splitted: - splitNeu.append("\""+s+"\"") + splitted=y.split(",") + #XXXX + splitNeu=["\'"+splitted[1]+" "+splitted[0]+"\'"] + + #for s in splitted: + # splitNeu.append("\""+s+"\"") search=string.join(splitNeu,' AND ') - + proj=self.ProjectCatalog({'xdata_01':search}) + if proj: - proj2=[x for x in proj] + proj2=[] + for x in proj: + + if not((splitted[1]==" Christoph") and (splitted[0]=="Hoffmann") and (str(x.WEB_title).find('Einstein')>0)): + + #print repr(splitted[1]),repr(splitted[0]),repr(x.WEB_title) + proj2.append(x) # proj2.sort(sortP) # ret.append((y,proj2)) else: @@ -611,8 +755,9 @@ class MPIWGRoot(ZSQLExtendFolder): splitted=name.split(",") if len(splitted)==1: - splitted=name.split(" ") - splittedNew=[re.sub(r'\s(.*)','$1',split) for split in splitted] + splitted=name.lstrip().rstrip().split(" ") + splittedNew=[split.lstrip() for split in splitted] + if splittedNew[0]=='': del splittedNew[0] search=string.join(splittedNew,' AND ') @@ -701,6 +846,7 @@ class MPIWGProject(Folder): meta_type='MPIWGProject' + def crossLinker(self): """experimental crosslinker""" splitted=self.WEB_project_description[0].split() @@ -759,6 +905,18 @@ class MPIWGProject(Folder): {'label':'Edit Themes & Disciplines','action':'editMPIWGDisciplinesThemesForm'}, ) + + def index_html(self): + """show homepage""" + ext=self.ZopeFind(self.aq_parent,obj_ids=["project_main"]) + + if ext: + return getattr(self,ext[0][1].getId())() + + pt=PageTemplateFile('Products/MPIWGWeb/zpt/project_main').__of__(self) + return pt() + + def getDataFields(self): """giveListofDatafields""" ret=[] @@ -793,17 +951,30 @@ class MPIWGProject(Folder): text=x.decode('latin-1').encode('utf-8') #delete separator (;) if is there is one + ## try: +## print text, text[len(text)-1] +## except: +## print "error:",text try: if text[len(text)-1]==";": - text=text[0:len(text)-1].encode('utf-8') + text=text[0:len(text)-1] + + except: """nothing""" - if (type(text)==StringType) or (type(text)==UnicodeType): - return text - else: - return text[0] + text2=re.sub(r';([^\s])','; \g<1>',text) + #teste ob ergebnis leer und header dann nehme title + + if (text2=='') and (field=='WEB_project_header'): + return self.getContent('WEB_title') + #teste ob WEB_project_description und keine führenden p tags + if (len(text2)>4) and (not text2[0:3]=='

') and (field=='WEB_project_description'): + return "

"+text2+"

" + #if text2=="Otto Sibum": + #text2="H. Otto Sibum" + return text2 def show_html(self): """simple index""" @@ -818,7 +989,7 @@ class MPIWGProject(Folder): def editMPIWGProject(self,RESPONSE=None): """edit the project""" - + #return self.REQUEST for x in definedFields: if self.REQUEST.has_key(x):