--- MPIWGWeb/MPIWGProjects.py 2005/10/10 08:42:49 1.47.2.25 +++ MPIWGWeb/MPIWGProjects.py 2008/06/24 11:16:26 1.47.2.84 @@ -15,7 +15,7 @@ import string import re import os from types import * -import zLOG +import logging import xmlhelper # Methoden zur Verwaltung der projekt xml from OFS.SimpleItem import SimpleItem from OFS.Folder import Folder @@ -23,1121 +23,31 @@ from Products.ZSQLMethods.SQL import SQL from AccessControl import ClassSecurityInfo from bibliography import * import time +import xml.dom.minidom +import sys +from Ft.Xml.XPath import Evaluate +from Ft.Xml.XPath.Context import Context +from Ft.Xml.Domlette import NonvalidatingReader,PrettyPrint, Print +from Ft.Xml import EMPTY_NAMESPACE +import copy +import updatePersonalWWW +import MPIWGStaff + +from MPIWGHelper import * + +import MPIWGRoot +import MPIWGLink +import MPIWGTemplate -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 +class MPIWGRoot(MPIWGRoot.MPIWGRoot): + """depricated""" -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 - - 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 MPIWGLink(SimpleItem): - """create a symbolic link to another page""" - - meta_type="MPIWGLink" +class MPIWGLink(MPIWGLink.MPIWGLink): + """depricated""" - def isActiveItem(self): - """teste ob ausgewaehlt""" - #url1 beim link anstelle von url1, da link jeweils index_html als url hat. - if self.absolute_url()==self.REQUEST['URL1']: - return "aktiv" - else: - return "" - - def __init__(self,id,link,title='',weight=''): - """init mpiwglink""" - self.id=id - self.link=link - self.title=title - self.weight=weight - - def getObj(self): - """bekomme original""" - ## objpath=self.link.replace("/",".") -## if objpath[0]!=".": -## objpath="."+objpath - -## print objpath -## return eval("self"+objpath) - - - splitted=self.link.lstrip().split("/") - obj=self - for x in splitted: - if not x=="": - obj=getattr(obj,x) - - return obj - - def getWeight(self): - if self.linkWeight and linkWeight!="": - return self.linkWeight - else: - return self.getObj().weight - - manage_options=SimpleItem.manage_options+( - {'label':'main config','action':'changeLinkForm'}, - ) - - - def changeLinkForm(self): - """change MPIWG link""" - pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGLinkChange.zpt')).__of__(self) - return pt() - - def changeLink(self,link,title,weight,RESPONSE=None): - """change links""" - self.link=link - self.title=title - self.weight=weight - - if RESPONSE is not None: - RESPONSE.redirect('manage') - - def index_html(self): - """index""" - - return self.getObj().pt_render(extra_context={'here':self}) - - -def manage_addMPIWGLinkForm(self): - """Form for adding link""" - pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/AddMPIWGLink.zpt')).__of__(self) - return pt() - -def manage_addMPIWGLink(self,id,link,title,weight,RESPONSE=None): - """add link""" - newObj=MPIWGLink(id,link,title,weight) - - self._setObject(id,newObj) - - if RESPONSE is not None: - RESPONSE.redirect('manage_main') - - -class MPIWGTemplate(ZopePageTemplate): - """Create a layout Template for different purposes""" - - 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) - - - - 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) - +class MPIWGTemplate(MPIWGTemplate.MPIWGTemplate): + """depricated""" - """change form""" - - def isActiveItem(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) - return pt() - -from urllib import quote - - -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] - 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'] - - ob = getattr(self, id) - ob.weight=weight - - REQUEST.RESPONSE.redirect(u+'/manage_main') - return '' - - -class MPIWGRoot(ZSQLExtendFolder): - """Stammordner für den Web-Server""" - - 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':'Disciplines','xdata_10':'Themes', - '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 versionHeaderEN(self): - """version header text""" - - date= self.REQUEST.get('date',None) - if date: - txt="""
%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: - 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.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 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,date=None): - """generate Tree from project list""" - - returnList=[] - for project in self.getProjectFields('xdata_05',sort="int",date=date): # 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 - 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+=""""""%(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(): - if not (fields[int(idNr)][3].xdata_05==form[idNr]): - fields[int(idNr)][3].xdata_05=form[idNr] - fields[int(idNr)][3].copyObjectToArchive() - - - 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: - - 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,";") - - - 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,date=None): - """give tuple member /projects""" - ret=[] - members=self.getAllMembers() - #return str(members) - for x in members: - ret+=self.getProjectsOfMember(name=x,date=date) - - return ret - - def getProjectsOfMember(self,name=None,email=None,date=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: - - members=self.ZopeFind(self.members,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)) and (getattr(x.getObject(),'archiveTime','')==''): - 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_08':search}) - if proj: - names=[x.WEB_title for x in proj] - for x in proj: - - if (not x.WEB_title in names) and (getattr(x.getObject(),'archiveTime','')==''): - 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.lstrip().rstrip().split(" ") - splittedNew=[split.lstrip() for split in splitted] - - if splittedNew[0]=='': - del splittedNew[0] - search=string.join(splittedNew,' AND ') - if not search=='': - proj=self.MembersCatalog({'title':search}) - - if proj: - return [[x.lastName,x.firstName] for x in proj] - else: - return [] - -## splitted=name.split(",") # version nachname, vorname... -## if len(splitted)>1: -## lastName=splitted[0] -## firstName=splitted[1] -## else: -## splitted=name.split(" ") #version vorname irgenwas nachnamae - -## lastName=splitted[len(splitted)-1] -## firstName=string.join(splitted[0:len(splitted)-1]) - -## objs=[] - - #print self.members - ## for x in self.members.__dict__: -## obj=getattr(self.members,x) -## if hasattr(obj,'lastName') and hasattr(obj,'firstName'): - -## if (re.match(".*"+obj.lastName+".*",lastName) or re.match(".*"+lastName+".*",obj.lastName)) and (re.match(".*"+obj.firstName+".*",firstName) or re.match(".*"+firstName+".*",obj.firstName)): - -## objs.append((obj,lastName+", "+firstName)) - - - return objs - - - def personCheck(self,names): - """all persons for list""" - #print "names",names - splitted=names.split(";") - ret={} - for name in splitted: - - if not (name==""): - try: - ret[name]=self.givePersonList(name) - except: - """NOTHIHN""" - #print "RET",ret - return ret - - def giveCheckList(self,person,fieldname): - """return checklist""" - #print "GCL",fieldname - if fieldname=='xdata_01': - x=self.personCheck(person.getContent(fieldname)) - #print "GCLBACKX",x - return x - - - def isCheckField(self,fieldname): - """return chechfield""" - - return (fieldname in checkFields) - - - - - -def manage_addMPIWGRootForm(self): - """form for adding the root""" - pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMPIWGRootForm.zpt')).__of__(self) - return pt() - -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_publication(SimpleItem): """publications object fuer project""" @@ -1190,6 +100,10 @@ class MPIWGProject(CatalogAware,Folder): meta_type='MPIWGProject' default_catalog='ProjectCatalog' + def decode(self,str): + """return unicode object""" + return unicodify(str) + def sortedByPlace(self,metatype): """find metatype and sort by place""" def sort(x,y): @@ -1217,23 +131,70 @@ class MPIWGProject(CatalogAware,Folder): RESPONSE.redirect('managePublications') - def copyImageToMargin(self,RESPONSE=None): + def copyImageToMargin(self,RESPONSE=None): """copy inline images to marginal images""" - self.getContent('WEB_project_description',filter='yes') + + + #getImages from WEB_project_description + description=self.getContent('WEB_project_description') + + text2=description + splitted=text2.split("""""") + + imageURLs=[] + imageCaptions=[] + for split in splitted[1:]: + tmp=split.split("
") + #return repr(splitted[1]) + + try: + imageURLs.append(tmp[0].split("\"")[1].encode('utf-8')) + except: + + try: + imageURLs.append(tmp[0].split("src=")[1].split(" ")[0].encode('utf-8')) + except: + imageURLs.append("") + + split2="".join(tmp[1:]) - filename=self.imageURL.split("/")[-1] - #lege neues images object an, mit leerem bild - if self.ZopeFind(self,obj_ids=[filename]): - #existiert das bild schon, dann neueun filenamen - filename="project_image_"+filename - - self.addImage(None,self.imagecap,filename=filename) - #hole die bilddaten aus der url - data=urllib.urlopen(self.absolute_url()+"/"+self.imageURL).read() + splitted=split2.split("""""") + if len(splitted)>1: + tmp=splitted[1].split("
") + imageCaptions.append(tmp[0].encode('utf-8')) - obj=getattr(self,filename) - obj.update_data(data) + + else: + #keine caption + + imageCaptions.append("") + + + #eintragen: + for imageURL in imageURLs: + filename=imageURL.split("/")[-1] + #lege neues images object an, mit leerem bild + + if self.ZopeFind(self,obj_ids=[filename]): + #existiert das bild schon, dann neuen filenamen + filename="project_image_"+filename + + self.addImage(None,imageCaptions[imageURLs.index(imageURL)],filename=filename) + #hole die bilddaten aus der url + url=self.absolute_url()+"/"+imageURL + #url=self.absolute_url()+"/"+filename + + try:#relative url + data=urllib.urlopen(url).read() + except: + try:#absolute + data=urllib.urlopen(self.imageURL).read() + except: + logger("MPIWG Project",logging.ERROR,"can't open: %s"%url) + + obj=getattr(self,filename) + obj.update_data(data) if RESPONSE: RESPONSE.redirect('manageImages') @@ -1331,16 +292,26 @@ class MPIWGProject(CatalogAware,Folder): return getattr(publications[-1][1],'place',0) def deletePublication(self,id,RESPONSE=None): - """delete Publication id""" - self.manage_delObjects([id]) - if RESPONSE: - RESPONSE.redirect('managePublications') - + """delete Publication id""" + self.manage_delObjects([id]) + if RESPONSE: + RESPONSE.redirect('managePublications') + def getImages(self): """get all Images""" + def sort_images(x,y): return cmp(getattr(x[1],'place',0),getattr(y[1],'place',0)) + + if (getattr(self,'imageURL','')!='') or (getattr(self,'imagecap','')!='') : + try: + self.addImage(None,getattr(self,'imagecap',''),RESPONSE=None,filename=getattr(self,'imageURL','')) + except: + pass + self.imageURL='' + self.imagecap='' + images=self.ZopeFind(self,obj_metatypes=['MPIWGProject_image']) images.sort(sort_images) @@ -1360,6 +331,18 @@ class MPIWGProject(CatalogAware,Folder): if RESPONSE: RESPONSE.redirect('manageImages') + + def hasChildren(self,date=None,onlyActive=1,onlyArchived=1): + """check if project has children""" + ct=self.getContexts(childs=self.getContent('xdata_05'), + depth=1,date=date,onlyActive=onlyActive) + + if ct and len(ct)>0: + return True + else: + return False + + def addImage(self,fileHd,caption,RESPONSE=None,filename=None): """add an MPIWG_Project_image""" @@ -1376,7 +359,8 @@ class MPIWGProject(CatalogAware,Folder): obj.caption=caption[0:] obj.enabled=True; obj.place=self.getLastImageNumber()+1 - + obj.id=filename + if RESPONSE is not None: RESPONSE.redirect('manageImages') @@ -1497,7 +481,7 @@ class MPIWGProject(CatalogAware,Folder): def generateTemplate(self,RESPONSE=None): - """Erzeuge Template für defined fields not_used""" + """Erzeuge Template fuer defined fields not_used""" id="index_html" title=id @@ -1517,6 +501,9 @@ class MPIWGProject(CatalogAware,Folder): self.creationTime=time.strftime("%Y%m%d%H%M%S",time.localtime())[0:] self.id=id self.title=id + self.isActiveFlag=True #Flag is true is the project is still active, False if accomplished + self.responsibleScientistsList=[] # enthaelt die Lister der verantwortlichen Wissenschaftler in der Form (NAME, KEY), key ist "" flass Wissenschaftler nicht an unserem Haus + if argv: for arg in definedFields: try: @@ -1537,6 +524,97 @@ class MPIWGProject(CatalogAware,Folder): ) + def isActiveProject(self): + """check if the project is still active, default is true, set to false is the project is accomplished""" + return getattr(self,'isActiveFlag',True) + + def isArchivedProject(self): + """check if the project is archived""" + + completed=getattr(self,'completedAt',0) + + #completed leer + if completed=="" : + return False; + if completed == 0: + return False; + + + return True + + + def setActiveFlag(self,status=True): + """set the active flag""" + self.isActiveFlag=status + + def setCompletedAt(self,date): + """set the date of completion, date should be in the form DD.MM.YYYY or MM.YYYY or YYYY""" + logging.info("DATE:"+repr(date)) + transformedDate=self.transformDate(date); + logging.info("transformed"+repr(transformedDate)) + if transformedDate is not None: + setattr(self,"completedAt",transformedDate) + return True; + else: + return False; + + def getCompletedAt(self): + """gibt das transformierte Datum zurŸck""" + date=getattr(self,'completedAt','') + if date: + return self.reTransformDate(date); + else: + return ''; + + def reTransformDate(self,date): + """transformiert , transformdate zurueck""" + year=int(date/10000) + month=int((date-year*10000)/100) + day=int((date-year*10000-month*100)) + return """%s.%s.%s"""%(day,month,year); + + + def transformDate(self,date): + """transformiert ein Datum von DD.MM.YYYY, MM.YYYY,YYYY nach YYYYMMDD, alle nicht angebebenn Werte + werden auf 0 gesetzt, es wird null zurŸckgegeben falls das Datum ungueltig ist""" + + if (date=="" ) : + return ""; + + if (date==None): + return None; + + splitted=date.split(".") + length=len(splitted) + year=0 + month=0 + day=0 + if length > 3: + return ""; + if length==3: + day = int(splitted[0]) + if length>1: + month=int(splitted[length-2]) + + if length > 0: + try: + year = int(splitted[length-1]) + except: + pass + + ## logging.info("month:"+(month)) + if not (0<=month<13): + return None; + + if not(0<=day<32): + return None; + + if (year>0) and (year<1900): #jahr nicht vierstellig eingegeben + year=2000+year; + return year*10000+month*100+day + + + def checkDate(self,date): """teste ob zum Zeitpunkt date eine andere version existierte""" @@ -1577,7 +655,109 @@ class MPIWGProject(CatalogAware,Folder): """warnung: project noch nicht existent""" pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','no_project')).__of__(self) return pt() - + + def getGetNeighbourhood(self,wordStr, length=100,tagging=True): + """finde umgebung um die worte in wordStr, zurueckgegeben wird eine Array mit den Umgebungen von Fundstellen der Worte + alle Tags werden entfernt, die Fundstellen werden mit XX getaggt, die Umgebungen werden + case insensitive gesucht + @param wordStr: string mit Worten getrennt durch Leerzeichen, Phrasen sind mit " gekennzeichnet + "eine phrase", "*" bezeichnet wildcards und wird ignoriert" + @param length: optional, default wert 100, 2*length ist die groesse der Umgebung + @param tagging: optional default wert true, kein span tag wird erzweugt falls tag=false + """ + + ret=[] # nimmt das Array auf, dass spaeter zurueckgegeben wird + ranges=[] #Array mit tupeln x,y wobei x die Position des Anfang und y des Endes der i-ten Umgebung angiebt + + def isInRanges(nr,length): + """test ob eine gegeben Position nr schon irgendwo in einer Umgebung ist, gibt den Index des ersten Wertes aus ranges zurueck, + -1, wenn kein Treffer + + @param nr: Position die geprueft werden soll + @param length: Laenge des Wortes das geprueft werden soll + """ + for x in ranges: + if (x[0]<=nr) and (nr < (x[1]-length)): + return ranges.index(x) + return -1 + + # deal with phrases, in Phrasen werden die Leerzeichen durch "_" ersetzt. + def rep_empty(str): + x= re.sub(" ","_",str.group(0)) + return re.sub("\"","",x) + + wordStr=re.sub("\".*?\"", rep_empty,wordStr)#ersetze leerzeichen in " " durch "_" und loesche " + + #deal with wildcards, for our purposes it is enough to delete the wildcard + wordStr=wordStr.replace("*","") + + words=wordStr.split(" ") + #if not words is ListType: + # words=[words] + + txt=self.harvest_page() + if not txt: + return ret + txt=re.sub("<.*?>", "", txt) # loesche alle Tags + for word in words: + word=re.sub("_"," ",word) # ersetze zurueck "_" durch " " + pos=0 + + n=txt.lower().count(word.lower()) # wie oft tritt das Wort auf + + for i in range(n): + pos=txt.lower().find(word.lower(),pos) + + if pos > 0: + x=max(0,pos-length) + y=min(len(txt),pos+length) + + + #is word already in one of the results + nr=isInRanges(pos,len(word)) + if nr >=0:# word ist in einer schon gefunden Umgebung, dann vergroessere diese + x=min(ranges[nr][0],x) + y=max(ranges[nr][1],y) + + str=txt[x:y] + + if nr >=0: # word ist in einer schon gefunden Umgebung + ranges[nr]=(x,y) # neue Position der Umgebung + + ret[nr]=str # neue Umgebung + else: # andernfalls neue Umgebung hinzufuegen + ranges.append((x,y)) + + ret.append(str) + + pos=pos+len(word) + else: + break; + + # now highlight everything + if tagging: + for x in range(len(ret)): + for word in words: + repl=re.compile(word,re.IGNORECASE) + ret[x]=repl.sub(""" %s"""%word.upper(),ret[x]) + + return ret + + def harvest_page(self,context=None): + """seite fuer harvesting fuer die Projektsuche""" + if not context: + context=self + + if self.isActiveProject() and self.isActual(): + ext=getattr(self,"harvest_main",None) + if ext: + return getattr(self,ext.getId())() + + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','harvest_main')).__of__(context) + + + return pt() + def index_html(self,request=True,context=None): """show homepage""" if not context: @@ -1656,8 +836,11 @@ class MPIWGProject(CatalogAware,Folder): try: self.imageURL=tmp[0].split("\"")[1].encode('utf-8') except: + try: self.imageURL=tmp[0].split("src=")[1].split(" ")[0].encode('utf-8') - + except: + self.imageURL="" + split2="".join(tmp[1:]) text3=splitted[0]+split2 @@ -1679,15 +862,21 @@ class MPIWGProject(CatalogAware,Folder): else: text5=text2 - #teste ob WEB_project_description und keine führenden p tags + #teste ob WEB_project_description und keine fuehrenden p tags if (len(text5)>4) and (not text5[0:3]=='') and (field=='WEB_project_description'): text5= "
"+text5+"
" #filter image + text5=text5.lstrip().rstrip() #loescher leerzeichen und einzelndes br + if (text5=="