--- 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 """"""%(element[3].absolute_url(),element[3].getContent('WEB_title')) + return """
"""%(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 """
') 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):