--- MPIWGWeb/MPIWGProjects.py 2004/02/09 08:57:27 1.3 +++ MPIWGWeb/MPIWGProjects.py 2005/04/25 16:58:02 1.46 @@ -1,134 +1,783 @@ -"""This files contains the class MPIWG Projects""" +"""This contains the class MPIWG Projects +for organizing and maintaining the different project pages + +""" from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplate import PageTemplate from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate - +from Products.ZSQLExtend.ZSQLExtend import ZSQLExtendFolder +from Products.ZCatalog.CatalogPathAwareness import CatalogAware +from Globals import package_home +import urllib import MPIWGStaff import string import re - +import os +from types import * +import zLOG import xmlhelper # Methoden zur Verwaltung der projekt xmls from OFS.SimpleItem import SimpleItem from OFS.Folder import Folder +from Products.ZSQLMethods.SQL import SQLConnectionIDs + +from bibliography import * +import time 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'] checkFields = ['xdata_01'] + + def sortF(x,y): + try: + return cmp(x[1],y[1]) + except: + try: + return cmp(str(x[1]),str(y[1])) + except: + + return 0 + +def sortI(x,y): + xsplit=x[1].split(".") + ysplit=y[1].split(".") + xret="" + yret="" + try: + for i in range(5): + try: + yret=yret+"%04i"%int(xsplit[i]) + except: + yret=yret+"%04i"%0 - return cmp(x[1],y[1]) + try: + xret=xret+"%04i"%int(ysplit[i]) + except: + xret=xret+"%04i"%0 + + + return cmp(int(yret),int(xret)) + except: + return cmp(x[1],y[1]) + +class MPIWGTemplate(ZopePageTemplate): + """Create a layout Template for different purposes""" + + meta_type="MPIWGTemplate" -class MPIWGRoot(Folder): + 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""" - folders=['MPIWGProject','Folder'] + fieldLabels={'WEB_title':'WEB_Title','xdata_01':'Responsible Scientists','xdata_02':'Department', + 'xdata_03':'Historical Persons','xdata_04':'Time period', + 'xdata_05':'Sorting number','xdata_06':'Keywords','xdata_07':'Short title', + 'xdata_08':'Other involved scholars' ,'xdata_09':'Part of','xdata_10':'Covered by', + 'xdata_11':'Object Digitallibrary','xdata_12':'Cooperation partners', + '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','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) + zLOG.LOG("MPIWG Web",zLOG.INFO,"java -classpath %s -Djava.awt.headless=true Convert %s"%(fmJarPath,xmlPath)) + ret=os.popen("java -classpath %s -Djava.awt.headless=true Convert %s"%(fmJarPath,xmlPath),"r").read() + zLOG.LOG("MPIWG Web",zLOG.INFO,"result convert: %s"%ret) + 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.lstrip()==''): + return format%field + else: + return "" + + + def isActual(self,project): + """checke if project is actual""" + actualTime=time.localtime() + obj= project.getObject() + + if getattr(obj,'archiveTime',actualTime)< actualTime: + return False + else: + return True + + 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,fieldStr): + """Inhalt des Feldes""" + + if type(fieldStr)==StringType: + field=fieldStr + else: + 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): + """sort names""" + + def sortLastName(x_c,y_c): + try: + x=urllib.unquote(x_c).encode('utf-8','ignore') + except: + x=urllib.unquote(x_c) + + try: + y=urllib.unquote(y_c).encode('utf-8','ignore') + except: + x=urllib.unquote(y_c) + + + + try: + last_x=x.split()[len(x.split())-1] + last_y=y.split()[len(y.split())-1] + + except: + + last_x="" + last_y="" + + + + if last_xnew:%s
\n"%found.username) except: - print "not done:",splitted[0] + 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()) + try: + self.MembersCatalog.manage_catalogReindex(self.REQUEST,RESPONSE,self.REQUEST['URL1']) + except: + pass + self.ProjectCatalog.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=[] - for x in self.members.objectValues('MPIWGStaff'): - print x.title - ret.append(x.title) + #for x in self.members.objectValues('MPIWGStaff'): + #print x.title + # ret.append(x.title.decode('utf-8')) + + for x in self.ZopeFind(self.members,obj_metatypes=['MPIWGStaff']): + ret.append(x[1].title.decode('utf-8')) ret.sort() + #print ret + return ret - def getUrlFromPerson(self,list): + def printAllMembers(self): + """prin""" + members=self.getAllMembers() + ret="" + for x in members: + ret+="%s
"%x + return ret + + + def makeList(self,entry): + """makes a list out of one entry or repeat a list""" + if type(entry) is StringType: + return [entry] + else: + return entry + + + def getTree(self): + """generate Tree from project list""" + returnList=[] + for project in self.getProjectFields('xdata_05',sort="int"): # get Projects sorted by xdata_05 + + for idNr in project[1].split(";"): # more than one number + if not idNr=="": + splittedId=idNr.split(".") + depth=len(splittedId) + nr=idNr + #title=project[0].WEB_title + title=[project[0].getContent('WEB_title')] + #print title + returnList.append((depth,nr,title,project[0])) + + 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')) + + elif element[0]==3: + return """
"""%(element[3].absolute_url()+"/index.html",element[3].getContent('WEB_title')) + + + def changePosition(self,treeId,select,RESPONSE=None): + """Change Postion Entry""" + numbers=[] + + # Suche hoechste bisherige nummer + projects=self.getProjectFields('xdata_05') # get Projects sorted by xdata_05 + #print "pj",projects + for project in projects: #suche alle subtrees der treeId + #print treeId + + founds=re.match(treeId+"\.(.*)",project[1].split(";")[0]) + if founds: + #print "x",founds.group(0),len(founds.group(0).split(".")) + if len(founds.group(0).split("."))==len(treeId.split("."))+1: # nur ein punkt mehr, d.h. untere ebene + try: + numbers.append(int(founds.group(0).split(".")[len(founds.group(0).split("."))-1])) + except: + numbers.append(int(0)) + + try: + highest=max(numbers) + except: + highest=0 + projects=self.showNewProjects() + for i in self.makeList(select): + highest+=10 + projects[int(i)][0].xdata_05=treeId+"."+str(highest) + + + if RESPONSE is not None: + RESPONSE.redirect('showTree') + + def changeTree(self,RESPONSE=None): + """change the complete tree""" + form=self.REQUEST.form + hashList={} + fields=self.getTree() + + + for idNr in form.keys(): + fields[int(idNr)][3].xdata_05=form[idNr] + + + + if RESPONSE is not None: + RESPONSE.redirect('showTree') + + def getProjectWithId(self,id): + fields=self.getProjectFields('xdata_05') + for field in fields: + if field[1]==id: + return field[0] + + return None + + + + + def getRelativeUrlFromPerson(self,list): """get urls to person list""" ret=[] persons=list.split(";") for person in persons: - splitted=person.split(",") - if len(splitted)==1: - splitted=person.split(" ") - splittedNew=[re.sub(r'\s(.*)','$1',split) for split in splitted] - if splittedNew[0]=='': - del splittedNew[0] - search=string.join(splittedNew,' AND ') - if not search=='': - proj=self.MembersCatalog({'title':search}) - print search,"PER",person,splittedNew,proj + if len(person)>1: #nicht nur Trennzeichen + splitted=person.split(",") + if len(splitted)==1: + splitted=person.split(" ") + splittedNew=[re.sub(r'\s(.*)','$1',split) for split in splitted] + if splittedNew[0]=='': + del splittedNew[0] + search=string.join(splittedNew,' AND ') + + if not search=='': + + try: + proj=self.MembersCatalog({'title':search}) + except: + proj=None + + if proj: + #ret.append("%s"%(proj[0].absolute_url,person.encode('utf-8'))) + ret.append("%s"%('members/'+proj[0].id+'/index.html',person)) + else: + #ret.append("%s"%person.encode('utf-8')) + ret.append("%s"%person) + return string.join(ret,";") - if proj: - ret.append("%s"%(proj[0].absolute_url,person)) - else: - ret.append("%s"%person) + + def getUrlFromPerson(self,list): + """get urls to person list""" + ret=[] + persons=list.split(";") + for person in persons: + + if len(person)>1: #nicht nur Trennzeichen + splitted=person.split(",") + if len(splitted)==1: + splitted=person.lstrip().rstrip().split(" ") + splittedNew=[re.sub(r'\s(.*)','$1',split) for split in splitted] + if splittedNew[0]=='': + del splittedNew[0] + search=string.join(splittedNew,' AND ') + + if not search=='': + + try: + proj=self.MembersCatalog({'title':search}) + except: + 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: + #ret.append("%s"%person.encode('utf-8')) + ret.append("%s"%person) return string.join(ret,";") def getProjectsOfMembers(self): """give tuple member /projects""" ret=[] members=self.getAllMembers() + #return str(members) for x in members: - splitted=x.split(",") + ret+=self.getProjectsOfMember(name=x) + + return ret + + def getProjectsOfMember(self,name=None,email=None): + """get project of a member""" + def sortP(x,y): + """sort by sorting number""" + #print x.xdata_05,y.xdata_05 + return cmp(x.WEB_title,y.WEB_title) + + + ret=[] + splitNeu=[] + if 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(",") + #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=[] + for x in proj: + + if not getattr(x.getObject(),'invisible',None): + if not((splitted[1]==" Christoph") and (splitted[0]=="Hoffmann") and (str(x.WEB_title).find('Einstein')>0)): + proj2.append(x) + + else: + proj2=[] - proj=self.ProjectCatalog({'xdata_01':string.join(splitted,' AND')}) - if proj: - ret.append((x,proj)) + proj=self.ProjectCatalog({'xdata_08':search}) + if proj: + names=[x.WEB_title for x in proj] + for x in proj: + + if not x.WEB_title in names: + proj2.append(x) + + + proj2.sort(sortP) + + if len(proj2)>0: + ret.append((y,proj2)) + return ret + def givePersonList(self,name): """check if person is in personfolder and return list of person objects""" 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 ') @@ -167,7 +816,7 @@ class MPIWGRoot(Folder): def personCheck(self,names): """all persons for list""" - print "names",names + #print "names",names splitted=names.split(";") ret={} for name in splitted: @@ -177,7 +826,7 @@ class MPIWGRoot(Folder): ret[name]=self.givePersonList(name) except: """NOTHIHN""" - print "RET",ret + #print "RET",ret return ret def giveCheckList(self,person,fieldname): @@ -185,7 +834,7 @@ class MPIWGRoot(Folder): #print "GCL",fieldname if fieldname=='xdata_01': x=self.personCheck(person.getContent(fieldname)) - print "GCLBACKX",x + #print "GCLBACKX",x return x @@ -194,28 +843,86 @@ class MPIWGRoot(Folder): return (fieldname in checkFields) + def manage_addMPIWGRootForm(self): """form for adding the root""" - pt=PageTemplateFile('Products/MPIWGWeb/zpt/addMPIWGRootForm.zpt').__of__(self) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMPIWGRootForm.zpt')).__of__(self) return pt() -def manage_addMPIWGRoot(self,id,title,RESPONSE=None): +def manage_addMPIWGRoot(self,id,title,connection_id="",RESPONSE=None): """add a root folder""" newObj=MPIWGRoot(id,title) self._setObject(id,newObj) - + ob=getattr(self,id) + setattr(ob,'connection_id',connection_id) if RESPONSE is not None: RESPONSE.redirect('manage_main') -class MPIWGProject(Folder): +class MPIWGProject(CatalogAware,Folder): """Class for Projects""" meta_type='MPIWGProject' + default_catalog='ProjectCatalog' + + def PrincipiaSearchSource(self): + """Return cataloguable key for ourselves.""" + return str(self) + def versionHeader(self): + """version Header, gibt header text entsprechend der aktuellen version aus""" + + actualTime=time.localtime() + retTXT="""') and (field=='WEB_project_description'): + return "
"+text2+"
" + + + return text2.encode('utf-8') def show_html(self): """simple index""" #return "HI" - pt=PageTemplateFile('Products/MPIWGWeb/zpt/MPIWGProject_index.zpt').__of__(self) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGProject_index.zpt')).__of__(self) return pt() def editMPIWGProjectForm(self): """editform""" - pt=PageTemplateFile('Products/MPIWGWeb/zpt/edit_MPIWGProject.zpt').__of__(self) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGProject.zpt')).__of__(self) return pt() - def editMPIWGBasisForm(self): - """editform""" - pt=PageTemplateFile('Products/MPIWGWeb/zpt/edit_MPIWGBasis.zpt').__of__(self) - return pt() - def editMPIWGRelatedPublicationsForm(self): - """Edit related Publications""" - pt=PageTemplateFile('Products/MPIWGWeb/zpt/edit_MPIWGRelatedPublications.zpt').__of__(self) - return pt() - def editMPIWGProject(self,RESPONSE=None): - """edit the project""" + """edit the project and archive the old version""" - #return self.REQUEST + self.copyObjectToArchive() # archive the object + + for x in definedFields: if self.REQUEST.has_key(x): - setattr(self,x,[self.REQUEST[x]]) + setattr(self,x,[self.REQUEST[x].decode('utf-8')]) + + + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + + def editMPIWGDisciplinesThemesForm(self): + """edit the disciplines and themes Form""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGDisciplinesThemes.zpt')).__of__(self) + return pt() + + def editMPIWGDisciplinesThemes(self,disciplines=None,themes=None,RESPONSE=None): + """edit disciplin and form""" + if disciplines: + if type(disciplines) is StringType: + self.xdata_09=disciplines + else: + self.xdata_09=string.join(disciplines,";") + else: + self.xdata_09="" + if themes: + if type(themes) is StringType: + self.xdata_10=themes + else: + self.xdata_10=string.join(themes,";") + else: + self.xdata_10="" if RESPONSE is not None: RESPONSE.redirect('manage_main') + + def isChecked(self,wert,list): + """check if wert is in ; seperated list""" + + #felder sind manchmnal als liste mit einem element definiert + if type(list) is StringType or UnicodeType: + splitted=list.split(";") + else: + splitted=list[0].split(";") + + + for x in splitted: + if (not x==u'') and x in wert: + return 1 + return 0 + + def editMPIWGBasisForm(self): + """editform""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGBasis.zpt')).__of__(self) + return pt() + def editMPIWGRelatedPublicationsForm(self): + """Edit related Publications""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGRelatedPublications.zpt')).__of__(self) + return pt() + def loadNewFileForm(self): """Neues XML-File einlesen""" - pt=PageTemplateFile('Products/MPIWGWeb/zpt/MPIWGProject_newfile.zpt').__of__(self) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGProject_newfile.zpt')).__of__(self) return pt() def loadNewFile(self,RESPONSE=None): @@ -364,22 +1186,24 @@ class MPIWGProject(Folder): def manage_addMPIWGProjectForm(self): """form for adding the project""" - pt=PageTemplateFile('Products/MPIWGWeb/zpt/addMPIWGProjectForm.zpt').__of__(self) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMPIWGProjectForm.zpt')).__of__(self) return pt() def manage_addMPIWGProject(self,id,RESPONSE=None): """method to add a project""" #print argv - fileupload=self.REQUEST['fileupload'] + fileupload=self.REQUEST.get('fileupload',None) if fileupload: + file_name=fileupload.filename - filedata=fileupload.read() + filedata=fileupload.read() argv=xmlhelper.proj2hash(filedata) - + #print argv - - newObj=MPIWGProject(id,argv) + newObj=MPIWGProject(id,argv) + else: + newObj=MPIWGProject(id) self._setObject(id,newObj)