--- MPIWGWeb/MPIWGProjects.py 2004/09/30 20:00:40 1.31 +++ 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,15 +138,25 @@ 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: - project[1].WEB_project_description[0]=project[1].WEB_project_description[0].replace("/CD/projects/einstein/","") - RESPONSE.write("
%s
\n"%project[0]) + 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""" @@ -312,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: @@ -355,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'}, @@ -389,6 +461,42 @@ class MPIWGRoot(ZSQLExtendFolder): 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=[] @@ -438,22 +546,24 @@ class MPIWGRoot(ZSQLExtendFolder): return returnList + def formatElementForOverview(self,element): """format the element for output in overview""" if element[0]==1: #department #print element[3].getContent('xdata_05') if element[3].getContent('xdata_05') == "4": - return """"""%(element[3].absolute_url()+"/index.html",element[3].getContent('WEB_title')) + return """
"""%(element[3].absolute_url()+"/index.html",element[3].getContent('WEB_title')) elif element[0]==3: - return """
"""%(element[3].absolute_url()+"/index.html",element[3].getContent('WEB_title')) + return """"""%(element[3].absolute_url()+"/index.html",element[3].getContent('WEB_title')) + def changePosition(self,treeId,select,RESPONSE=None): """Change Postion Entry""" @@ -567,6 +677,8 @@ 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+"/index.html",person)) else: @@ -595,7 +707,8 @@ 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 @@ -733,6 +846,7 @@ class MPIWGProject(Folder): meta_type='MPIWGProject' + def crossLinker(self): """experimental crosslinker""" splitted=self.WEB_project_description[0].split() @@ -791,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=[] @@ -846,7 +972,8 @@ class MPIWGProject(Folder): #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):