--- MPIWGWeb/MPIWGProjects.py 2004/10/21 14:28:09 1.39 +++ MPIWGWeb/MPIWGProjects.py 2005/06/14 12:35:55 1.47.2.13 @@ -1,11 +1,12 @@ """This contains the class MPIWG Projects -for organizing and maintaining the different projectspages +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 @@ -13,12 +14,14 @@ 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'] @@ -33,7 +36,7 @@ def sortF(x,y): try: return cmp(str(x[1]),str(y[1])) except: - print "error",x[1],y[1] + return 0 def sortI(x,y): @@ -63,6 +66,22 @@ class MPIWGTemplate(ZopePageTemplate): meta_type="MPIWGTemplate" + manage_options=ZopePageTemplate.manage_options+( + {'label':'Change Weight','action':'changeWeightForm'}, + ) + + def changeWeightForm(self): + """change weight form""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGTemplateChangeWeight.zpt')).__of__(self) + return pt() + + def changeWeight(self,weight,RESPONSE=None): + """change weight""" + self.weight=weight + if RESPONSE is not None: + RESPONSE.redirect('manage') + + def __init__(self, id, text=None, content_type=None,MPIWGType=None): self.id = str(id) @@ -78,7 +97,13 @@ class MPIWGTemplate(ZopePageTemplate): """change form""" - + def isActive(self): + """teste ob ausgewaehlt""" + if self.absolute_url()==self.REQUEST['URL']: + return "aktiv" + else: + return "" + def manage_addMPIWGTemplateForm(self): """Form for adding""" pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/AddMPIWGTemplate.zpt')).__of__(self) @@ -87,7 +112,7 @@ def manage_addMPIWGTemplateForm(self): from urllib import quote -def manage_addMPIWGTemplate(self, MPIWGType,id, title=None,REQUEST=None): +def manage_addMPIWGTemplate(self, MPIWGType,id, title=None,weight=0,REQUEST=None): "Add a Page Template with optional file content." if type(MPIWGType)==StringType: MPIWGTypes=[MPIWGType] @@ -122,7 +147,9 @@ def manage_addMPIWGTemplate(self, MPIWGT except AttributeError: u = REQUEST['URL1'] - + ob = getattr(self, id) + ob.weight=weight + REQUEST.RESPONSE.redirect(u+'/manage_main') return '' @@ -141,13 +168,65 @@ class MPIWGRoot(ZSQLExtendFolder): folders=['MPIWGProject','Folder','ECHO_Navigation'] meta_type='MPIWGRoot' + def getKategory(self,url): + """kategorie""" + splitted=url.split("/") + return splitted[4] + + def generateUrlProject(self,url,project=None): + """erzeuge aus absoluter url, relative des Projektes""" + + splitted=url.split("/") + length=len(splitted) + short=splitted[length-2:length] + if project: + base=self.REQUEST['URL3']+"/"+"/".join(short) + else: + base=self.REQUEST['URL1']+"/"+"/".join(short) + return base + + def isNewCapital(self,text=None,reset=None): + if reset: + self.REQUEST['capital']="A" + return True + else: + if len(text)>0 and not (text[0]==self.REQUEST['capital']): + self.REQUEST['capital']=text[0] + return True + else: + return False + + def subNav(self,id): + """return subnav elemente""" + def sortWeight(x,y): + x1=int(getattr(x[1],'weight','0')) + y1=int(getattr(y[1],'weight','0')) + return cmp(x1,y1) + if hasattr(self,id): + subs=self.ZopeFind(getattr(self,id),obj_metatypes=['MPIWGTemplate']) + subret=[] + for x in subs: + if not(x[1].title==""): + subret.append(x) + subret.sort(sortWeight) + return subret + else: + return None + def isActive(self,name): + """teste ob subnavigation aktiv""" + for part in self.REQUEST['URL'].split("/"): + if part==name: + return True + return False + + 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() - + 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): @@ -160,12 +239,22 @@ class MPIWGRoot(ZSQLExtendFolder): def replaceNotEmpty(self,format,field): """replace not empty""" - if field and (not field==''): + 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' @@ -286,7 +375,8 @@ class MPIWGRoot(ZSQLExtendFolder): list[urllib.quote(personNormal)]=(personNormal,[project[1]]) except: - print "ERROR",project + zLOG.LOG("MPIWG Web (harvestHistoricalPerson)",zLOG.ERROR,"cannot annalyize: %s"%repr(project)) + return list @@ -317,34 +407,43 @@ class MPIWGRoot(ZSQLExtendFolder): def showHistoricalPersons(self): """show persons""" - pt=PageTemplateFile('Products/MPIWGWeb/zpt/showHistoricalPersons').__of__(self) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','showHistoricalPersons')).__of__(self) return pt() def editHistoricalPersonsForm(self): """edit historical persons for consistency""" - pt=PageTemplateFile('Products/MPIWGWeb/zpt/editHistoricalPersonsForm').__of__(self) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editHistoricalPersonsForm')).__of__(self) return pt() def getProjectsByFieldContent(self,fieldName,fieldContentsEntry): """gib alle Projekte aus mit Value von field mit fieldName enthält ein Element der Liste fieldContents""" - if type(fieldContentsEntry) is StringType: - fieldContents=[fieldContentsEntry] + def sort(x,y): + return cmp(x.WEB_title[0],y.WEB_title[0]) + + if type(fieldContentsEntry) is StringType: + fieldContentsTmp=[fieldContentsEntry] else: - fieldContents=fieldContentsEntry - - projects=self.ProjectCatalog({fieldName:string.join(fieldContents,' OR')}) + fieldContentsTmp=fieldContentsEntry + + fieldContents=[] + for x in fieldContentsTmp: + fieldContents.append(" AND ".join(x.split())) + projects=self.ProjectCatalog({fieldName:string.join(fieldContents,' AND')}) #print projects - return projects + ret=[x for x in projects] + ret.sort(sort) + return ret def changeMPIWGRootForm(self): """edit""" - pt=PageTemplateFile('Products/MPIWGWeb/zpt/changeMPIWGRootForm').__of__(self) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeMPIWGRootForm')).__of__(self) return pt() - def changeMPIWGRoot(self,title,disciplineList,themesList,RESPONSE=None): + def changeMPIWGRoot(self,title,disciplineList,themesList,connection_id,RESPONSE=None): """change""" self.title=title + self.connection_id=connection_id self.disciplineList=disciplineList self.themesList=themesList @@ -353,11 +452,13 @@ class MPIWGRoot(ZSQLExtendFolder): def getDisciplineList(self): """get disciplines as list""" - return self.disciplineList.split("\n") + list= self.disciplineList.split("\n") + return [x.rstrip().lstrip() for x in list] def getThemeList(self): """get themes as list""" - return self.themesList.split("\n") + list= self.themesList.split("\n") + return [x.rstrip().lstrip() for x in list] def test(self): """test""" @@ -388,25 +489,27 @@ class MPIWGRoot(ZSQLExtendFolder): ret.append(project) return ret - def getProjectFields(self,fieldName,folder=None,sort=None): + def getProjectFields(self,fieldName,actual="yes",folder=None,sort=None): """getListofFieldNames""" ret=[] - objects=self.ZopeFind(self,obj_metatypes=['MPIWGProject'],search_sub=1) + objects=self.ZopeFind(self.projects,obj_metatypes=['MPIWGProject'],search_sub=0) 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" + + if (not getattr(obj,'invisible',None)) and (obj.isActual()): + 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="xdata_07" - else: - fieldNameTmp=fieldName - - ret.append((obj,obj.getContent(fieldNameTmp))) + fieldNameTmp=fieldName + + ret.append((obj,obj.getContent(fieldNameTmp))) if sort=="int": @@ -435,7 +538,7 @@ class MPIWGRoot(ZSQLExtendFolder): def importNamesForm(self): """Form""" - pt=PageTemplateFile('Products/MPIWGWeb/zpt/MPIWGNamesForm.zpt').__of__(self) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGNamesForm.zpt')).__of__(self) return pt() def importNames(self,fileupload,folderName,RESPONSE=None): @@ -456,7 +559,8 @@ class MPIWGRoot(ZSQLExtendFolder): project._setObject(splitted[0],newObj) #print "done:",splitted[0] except: - print "not done:",splitted[0] + zLOG.LOG("MPIWG Web (importNames)",zLOG.INFO,"cannot import: %s"%splitted[0]) + if RESPONSE is not None: RESPONSE.redirect('manage_main') @@ -488,9 +592,11 @@ class MPIWGRoot(ZSQLExtendFolder): 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']) - + 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: @@ -534,6 +640,7 @@ class MPIWGRoot(ZSQLExtendFolder): """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(".") @@ -542,11 +649,62 @@ class MPIWGRoot(ZSQLExtendFolder): #title=project[0].WEB_title title=[project[0].getContent('WEB_title')] #print title - returnList.append((depth,nr,title,project[0])) + if idNr[0]!="x": + returnList.append((depth,nr,title,project[0])) return returnList + def formatElementsAsList(self,elements): + """formatiere tree als liste""" + + actualDepth=0 + ret="" + for element in elements: + if (element[0]>actualDepth): + #fuege soviele ul ein wie unterschied in tiefe + if element[0]==1: + ret+="""
\n
\n""" + if department==4: #hack + department=3 + + ret+="""
+
\n