"""This contains the class MPIWG Projects
for organizing and maintaining the different project pages
"""
#TODO: mechanismus fur links to personen ueberarbeiten, da jetzt alle e_mails als members auftauchen unabhaenig vom status publish_the_data
#TODO: was passiert wenn aenderungen von jochen im filemaker nicht mit den aenderungen im sql uebereinstimmen
#TODO: in einzelnen projecte steht als pfad auf die bilder noch wwwneu statt www
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 OFS.Image import Image
from Globals import package_home
import urllib
import MPIWGStaff
import string
import re
import os
from types import *
import logging
import xmlhelper # Methoden zur Verwaltung der projekt xml
from OFS.SimpleItem import SimpleItem
from OFS.Folder import Folder
from Products.ZSQLMethods.SQL import SQLConnectionIDs
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
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']
#ersetzt logging
def logger(txt,method,txt2):
"""logging"""
logging.info(txt+ txt2)
def getTextFromNode(nodename):
nodelist=nodename.childNodes
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
def sortStopWordsF(self,xo,yo):
if not hasattr(self,'_v_stopWords'):
self._v_stopWords=self.stopwords_en.data.split("\n")
x=str(xo[1])
y=str(yo[1])
strx=x.split(" ")
stry=y.split(" ")
for tmp in strx:
if tmp.lower() in self._v_stopWords:
del strx[strx.index(tmp)]
for tmp in stry:
if tmp.lower() in self._v_stopWords:
del stry[stry.index(tmp)]
return cmp(" ".join(strx)," ".join(stry))
def sortStopWords(self):
return lambda x,y : sortStopWordsF(self,x,y)
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
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])
def unicodify(str):
"""decode str (utf-8 or latin-1 representation) into unicode object"""
if not str:
return ""
if type(str) is StringType:
try:
return str.decode('utf-8')
except:
return str.decode('latin-1')
else:
return str
def utf8ify(str):
"""encode unicode object or string into byte string in utf-8 representation"""
if not str:
return ""
if type(str) is StringType:
return str
else:
return str.encode('utf-8')
class MPIWGLink(SimpleItem):
"""create a symbolic link to another page"""
meta_type="MPIWGLink"
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 self.linkWeight!="":
return self.linkWeight
else:
return self.getObj().weight
manage_options=(
{'label':'main config','action':'changeLinkForm'},
)+SimpleItem.manage_options
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,**argv):
"""index"""
try:
return self.getObj().pt_render(extra_context={'here':self})
except:
self.REQUEST.RESPONSE.redirect(self.getObj().absolute_url())
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)
"""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, text="",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 fuer 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 harvestProjects(self):
"""harvest"""
folder="/tmp"
try:
os.mkdir("/tmp/harvest_MPIWG")
except:
pass
founds=self.ZopeFind(self.aq_parent.projects,obj_metatypes=['MPIWGProject'],search_sub=1)
for found in founds:
txt=found[1].harvest_page()
if txt and (txt != ""):
name=found[0].replace("/","_")
fh=file("/tmp/harvest_MPIWG/"+name,"w")
fh.write(txt)
fh.close()
def decode(self,str):
"""decoder"""
if not str:
return ""
if type(str) is StringType:
try:
return str.decode('utf-8')
except:
return str.decode('latin-1')
else:
return str
def getat(self,array,idx=0,default=None):
"""return array element idx or default (but no exception)"""
if len(array) <= idx:
return default
else:
return array[idx]
def browserCheck(self):
"""check the browsers request to find out the browser type"""
bt = {}
ua = self.REQUEST.get_header("HTTP_USER_AGENT")
bt['ua'] = ua
bt['isIE'] = False
bt['isN4'] = False
if string.find(ua, 'MSIE') > -1:
bt['isIE'] = True
else:
bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1)
try:
nav = ua[string.find(ua, '('):]
ie = string.split(nav, "; ")[1]
if string.find(ie, "MSIE") > -1:
bt['versIE'] = string.split(ie, " ")[1]
except: pass
bt['isMac'] = string.find(ua, 'Macintosh') > -1
bt['isWin'] = string.find(ua, 'Windows') > -1
bt['isIEWin'] = bt['isIE'] and bt['isWin']
bt['isIEMac'] = bt['isIE'] and bt['isMac']
bt['staticHTML'] = False
return bt
def versionHeaderEN(self):
"""version header text"""
date= self.REQUEST.get('date',None)
if date:
txt="""<h2>This pages shows the project which existed at %s</h2>"""%str(date)
return txt
return ""
def versionHeaderDE(self):
"""version header text"""
date= self.REQUEST.get('date',None)
if date:
txt="""<h2>Auf dieser Seite finden Sie die Projekte mit Stand vom %s</h2>"""%str(date)
return ""
def createOrUpdateId_raw(self):
"""create sequence to create ids for bibliography"""
debug=None
#suche groesste existierende id
founds=self.ZSQLQuery("select id from bibliography")
if founds:
ids=[int(x.id[1:]) for x in founds]
maximum=max(ids)
id_raw=self.ZSQLQuery("select nextval('id_raw')",debug=debug)
if id_raw:
self.ZSQLQuery("drop sequence id_raw",debug=debug)
self.ZSQLQuery("create sequence id_raw start %i"%(maximum+1),debug=debug)
def queryLink(self,link):
"""append querystring to the link"""
return "%s?%s"%(link,self.REQUEST.get('QUERY_STRING',''))
def getKategory(self,url):
"""kategorie"""
splitted=url.split("/")
return splitted[4]
def generateUrlProject(self,url,project=None):
"""erzeuge aus absoluter url, relative des Projektes"""
if project:
splitted=url.split("/")
length=len(splitted)
short=splitted[length-2:length]
base=self.REQUEST['URL3']+"/"+"/".join(short)
else:
findPart=url.find("/projects/")
base=self.REQUEST['URL1']+"/"+url[findPart:]
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 subNavStatic(self,obj):
"""subnav" von self"""
def sortWeight(x,y):
x1=int(getattr(x[1],'weight','0'))
y1=int(getattr(y[1],'weight','0'))
return cmp(x1,y1)
subs=self.ZopeFind(obj,obj_metatypes=['MPIWGTemplate','MPIWGLink'])
subret=[]
for x in subs:
if not(x[1].title==""):
subret.append(x)
subret.sort(sortWeight)
return subret
def subNav(self,obj):
"""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 obj.meta_type in ['MPIWGTemplate','MPIWGLink']:
# id=obj.aq_parent.getId()
#else:
#id=obj.getId()
#suche die zweite ebene
if not obj.aq_parent.getId() in ['de','en']:
obj=obj.aq_parent
while not self.ZopeFind(self,obj_ids=[obj.getId()]):
obj=obj.aq_parent
if hasattr(self,obj.getId()):
subs=self.ZopeFind(getattr(self,obj.getId()),obj_metatypes=['MPIWGTemplate','MPIWGLink'])
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 getSection(self):
"""returns the current section name"""
root = self.absolute_url()
url = self.REQUEST['URL']
path = string.replace(url, root, '')
paths = path.split('/')
if len(paths) > 0:
sec = paths[1]
if sec.find('.') < 0:
return sec
else:
return None
return None
def getSectionStyle(self, name, style=""):
"""returns a string with the given style + '-sel' if the current section == name"""
if self.getSection() == name:
return style + '-sel'
else:
return style
def MPIWGrootURL(self):
"""returns the URL to the root"""
return self.absolute_url()
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)
logger("MPIWG Web",logging.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()
logger("MPIWG Web",logging.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("<p>%s</p>\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_x<last_y:
return 1
elif last_x>last_y:
return -1
else:
return 0
list.sort(sortLastName)
list.reverse()
return list
def __init__(self, id, title):
"""init"""
self.id=id
self.title=title
def removeStopWords(self,xo):
"""remove stop words from xo"""
if not hasattr(self,'_v_stopWords'):
self._v_stopWords=self.stopwords_en.data.split("\n")
x=str(xo)
strx=x.split(" ")
for tmp in strx:
if tmp.lower() in self._v_stopWords:
del strx[strx.index(tmp)]
return " ".join(strx)
def urlQuote(self,str):
"""quote"""
return urllib.quote(str)
def urlUnQuote(self,str):
"""quote"""
return urllib.unquote(str)
def getProjectsByFieldContent(self,fieldName,fieldContentsEntry, date=None):
"""gib alle Projekte aus mit Value von field mit fieldName enthaelt ein Element der Liste fieldContents"""
def sort(x,y):
return cmp(x.WEB_title[0],y.WEB_title[0])
if type(fieldContentsEntry) is StringType:
fieldContentsTmp=[fieldContentsEntry]
else:
fieldContentsTmp=fieldContentsEntry
fieldContents=[]
for x in fieldContentsTmp:
fieldContents.append(" AND ".join(x.split()))
projects=self.ProjectCatalog({fieldName:string.join(fieldContents,' AND')})
#print projects
#ret=[x for x in projects]
ret=[]
for x in projects:
obj=x.getObject()
obj=obj.getActualVersion(date)
if obj and (not getattr(obj,'invisible',None)):
#if not (x in ret):
ret.append(x)
ret.sort(sort)
return ret
def changeMPIWGRootForm(self):
"""edit"""
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeMPIWGRootForm')).__of__(self)
return pt()
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
if RESPONSE is not None:
RESPONSE.redirect('manage_main')
def getContexts(self,childs=None,parents=None,depth=None,date=None,onlyActive=True):
"""childs alle childs, alle parents"""
ret=[]
if parents:
splitted=parents.split(".")
parentId=string.join(splitted[0:len(splitted)-1],".")
for project in self.getProjectFields('xdata_05',sort='int',date=date):
if project[1]==parentId:
ret.append(project)
if childs:
for project in self.getProjectFields('xdata_05',sort='int',date=date):
searchStr=childs+"(\..*)"
if (onlyActive and project[0].isActiveProject()) or (not onlyActive):
if re.match(searchStr,project[1]):
if depth:
if int(depth)>=len(project[1].split("."))-len(childs.split(".")):
ret.append(project)
else:
ret.append(project)
return ret
def getProjectFields(self,fieldName,date=None,folder=None,sort=None):
"""getListofFieldNames"""
ret=[]
objects=self.ZopeFind(self.projects,obj_metatypes=['MPIWGProject'],search_sub=0)
for object in objects:
obj=object[1]
obj=obj.getActualVersion(date)
if obj and (not getattr(obj,'invisible',None)):
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.append((obj,obj.getContent(fieldNameTmp)))
if sort=="int":
ret.sort(sortI)
elif sort=="stopWords":
ret.sort(sortStopWords(self))
else:
ret.sort(sortF)
return ret
def showNewProjects(self):
projects=[]
for objs in self.getProjectFields('WEB_title_or_short'): # Get all Projets
if objs[0].xdata_05 and (objs[0].xdata_05[0] == ""):
projects.append(objs)
return projects
manage_options = Folder.manage_options+(
{'label':'Update personal homepages','action':'updatePersonalwww_html'},
{'label':'Reindex catalogs','action':'reindexCatalogs'},
{'label':'Main config','action':'changeMPIWGRootForm'},
{'label':'add e-mails','action':'showNewDBEntries'},
{'label':'update the institutsbibliography','action':'updateInstitutsbiliography'},
#{'label':'Edit Historical Persons','action':'editHistoricalPersonsForm'},
#{'label':'Store Historical Persons','action':'storeHistoricalPersons'},
)
def updatePublicationDB(self,personId=None):
"""updates the publication db, i.e. copy year and type into the main table"""
if personId:
founds = self.ZSQLInlineSearch(_table="publications",key_main=personId)
else:
founds = self.ZSQLInlineSearch(_table="publications")
for found in founds:
if found.id_institutsbibliographie and (not found.id_institutsbibliographie =="") and (not found.id_institutsbibliographie =="0"):
entries = self.ZSQLInlineSearch(_table="institutsbiblio",id=found.id_institutsbibliographie)
for entry in entries:
self.ZSQLChange(_table='publications',_identify='oid=%s' % found.oid,year=entry.year,referencetype=entry.reference_type)
if found.id_gen_bib and (not found.id_gen_bib ==""):
entries = self.ZSQLInlineSearch(_table="bibliography",id=found.id_gen_bib)
for entry in entries:
self.ZSQLChange(_table='publications',_identify='oid=%s' % found.oid,year=entry.year,referencetype=entry.reference_type)
return True
def showNewDBEntries(self):
"""zeige neue Eintraege in der Datenbank ohne e-mail adressen bzw. fuer die noch kein Object angelegt wurde"""
qstr="select * from personal_www where web_object_created='no' and not key=''"
res=self.ZSQLQuery(qstr)
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','showNewDBEntries.zpt')).__of__(self)
return pt(newEntries=res)
def createNewStaffObjects(self,RESPONSE):
"""create new staff object"""
memberFolder=getattr(self,'members')
args=self.REQUEST.form
arg_k=args.keys()
arg_k.remove("submit")
ret=""
for key in arg_k:
k=self.urlUnQuote(key)
qstr="select * from personal_www where key=%s"%self.ZSQLQuote(k)
res=self.ZSQLQuery(qstr)[0]
if args[key]!="": #email-adresse wurde eingetragen
#create the object
e_mail=args[key]
try:
newObj=MPIWGStaff.MPIWGStaff(e_mail,res.last_name,res.first_name,k)
memberFolder._setObject(e_mail,newObj)
obj=getattr(memberFolder,e_mail)
obj.reindex_object()
ret+="Created %s \n"%e_mail
created=True
except:
msg="Cannot create new user %s (%s %s)"%(e_mail,sys.exc_info()[0],sys.exc_info()[1])
logging.error(msg)
ret+=msg+"\n"
created=False
if created:
qstr="update personal_www set web_object_created='yes',e_mail='%s@mpiwg-berlin.mpg.de' where key=%s"%(e_mail,self.ZSQLQuote(k))
self.ZSQLQuery(qstr)
return ret
def generateNewPersonEntry(self,data):
"""generate a new person entry for data, neue personen werden zunaechst nur in der datenbank angelegt """
#memberFolder=getattr(self,'members')
#create the object
# try:
# newObj=MPIWGStaff.MPIWGStaff(urllib.quote(data['key']),data['last_name'].encode('utf-8'),data['first_name'].encode('utf-8'))
# memberFolder._setObject(urllib.quote(data['key']),newObj)
# except:
# return False, "Cannot create new user %s (%s %s)"%(data['key'],sys.exc_info()[0],sys.exc_info()[1])
#
#create the new entry in the database
result,msg=MPIWGStaff.createNewDBEntry(self,data['publish_the_data'],data['key'],data['last_name'],
data['first_name'],data['title'],data['status'],"",
"",data['date_from'],data['date_to'],
data['department'],data['home_inst'],data['funded_by'],
data['e_mail2'],data['current_work'],"yes",data['date_stay_at_mpiwg'],data['group'],"no",data['current_work'])
return result,msg
def updatePersonEntry(self,data,ignoreEntries=[]):
"""update an person entry from data. but ignore all fields in ignore Entries"""
ignoreEntries.append('current_work') # TODO:updatecurrent work
if data['date_to']=="": # wenn date_to leer
data['date_to']="date_none"
if data['date_from']=="": # wenn date_fromleer
data['date_from']="date_none"
msg=""
#eintragen
columns=data.keys()
for x in ignoreEntries:
logging.info("ign rem: %s"%x)
try: #falls in ignore entries felder sind, die nicht in columns sind, fange den fehler ab
columns.remove(x)
except:
pass
insert=[]
for key in columns:
if data[key]=="date_none": # date_none eintrag wird zu null uebersetzt
insert.append('%s=null'%key)
else:
insert.append(""" "%s"=%s"""%(key,self.ZSQLQuote(data[key])))
insertStr=",".join(insert)
queryStr="update personal_www SET %s where key='%s'"%(insertStr,data['key'])
self.ZSQLQuery("SET DATESTYLE TO 'German'")
self.ZSQLQuery(queryStr)
#currentwork
#if not (txt==""):
# queryStr="INSERT INTO current_work (id_main,current,publish) VALUES ('%s','%s','%s')"%(id,txt,txt_p)
#
# self.ZSQLQuery(queryStr)
return True,msg
def updatePersonalwww_doIt(self):
"""do the update"""
args=self.REQUEST.form
resultSet=self.REQUEST.SESSION['personal_www']['resultSet']
news=self.REQUEST.SESSION['personal_www']['news']
conflicts=self.REQUEST.SESSION['personal_www']['conflicts']
ret="<html><body>"
# generate the new entry
if news and (len(news)>0):
ret+="<h2>Hinzugefügt</h2>"
ret+="<p>Neueinträge erscheinen erst auf der Homepage, wenn ihnen eine e-mail Adresse zugeordnet wurde.</p>"
ret+="<ul>"
for new in news:
if args.has_key(self.urlQuote(new.encode('utf-8'))): # entry was selected
result,msg=self.generateNewPersonEntry(resultSet[new])
if not result:
logging.error("Error (generateNewPersonEntry) %s"%msg)
ret+="<li>ERROR: %s %s"%(new.encode('utf-8'),msg)
else:
ret+="<li>OK: %s"%(new.encode('utf-8'))
if news and (len(news)>0):
ret+="<p>Neueinträge erscheinen erst auf der Homepage, wenn ihnen eine e-mail Adresse zugeordnet wurde.</p>"
ret+="</ul>"
# update
if len(conflicts.keys())>0:
ret+="<h2>Änderung des Benutzers übernehmen</h2>"
ret+="<p>Wenn nötig in Filemaker-db ändern:</p>"
# konflicte
for conflict in conflicts.keys():
ignoreEntries=[]
displayIgnored=[]
for cf in conflicts[conflict]:
if args[conflict.encode('utf-8')+'_'+cf[0]]=="stored": #use the stored one
ignoreEntries.append(cf[0]) #so ignore field cf[0]
displayIgnored.append(cf)
if len(displayIgnored)>0:
ret+="<h3>%s</h3>"%conflict.encode('utf-8')
ret+="<table border='1'>"
for iE in displayIgnored:
ret+="<tr><td>%s</td><td>%s</td><td>%s</td>"%(iE[0].encode('utf-8'),iE[1].encode('utf-8'),iE[2].encode('utf-8'))
ret+="</tabel>"
self.updatePersonEntry(resultSet[conflict],ignoreEntries=ignoreEntries)
# rest
cl=list(conflicts.keys())
for key in resultSet.keys():
if key not in cl:
self.updatePersonEntry(resultSet[key])
return ret+"</body></html>"
def updateInstitutsbiliography(self):
"""update the Institutsbibliogrpahy"""
self.upDateSQL('personalwww.xml')
return "<html><body>DONE</body></html>"
def updatePersonalwww_html(self):
"""update form for the homepages web form"""
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','updatePersonalwww.zpt')).__of__(self)
return pt()
def updatePersonalwww(self,uploadfile):
"""update personalwww
@param uploadfile: file handle auf das file
"""
dsn=self.getConnectionObj().connection_string
#dsn="dbname=personalwww"
resultSet=updatePersonalWWW.importFMPXML(uploadfile)
news,conflicts=updatePersonalWWW.checkImport(dsn, resultSet)
self.REQUEST.SESSION['personal_www']={}
self.REQUEST.SESSION['personal_www']['resultSet']=resultSet
self.REQUEST.SESSION['personal_www']['news']=news
self.REQUEST.SESSION['personal_www']['conflicts']=conflicts
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','updatePersonalwww_check.zpt')).__of__(self)
return pt()
def reindexCatalogs(self,RESPONSE=None):
"""reindex members and project catalog"""
try:
self.ProjectCatalog.manage_catalogReindex(self.REQUEST,RESPONSE,self.REQUEST['URL1'])
except:
logger("MPIWG Root (updatehomepage)",logging.WARNING," %s %s"%sys.exc_info()[:2])
if RESPONSE:
RESPONSE.redirect('manage_main')
def getAllMembers(self):
#ret=[]
results=self.MembersCatalog({'isPublished':True})
ret=[", ".join([proj.lastName, proj.firstName]).decode('utf-8') for proj in results]
ret.sort()
return ret
def printAllMembers(self):
"""print"""
members=self.getAllMembers()
ret=""
for x in members:
ret+="<p>%s</p>"%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,dep=None,date=None,onlyActive=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": # kompatibilitaet mit alter Konvention, x vor der Nummer macht project inactive
project[0].setActiveFlag(False)
if (not dep) or (idNr[0]==dep): #falls dep gesetzt ist nur dieses hinzufuegen.
if onlyActive and project[0].isActiveProject(): #nur active projekte
returnList.append((depth,nr,title,project[0]))
elif not onlyActive:
returnList.append((depth,nr,title,project[0]))
return returnList
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():
splitted=idNr.split('_')
if len(splitted)==1: # name des Feldes = idNr, dann Aendere id_nr
if not (fields[int(idNr)][3].xdata_05==form[idNr]):
fields[int(idNr)][3].xdata_05=form[idNr]
fields[int(idNr)][3].copyObjectToArchive()
if form.has_key(idNr+'_active'): # active flag is set
fields[int(splitted[0])][3].setActiveFlag(True)
else:
fields[int(splitted[0])][3].setActiveFlag(False)
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("<a href=%s >%s</a>"%(proj[0].absolute_url,person.encode('utf-8')))
ret.append("<a href=%s >%s</a>"%('members/'+proj[0].id+'/index.html',person))
else:
#ret.append("%s"%person.encode('utf-8'))
ret.append("%s"%person)
return string.join(ret,";")
def getMembersFromList(self,list):
"""get member names from person full text list"""
memberlist=[]
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:
member=self.MembersCatalog({'title':search})
except:
member=None
if member and (member[0].getObject().isPublished()):
if person =="Otto Sibum" : person="H. Otto Sibum"
if person =="Norton Wise" : person="M. Norton Wise"
#memberlist.append("<a href=%s >%s</a>"%(member[0].absolute_url,person.encode('utf-8')))
memberlist.append((person, member[0].getObject().getId()))
else:
#memberlist.append("%s"%person.encode('utf-8'))
memberlist.append((person,None))
return memberlist
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 and (proj[0].getObject().isPublished()):
if person =="Otto Sibum" : person="H. Otto Sibum"
if person =="Norton Wise" : person="M. Norton Wise"
#ret.append("<a href=%s >%s</a>"%(proj[0].absolute_url,person.encode('utf-8')))
if self.MPIWGrootURL().split("/")[-1]=='en':
tmpPath="/en/staff/members/"
else:
tmpPath="/de/mitarbeiter/members/"
ret.append("<a href=%s >%s</a>"%(tmpPath+proj[0].getObject().getId()+"/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,key=None,date=None):
"""get projects of a member
@param name: (optional)Vorname + Nachname
@param key: (optional) Key zur Idenfikation des Benutzer
@param date: (optional) Version die zum Zeitpunkt date gueltig war
"""
# TODO: Die ganze Loesung
def sortP(x,y):
"""sort by sorting number"""
#print x.xdata_05,y.xdata_05
return cmp(x.WEB_title,y.WEB_title)
ret=[]
logging.error("XXXXXXXXXXXXXXXXX")
if key:
#members=self.ZopeFind(self.members,obj_metatypes=['MPIWGStaff'],obj_ids=[email],search_sub=1)
members=self.MembersCatalog({'getKey':key})
if len(members)==0:
return ret
splitted = [members[0].lastName,members[0].firstName]
elif name:
splitted=name.split(",")
else:
return ret # name oder key mussen definiert sein
#XXXX
splitNeu=["\'"+splitted[1]+" "+splitted[0]+"\'"]
#for s in splitted:
# splitNeu.append("\""+s+"\"")
search=string.join(splitNeu,' AND ')
proj=self.ProjectCatalog({'xdata_01':search})
logging.error("XXXXXXXXXXX %s"%proj)
if proj:
proj2=[]
for x in proj:
if (not getattr(x.getObject(),'invisible',None)) and (getattr(x.getObject(),'archiveTime','')==''):
# furchtbarer hack um sicher zustellen dass christoph hoffmann nicht mit Dieter Hoffmann verwechselt wird.
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((name,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 generateNameIndex(self):
"""erzeuge einen index verwendeter personen"""
import psycopg
o = psycopg.connect('dbname=authorities user=dwinter password=3333',serialize=0)
results={}
print self.fulltext.historicalNames.items()
for nameItem in self.fulltext.historicalNames.items(): #gehe durch alle namen des lexikons
c = o.cursor()
name=nameItem[0]
print "check",name
c.execute("select lastname,firstname from persons where lower(lastname) = '%s'"%quote(name))
tmpres=c.fetchall()
firstnames=[result[1] for result in tmpres] # find all firstnames
if tmpres:
lastname=tmpres[0][0]
for found in self.fulltext({'names':name}):
if found.getObject().isActual():
for nh in found.getObject().getGetNeighbourhood(name, length=50,tagging=False): #hole umgebung
#schaue nun ob der vorname hinter oder vor dem name ist
position=nh.find(lastname)
# vorher
#print "NH",nh
bevorS=nh[0:position].split()
#print "BV",bevorS
if len(bevorS)>1:
try:
bevor=[bevorS[-1],bevorS[-2]]
except:
bevor=[bevorS[0]]
else:
bevor=[]
#nachher
behindS= re.split("[,|;| ]",nh[position:])
#print "BH",behindS
if len(behindS)>2:
try:
behind=behindS[1:3]
except:
behind=[bevorS[1]]
else:
behind=[]
for firstname in firstnames:
if firstname in bevor+behind: #Namen wie mit Adelspraedikaten werden so erstmal nich gefunden
id="%s,%s"%(lastname,firstname)
if not results.has_key(id):
results[id]=[]
objId=found.getObject().getId()
if not (objId in results[id]):
print "d %s for %s"%(id,objId)
results[id].append(objId)
self.nameIndex=results
return results
def editNameIndexHTML(self):
"""edit the name index"""
if not hasattr(self,'nameIndexEdited'): # falls editierter index noch nicht existiert, kopiere automatisch erstellten
self.nameIndexEdited=copy.copy(self.nameIndex)
print "huh"
#self.nameIndexEdited=copy.copy(self.nameIndex)
#print self.nameIndexEdited
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editHistoricalNames.zpt')).__of__(self)
return pt()
def getNamesInProject(self,projectId):
"""get all names ofnameIndexEdited which are references in projec with projectId"""
ret=[]
for name in self.nameIndexEdited.keys():
if projectId in self.nameIndexEdited[name]:
ret.append(name)
return ret
def editNameIndex(self,RESPONSE=None,name=None,occurrances=None,submit=None):
"""edit the index"""
nI=self.nameIndexEdited # mI introduced to make sure that changes to nameIndexEdited are know to ZODB
if submit=="delete":
dh=getattr(self,'deletedHistoricalNames',{})
if type(dh) is ListType:
dh={}
if not dh.has_key(name):
dh[name]=occurrances.split("\n")
else:
dh[name]+=occurrances.split("\n")
self.deletedHistoricalNames=dh
del self.nameIndexEdited[name]
elif (submit=="change"):
nI[name]=occurrances.split("\n")[0:]
elif (submit=="add"):
if not nI.has_key(name):
nI[name]=occurrances.split("\n")
else:
nI[name]+=occurrances.split("\n")
self.nameIndexEdited=nI
if RESPONSE is not None:
RESPONSE.redirect('editNameIndexHTML')
def restoreIndex(self):
"""restore"""
self.nameIndexEdited=self.nameIndex
return "done"
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"""
meta_type="MPIWGProject_publication"
def editPublication(self,text=None,RESPONSE=None):
"""edit a publication"""
if (not text):
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_publicationForm.zpt')).__of__(self)
return pt()
self.text=text[0:]
if RESPONSE:
RESPONSE.redirect("../managePublications")
class MPIWGProject_image(Image):
"""Images for Projects"""
meta_type="MPIWGProject_image"
def showImage(self,imageUrl=None):
"""show Images at an extra page"""
self.getContent('WEB_project_description',filter='yes') #get the content and store image infos into session
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','projectImageView.zpt')).__of__(self)
return pt()
def editImage(self,file=None,caption=None,RESPONSE=None):
"""edit the Image"""
if (not file) and (not caption):
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_imageForm.zpt')).__of__(self)
return pt()
if file and (not file.filename.lstrip().rstrip()==""):
self.manage_upload(file)
if caption:
self.caption=caption[0:]
if RESPONSE:
RESPONSE.redirect("../manageImages")
class MPIWGProject(CatalogAware,Folder):
"""Class for Projects"""
security=ClassSecurityInfo()
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):
return cmp(getattr(x[1],'place',0),getattr(y[1],'place',0))
founds=self.ZopeFind(self,obj_metatypes=[metatype]);
founds.sort(sort)
return founds
def copyPublicationsToList(self,RESPONSE=None):
"""copy publications in to list"""
publicationTxt=self.getContent('WEB_related_pub')
pubSplits=publicationTxt.split("<p>")
for pubSplit in pubSplits:
pubSplit=pubSplit.replace("</p>","")
self.addPublication(pubSplit)
if RESPONSE:
RESPONSE.redirect('managePublications')
def copyImageToMargin(self,RESPONSE=None):
"""copy inline images to marginal images"""
#getImages from WEB_project_description
description=self.getContent('WEB_project_description')
text2=description
splitted=text2.split("""<p class="picture">""")
imageURLs=[]
imageCaptions=[]
for split in splitted[1:]:
tmp=split.split("</p>")
#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="</p>".join(tmp[1:])
splitted=split2.split("""<p class="picturetitle">""")
if len(splitted)>1:
tmp=splitted[1].split("</p>")
imageCaptions.append(tmp[0].encode('utf-8'))
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')
def manageImages(self,imageName=None,op=None):
"""managage images"""
if imageName and op:
if op=='up':
images=self.getImages()
for image in images:
if image[0]==imageName:
nr=images.index(image)
if not nr==0:
images[nr-1][1].place+=1
images[nr][1].place-=1
pass
elif op=='down':
images=self.getImages()
for image in images:
if image[0]==imageName:
nr=images.index(image)
if not (nr==len(images)-1):
images[nr+1][1].place-=1
images[nr][1].place+=1
pass
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGProject_manageImagesForm.zpt')).__of__(self)
return pt()
def managePublications(self,pubName=None,op=None):
"""managage images"""
if pubName and op:
if op=='up':
publications=self.getPublications()
for publication in publications:
if publication[0]==pubName:
nr=publications.index(publication)
if not nr==0:
publications[nr-1][1].place+=1
publications[nr][1].place-=1
pass
elif op=='down':
publications=self.getPublications()
for publication in publications:
if publication[0]==pubName:
nr=publications.index(publication)
if not (nr==len(publications)-1):
publications[nr+1][1].place-=1
publications[nr][1].place+=1
pass
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGProject_managePublicationsForm.zpt')).__of__(self)
return pt()
def getPublications(self):
"""get all Publications"""
def sort_images(x,y):
return cmp(getattr(x[1],'place',0),getattr(y[1],'place',0))
publications=self.ZopeFind(self,obj_metatypes=['MPIWGProject_publication'])
publications.sort(sort_images)
return publications
def addPublication(self,text,RESPONSE=None):
"""add an MPIWG_Publication"""
name="publication_"+str(self.getLastPublicationNumber()+1)
newPublication=MPIWGProject_publication(name)
self._setObject(name,newPublication)
obj=getattr(self,name)
obj.text=text[0:]
obj.enabled=True;
obj.place=self.getLastPublicationNumber()+1
obj.id=name
if RESPONSE is not None:
RESPONSE.redirect('managePublications')
def getLastPublicationNumber(self):
publications=self.getPublications()
if not publications:
return 0
else:
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')
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)
return images
def getLastImageNumber(self):
images=self.getImages()
if not images:
return 0
else:
return getattr(images[-1][1],'place',0)
def deleteImage(self,id,RESPONSE=None):
"""delete Image id"""
self.manage_delObjects([id])
if RESPONSE:
RESPONSE.redirect('manageImages')
def hasChildren(self,date=None,onlyActive=True):
"""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"""
if not filename:
filename=fileHd.filename
if not fileHd:
fileHd=file(os.path.join(package_home(globals()),'blank.gif'))
newImage=MPIWGProject_image(filename,filename,fileHd)
self._setObject(filename,newImage)
obj=getattr(self,filename)
obj.caption=caption[0:]
obj.enabled=True;
obj.place=self.getLastImageNumber()+1
obj.id=filename
if RESPONSE is not None:
RESPONSE.redirect('manageImages')
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="""<h2>This is an outdated version, for the actual version please refer to <a href="%s">%s</a></h2>"""
s=self.aq_parent.absolute_url()
#print getattr(self,'archiveTime',actualTime)
if getattr(self,'archiveTime',actualTime)< actualTime:
return retTXT%(s,s)
else:
return ""
def getActualVersion(self,date=None):
"""actuelle version"""
def sortProjectsByTime(x,y):
return cmp(x[1].archiveTime,y[1].archiveTime)
if not date:
if self.isActual():
return self
else:
return None
#suche ob aeltere versionen vorhanden sind
finds=self.ZopeFind(self,obj_metatypes=['MPIWGProject'])
if not finds: #wenn nicht dann teste ob die aktuelle version schon existiert hat.
ad=getattr(self,'creationTime','20050101000000')
if int(date)>int(ad):
return self
else:
return None
else:
finds.sort(sortProjectsByTime)
for find in finds:
#gehe durch die alten Projekte und finde das entprechende
if (int(find[1].archiveTime) > int(date)) and (int(date)>int(getattr(find[1],'creationTime','20050101000000'))):
return find[1]
#kein passendes gefunden, dann teste ob das aktuelle in frage kommt
ad=getattr(self,'creationTime','20050101000000')
if int(date)>int(ad):
return self
else:
return None
def isActual(self):
"""gibt 1 zurueck wenn aktuell, 0 sonst"""
actualTime=time.localtime()
#print getattr(self,'archiveTime',actualTime)
if getattr(self,'archiveTime',actualTime)< actualTime:
return 0
else:
return 1
def copyObjectToArchive(self):
"""kopiere aktuelles objekt ins archiv"""
cb=self.aq_parent.manage_copyObjects(self.getId())
self.manage_pasteObjects(cb)
actualTime=time.localtime()
self.manage_renameObject(self.getId(),self.getId()+"_"+time.strftime("%Y%m%d%H%M%S",actualTime))
obj=getattr(self,self.getId()+"_"+time.strftime("%Y%m%d%H%M%S",actualTime))
obj.setArchiveTime(time.strftime("%Y%m%d%H%M%S",actualTime))
ids=[x[0] for x in self.ZopeFind(obj,obj_metatypes=['MPIWGProject'])]
obj.manage_delObjects(ids)
def setArchiveTime(self,time):
"""set Archive Time"""
self.archiveTime=time[0:]
def versionManageForm(self):
"""version Manage form:currently only set to invisible"""
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGProject_versionManageForm.zpt')).__of__(self)
return pt()
def versionManage(self,invisible=None,RESPONSE=None):
"""version Manage form:currently only set to invisible"""
self.invisible=invisible
if RESPONSE is not None:
RESPONSE.redirect('manage_main')
def crossLinker(self):
"""experimental crosslinker"""
splitted=self.WEB_project_description[0].split()
new=[]
for split in splitted:
try:
found=self.DescriptionCatalog({'fulltext':split})
if len(found)>1:
new.append("<a href=%s>%s</a>"%(split,split))
else:
new.append(split)
except:
new.append(split)
return string.join(new)
def generateTemplate(self,RESPONSE=None):
"""Erzeuge Template fuer defined fields not_used"""
id="index_html"
title=id
if self._getOb('index_html'):
self._delObject('index_html')
newObj=ZopePageTemplate(id,'TEXT')
self._setObject(id,newObj)
#self.manage_addPageTemplate(id,title)
if RESPONSE is not None:
RESPONSE.redirect('manage_main')
def __init__(self, id, argv=None):
"""initiere classe"""
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
if argv:
for arg in definedFields:
try:
setattr(self,arg,argv[arg])
except:
setattr(self,arg,"")
else:
for arg in definedFields:
setattr(self,arg,'')
manage_options = Folder.manage_options+(
{'label':'Load New File','action':'loadNewFileForm'},
{'label':'Edit ProjectInfo','action':'editMPIWGProjectForm'},
{'label':'Edit BasisInfo','action':'editMPIWGBasisForm'},
{'label':'Edit Publications','action':'editMPIWGRelatedPublicationsForm'},
{'label':'Edit Themes & Disciplines','action':'editMPIWGDisciplinesThemesForm'},
{'label':'Versionmanager','action':'versionManageForm'},
)
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 setActiveFlag(self,status=True):
"""set the active flag"""
self.isActiveFlag=status
def checkDate(self,date):
"""teste ob zum Zeitpunkt date eine andere version existierte"""
def sortProjectsByTime(x,y):
return cmp(x[1].archiveTime,y[1].archiveTime)
#suche ob aeltere versionen vorhanden sind
finds=self.ZopeFind(self,obj_metatypes=['MPIWGProject'])
if not finds: #wenn nicht dann teste ob die aktuelle version schon existiert hat.
ad=getattr(self,'creationTime','20050101000000')
if int(date)>int(ad):
return self.REQUEST['URL1']+"/"+self.getId()
else:
return self.REQUEST['URL1']+"/no_project"
else:
finds.sort(sortProjectsByTime)
for find in finds:
#gehe durch die alten Projekte und finde das entprechende
if (int(find[1].archiveTime) > int(date)) and (int(date)>int(getattr(find[1],'creationTime','20050101000000'))):
return self.REQUEST['URL1']+"/"+find[1].getId()
#kein passendes gefunden, dann teste ob das aktuelle in frage kommt
ad=getattr(self,'creationTime','20050101000000')
if int(date)>int(ad):
return self.REQUEST['URL1']+"/"+self.getId()
else:
return self.REQUEST['URL1']+"/no_project"
def no_project(self):
"""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 <span class="found">XX</span> 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(""" <span class="found">%s</span>"""%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:
context=self
if request:
if self.REQUEST.has_key('date') and self.REQUEST.SESSION.get('MPI_redirected',None)==None:
self.REQUEST.SESSION['MPI_redirected']=1
self.REQUEST.RESPONSE.redirect(self.checkDate(self.REQUEST['date'])+"?date="+self.REQUEST['date'])
else:
self.REQUEST.SESSION['MPI_redirected']=None
#ext=self.ZopeFind(self.aq_parent,obj_ids=["project_main"])
ext=getattr(self,"project_main",None)
if ext:
return getattr(self,ext.getId())()
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','project_main')).__of__(context)
return pt()
def getDataFields(self):
"""giveListofDatafields"""
ret=[]
for x in range(1,14):
if not x in [6,10,9]: # not used fields
ret.append('xdata_%02i'%x)
return ret
def getDefinedFields(self):
"""show all defined fields"""
return definedFields
def getAttribute(self,field):
"""get attrbiute"""
return getattr(self,field)
def getContent(self,field,filter=None):
"""Inhalt des Feldes"""
text=u''
for x in getattr(self,field):
try:
text +=x
except:
text = x
try:
if text[len(text)-1]==";":
text=text[0:len(text)-1]
except:
pass
if text=='':
text2=text
else:
text2=re.sub(r';([^\s])','; \g<1>',text)
#teste ob ergebnis leer und header dann nehme title
if (text2=='') and (field=='WEB_project_header'):
return self.getContent('WEB_title')
if filter:
splitted=text2.split("""<p class="picture">""")
if len(splitted)>1:
tmp=splitted[1].split("</p>")
#return repr(splitted[1])
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="</p>".join(tmp[1:])
text3=splitted[0]+split2
splitted=text3.split("""<p class="picturetitle">""")
if len(splitted)>1:
tmp=splitted[1].split("</p>")
self.imagecap=tmp[0].encode('utf-8')
split4="".join(tmp[1:])
text5=splitted[0]+split4
else:
#keine caption
text5=text3
else:
#kein bild
text5=text2
else:
text5=text2
#teste ob WEB_project_description und keine fuehrenden p tags
if (len(text5)>4) and (not text5[0:3]=='<p>') and (field=='WEB_project_description'):
text5= "<p>"+text5+"</p>"
#filter image
text5=text5.lstrip().rstrip() #loescher leerzeichen und einzelndes br
if (text5=="<br>") or (text5=="<br/>"):
text5=""
logging.debug("getcontent: field=%s filter=%s -> %s"%(field,filter,repr(text5)))
#return unicodify(text5)
return utf8ify(text5) # return as utf-8 byte string
def showImagesOfPage(self,imageUrl=None):
"""show Images of project"""
self.getContent('WEB_project_description',filter='yes') #get the content and store image infos into session
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','projectImageView.zpt')).__of__(self)
return pt()
def show_html(self):
"""simple index"""
#return "HI"
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGProject_index.zpt')).__of__(self)
return pt()
def saveFromPreview(self):
"""save content aus preview"""
self.WEB_project_description=self.previewTemplate.WEB_project_description[0:]
self.REQUEST.RESPONSE.redirect("./index.html")
def saveEditedContent(self,kupu=None,preview=None):
"""save Edited content"""
if preview:
kupu=preview
#find content of body tags
start=kupu.find("<body>")
end=kupu.find("</body>")
newcontent= kupu[start+6:end]
if preview:
return self.preview(newcontent)
self.copyObjectToArchive()
self.WEB_project_description=newcontent[0:]
self.REQUEST.RESPONSE.redirect("./index.html")
return True
security.declareProtected('View management screens','edit')
def edit(self,western=None):
"""Edit pages"""
if western:
self.REQUEST.RESPONSE.setCookie("MP_debug_code","western",path="/")
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGProjectNeu.zpt')).__of__(self)
return pt()
edit_MPIWGProject_main = PageTemplateFile('zpt/edit_MPIWGProject_main', globals())
def getPathStyle(self, path, selected, style=""):
"""returns a string with the given style + 'sel' if path == selected."""
if path == selected:
return style + 'sel'
else:
return style
def preview(self,description):
"""preview"""
tmpPro=getattr(self,"previewTemplate",None)
if not tmpPro:
tmpPro=MPIWGProject("previewTemplate")
self._setObject("previewTemplate",tmpPro)
for field in definedFields:
setattr(tmpPro,field,getattr(self,field))
tmpPro.WEB_project_description=description[0:]
tmpPro.invisible=True
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','previewFrame.zpt')).__of__(self)
return pt()
#return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+"/previewTemplate")
def getWebProject_description(self):
"""get description"""
debug= self.REQUEST.cookies.get("MP_debug_code",None)
if debug and debug=="western":
return """
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>%s
</html></body>
"""%self.WEB_project_description[0]
return """
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>%s
</html></body>
"""%self.getContent('WEB_project_description')
def editMPIWGProjectForm(self):
"""editform"""
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGProject.zpt')).__of__(self)
return pt()
def editMPIWGProject(self,RESPONSE=None,fromEdit=None):
"""edit the project and archive the old version"""
self.copyObjectToArchive() # archive the object
for x in definedFields:
if self.REQUEST.has_key(x):
setattr(self,x,[self.REQUEST[x].decode('utf-8')])
if self.REQUEST.has_key('historicalNames'):
self.en.changeHistoricalNames(self.getId(),self.REQUEST['historicalNames'].split("\n"))
if self.REQUEST.has_key('active'):
self.setActiveFlag(True)
else:
self.setActiveFlag(False)
if fromEdit and (RESPONSE is not None):
RESPONSE.redirect('./editMPIWGBasisEditor')
else:
if RESPONSE is not None:
RESPONSE.redirect('manage_main')
security.declareProtected('View managment screens','editMPIWGDisciplinesThemesEditor')
def editMPIWGDisciplinesThemesEditor(self):
"""edit from edit"""
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGDisciplinesThemesNeu.zpt')).__of__(self)
return pt()
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,fromEdit=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 fromEdit and (RESPONSE is not None):
RESPONSE.redirect('./editMPIWGDisciplinesThemesEditor')
else:
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(";")
splitted=[y.rstrip().lstrip() for y in splitted]
for x in splitted:
x=re.sub(r"[^A-z ]","",x)
if (not x==u'') and x in wert:
return 1
return 0
security.declareProtected('View management screens','editMPIWGBasisEditor')
def editMPIWGBasisEditor(self):
"""editform"""
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGBasisNeu.zpt')).__of__(self)
return pt()
security.declareProtected('View management screens','editMPIWGBasisForm')
def editMPIWGBasisForm(self):
"""editform"""
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGBasis.zpt')).__of__(self)
return pt()
security.declareProtected('View management screens','editMPIWGRelatedPublicationsForm')
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(os.path.join(package_home(globals()),'zpt','MPIWGProject_newfile.zpt')).__of__(self)
return pt()
def loadNewFile(self,RESPONSE=None):
"""einlesen des neuen files"""
fileupload=self.REQUEST['fileupload']
if fileupload:
file_name=fileupload.filename
filedata=fileupload.read()
argv=xmlhelper.proj2hash(filedata)
#print argv.keys()
for arg in definedFields:
#print arg,argv[arg],getattr(self,arg)
try:
temp=argv[arg][0:]
#old=getattr(self,arg)
setattr(self,arg,temp)
#print old,getattr(self,arg)
except:
"""nothing"""
if RESPONSE is not None:
RESPONSE.redirect('manage_main')
def manage_addMPIWGProjectForm(self):
"""form for adding the project"""
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.get('fileupload',None)
if fileupload:
file_name=fileupload.filename
filedata=fileupload.read()
argv=xmlhelper.proj2hash(filedata)
#print argv
newObj=MPIWGProject(id,argv)
else:
newObj=MPIWGProject(id)
self._setObject(id,newObj)
if RESPONSE is not None:
RESPONSE.redirect('manage_main')
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>