Annotation of MPIWGWeb/MPIWGProjects.py, revision 1.47.2.35
1.9 dwinter 1: """This contains the class MPIWG Projects
1.42 dwinter 2: for organizing and maintaining the different project pages
1.6 dwinter 3:
4: """
1.47.2.28 dwinter 5: #TODO: mechanismus fur links to personen ueberarbeiten, da jetzt alle e_mails als members auftauchen unabhaengig vom status publish_the_data
1.47.2.29 dwinter 6: #TODO: was passiert wenn aenderungen von jochen im filemaker nicht mit den aenderungen im sql uebereinstimmen
1.47.2.34 dwinter 7: #TODO: in einzelnen projecte steht als pfad auf die bilder noch wwwneu statt www
1.47.2.28 dwinter 8:
1.1 dwinter 9: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
10: from Products.PageTemplates.PageTemplate import PageTemplate
11: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
1.11 dwinter 12: from Products.ZSQLExtend.ZSQLExtend import ZSQLExtendFolder
1.45 dwinter 13: from Products.ZCatalog.CatalogPathAwareness import CatalogAware
1.47.2.22 dwinter 14: from OFS.Image import Image
1.34 dwinter 15: from Globals import package_home
1.12 dwinter 16: import urllib
1.1 dwinter 17: import MPIWGStaff
18: import string
19: import re
1.34 dwinter 20: import os
1.5 dwinter 21: from types import *
1.40 dwinter 22: import zLOG
1.47.2.23 dwinter 23: import xmlhelper # Methoden zur Verwaltung der projekt xml
1.1 dwinter 24: from OFS.SimpleItem import SimpleItem
25: from OFS.Folder import Folder
1.45 dwinter 26: from Products.ZSQLMethods.SQL import SQLConnectionIDs
1.47.2.21 dwinter 27: from AccessControl import ClassSecurityInfo
1.11 dwinter 28: from bibliography import *
1.42 dwinter 29: import time
1.47.2.28 dwinter 30: import xml.dom.minidom
31: import sys
1.47.2.29 dwinter 32: from Ft.Xml.XPath import Evaluate
33: from Ft.Xml.XPath.Context import Context
34: from Ft.Xml.Domlette import NonvalidatingReader,PrettyPrint, Print
35: from Ft.Xml import EMPTY_NAMESPACE
1.11 dwinter 36:
1.1 dwinter 37: 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']
38:
39: checkFields = ['xdata_01']
40:
1.9 dwinter 41:
1.47.2.28 dwinter 42: def getTextFromNode(nodename):
43: nodelist=nodename.childNodes
44: rc = ""
45: for node in nodelist:
46: if node.nodeType == node.TEXT_NODE:
47: rc = rc + node.data
48: return rc
1.9 dwinter 49:
1.1 dwinter 50: def sortF(x,y):
1.9 dwinter 51: try:
52: return cmp(x[1],y[1])
53: except:
1.18 dwinter 54: try:
55: return cmp(str(x[1]),str(y[1]))
56: except:
1.46 dwinter 57:
1.18 dwinter 58: return 0
1.5 dwinter 59:
60: def sortI(x,y):
61: xsplit=x[1].split(".")
62: ysplit=y[1].split(".")
63: xret=""
64: yret=""
65: try:
66: for i in range(5):
67: try:
68: yret=yret+"%04i"%int(xsplit[i])
69: except:
70: yret=yret+"%04i"%0
71:
72: try:
73: xret=xret+"%04i"%int(ysplit[i])
74: except:
75: xret=xret+"%04i"%0
76:
77:
78: return cmp(int(yret),int(xret))
79: except:
80: return cmp(x[1],y[1])
1.1 dwinter 81:
1.47.2.14 dwinter 82: class MPIWGLink(SimpleItem):
83: """create a symbolic link to another page"""
84:
85: meta_type="MPIWGLink"
86:
1.47.2.16 dwinter 87: def isActiveItem(self):
88: """teste ob ausgewaehlt"""
1.47.2.17 dwinter 89: #url1 beim link anstelle von url1, da link jeweils index_html als url hat.
90: if self.absolute_url()==self.REQUEST['URL1']:
1.47.2.16 dwinter 91: return "aktiv"
92: else:
93: return ""
1.47.2.15 dwinter 94:
1.47.2.14 dwinter 95: def __init__(self,id,link,title='',weight=''):
96: """init mpiwglink"""
97: self.id=id
98: self.link=link
99: self.title=title
100: self.weight=weight
101:
102: def getObj(self):
103: """bekomme original"""
104: ## objpath=self.link.replace("/",".")
105: ## if objpath[0]!=".":
106: ## objpath="."+objpath
107:
108: ## print objpath
109: ## return eval("self"+objpath)
110:
111:
1.47.2.15 dwinter 112: splitted=self.link.lstrip().split("/")
1.47.2.14 dwinter 113: obj=self
114: for x in splitted:
1.47.2.25 dwinter 115: if not x=="":
1.47.2.15 dwinter 116: obj=getattr(obj,x)
1.47.2.14 dwinter 117:
118: return obj
119:
120: def getWeight(self):
121: if self.linkWeight and linkWeight!="":
122: return self.linkWeight
123: else:
124: return self.getObj().weight
125:
126: manage_options=SimpleItem.manage_options+(
127: {'label':'main config','action':'changeLinkForm'},
128: )
129:
130:
131: def changeLinkForm(self):
132: """change MPIWG link"""
133: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGLinkChange.zpt')).__of__(self)
134: return pt()
135:
136: def changeLink(self,link,title,weight,RESPONSE=None):
137: """change links"""
138: self.link=link
139: self.title=title
140: self.weight=weight
141:
142: if RESPONSE is not None:
143: RESPONSE.redirect('manage')
144:
145: def index_html(self):
146: """index"""
147:
148: return self.getObj().pt_render(extra_context={'here':self})
149:
150:
151: def manage_addMPIWGLinkForm(self):
152: """Form for adding link"""
153: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/AddMPIWGLink.zpt')).__of__(self)
154: return pt()
155:
156: def manage_addMPIWGLink(self,id,link,title,weight,RESPONSE=None):
157: """add link"""
158: newObj=MPIWGLink(id,link,title,weight)
159:
160: self._setObject(id,newObj)
161:
162: if RESPONSE is not None:
163: RESPONSE.redirect('manage_main')
164:
165:
1.37 dwinter 166: class MPIWGTemplate(ZopePageTemplate):
167: """Create a layout Template for different purposes"""
168:
169: meta_type="MPIWGTemplate"
170:
1.47.2.1 dwinter 171: manage_options=ZopePageTemplate.manage_options+(
172: {'label':'Change Weight','action':'changeWeightForm'},
173: )
174:
175: def changeWeightForm(self):
176: """change weight form"""
177: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGTemplateChangeWeight.zpt')).__of__(self)
178: return pt()
179:
180: def changeWeight(self,weight,RESPONSE=None):
181: """change weight"""
182: self.weight=weight
183: if RESPONSE is not None:
184: RESPONSE.redirect('manage')
185:
186:
1.37 dwinter 187: def __init__(self, id, text=None, content_type=None,MPIWGType=None):
188: self.id = str(id)
189:
190:
191:
192: self.ZBindings_edit(self._default_bindings)
193: if text is None:
194: self._default_content_fn = os.path.join(package_home(globals()),
195: 'zpt/MPIWG_%s_template_standard.zpt'%MPIWGType)
196: text = open(self._default_content_fn).read()
197: self.pt_edit(text, content_type)
198:
199:
200: """change form"""
201:
1.47.2.16 dwinter 202: def isActiveItem(self):
1.47.2.1 dwinter 203: """teste ob ausgewaehlt"""
204: if self.absolute_url()==self.REQUEST['URL']:
205: return "aktiv"
206: else:
207: return ""
1.47.2.25 dwinter 208:
1.37 dwinter 209: def manage_addMPIWGTemplateForm(self):
210: """Form for adding"""
211: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/AddMPIWGTemplate.zpt')).__of__(self)
212: return pt()
213:
214: from urllib import quote
215:
216:
1.47.2.1 dwinter 217: def manage_addMPIWGTemplate(self, MPIWGType,id, title=None,weight=0,REQUEST=None):
1.37 dwinter 218: "Add a Page Template with optional file content."
219: if type(MPIWGType)==StringType:
220: MPIWGTypes=[MPIWGType]
221: else:
222: MPIWGTypes=MPIWGType
223:
224: for singleType in MPIWGTypes:
225:
226:
227: if REQUEST is None:
228: self._setObject(id, MPIWGTemplate(id, text,EchoType=singleType))
229: ob = getattr(self, id)
230:
231: if title:
232: ob.pt_setTitle(title)
233: return ob
234: else:
235: file = REQUEST.form.get('file')
236: headers = getattr(file, 'headers', None)
237: if headers is None or not file.filename:
238: zpt = MPIWGTemplate(id,MPIWGType=singleType)
239: else:
240: zpt = MPIWGTemplate(id, file, headers.get('content_type'))
241:
242: self._setObject(id, zpt)
243: ob = getattr(self, id)
244: if title:
245: ob.pt_setTitle(title)
246:
247: try:
248: u = self.DestinationURL()
249: except AttributeError:
250: u = REQUEST['URL1']
251:
1.47.2.1 dwinter 252: ob = getattr(self, id)
253: ob.weight=weight
254:
1.37 dwinter 255: REQUEST.RESPONSE.redirect(u+'/manage_main')
256: return ''
257:
1.5 dwinter 258:
1.11 dwinter 259: class MPIWGRoot(ZSQLExtendFolder):
1.1 dwinter 260: """Stammordner für den Web-Server"""
261:
1.9 dwinter 262: fieldLabels={'WEB_title':'WEB_Title','xdata_01':'Responsible Scientists','xdata_02':'Department',
263: 'xdata_03':'Historical Persons','xdata_04':'Time period',
264: 'xdata_05':'Sorting number','xdata_06':'Keywords','xdata_07':'Short title',
1.47.2.18 dwinter 265: 'xdata_08':'Other involved scholars' ,'xdata_09':'Disciplines','xdata_10':'Themes',
1.9 dwinter 266: 'xdata_11':'Object Digitallibrary','xdata_12':'Cooperation partners',
267: 'xdata_13':'Funding institutions','WEB_project_header':'WEB_project_header',
268: 'WEB_project_description':'WEB_project_description','WEB_related_pub':'WEB_related_pub'}
269:
1.38 dwinter 270: folders=['MPIWGProject','Folder','ECHO_Navigation']
1.1 dwinter 271: meta_type='MPIWGRoot'
1.8 dwinter 272:
1.47.2.20 dwinter 273: def versionHeaderEN(self):
274: """version header text"""
275:
276: date= self.REQUEST.get('date',None)
277: if date:
278: txt="""<h2>This pages shows the project which existed at %s</h2>"""%str(date)
279: return txt
280: return ""
281:
282: def versionHeaderDE(self):
283: """version header text"""
284: date= self.REQUEST.get('date',None)
285: if date:
286: txt="""<h2>Auf dieser Seite finden Sie die Projekte mit Stand vom %s</h2>"""%str(date)
287: return ""
288:
1.47.2.28 dwinter 289:
290: def createOrUpdateId_raw(self):
291: """create sequence to create ids for bibliography"""
292: debug=None
293: #suche groesste existierende id
294: founds=self.ZSQLQuery("select id from bibliography")
295:
296: if founds:
297: ids=[int(x.id[1:]) for x in founds]
298: maximum=max(ids)
299:
1.47.2.32 dwinter 300: id_raw=self.ZSQLQuery("select nextval('id_raw')",debug=debug)
1.47.2.28 dwinter 301:
302: if id_raw:
1.47.2.32 dwinter 303: self.ZSQLQuery("drop sequence id_raw",debug=debug)
1.47.2.28 dwinter 304:
1.47.2.32 dwinter 305: self.ZSQLQuery("create sequence id_raw start %i"%(maximum+1),debug=debug)
1.47.2.28 dwinter 306:
307:
1.47.2.18 dwinter 308: def queryLink(self,link):
309: """append querystring to the link"""
310: return "%s?%s"%(link,self.REQUEST.get('QUERY_STRING',''))
311:
1.47.2.7 dwinter 312: def getKategory(self,url):
1.47.2.25 dwinter 313: """kategorie"""
314: splitted=url.split("/")
315: return splitted[4]
1.47.2.7 dwinter 316:
1.47.2.6 dwinter 317: def generateUrlProject(self,url,project=None):
1.47.2.5 dwinter 318: """erzeuge aus absoluter url, relative des Projektes"""
1.47.2.25 dwinter 319: if project:
1.47.2.18 dwinter 320: splitted=url.split("/")
321: length=len(splitted)
322: short=splitted[length-2:length]
323:
324: base=self.REQUEST['URL3']+"/"+"/".join(short)
325:
1.47.2.25 dwinter 326: else:
1.47.2.18 dwinter 327: findPart=url.find("/projects/")
328: base=self.REQUEST['URL1']+"/"+url[findPart:]
329:
330:
1.47.2.5 dwinter 331: return base
332:
1.47.2.1 dwinter 333: def isNewCapital(self,text=None,reset=None):
334: if reset:
335: self.REQUEST['capital']="A"
336: return True
337: else:
338: if len(text)>0 and not (text[0]==self.REQUEST['capital']):
339: self.REQUEST['capital']=text[0]
340: return True
341: else:
342: return False
343:
1.47.2.16 dwinter 344: def subNav(self,obj):
1.47.2.1 dwinter 345: """return subnav elemente"""
346: def sortWeight(x,y):
347: x1=int(getattr(x[1],'weight','0'))
348: y1=int(getattr(y[1],'weight','0'))
349: return cmp(x1,y1)
1.47.2.16 dwinter 350: #if obj.meta_type in ['MPIWGTemplate','MPIWGLink']:
351: # id=obj.aq_parent.getId()
352: #else:
353:
354: #id=obj.getId()
1.47.2.17 dwinter 355:
356:
357: #suche die zweite ebene
358: if not obj.aq_parent.getId() in ['de','en']:
359: obj=obj.aq_parent
360:
1.47.2.16 dwinter 361: while not self.ZopeFind(self,obj_ids=[obj.getId()]):
362: obj=obj.aq_parent
1.47.2.17 dwinter 363:
1.47.2.16 dwinter 364: if hasattr(self,obj.getId()):
365:
366: subs=self.ZopeFind(getattr(self,obj.getId()),obj_metatypes=['MPIWGTemplate','MPIWGLink'])
1.47.2.8 dwinter 367: subret=[]
1.47.2.16 dwinter 368:
1.47.2.8 dwinter 369: for x in subs:
370: if not(x[1].title==""):
371: subret.append(x)
372: subret.sort(sortWeight)
373: return subret
1.47.2.2 dwinter 374: else:
375: return None
1.47.2.16 dwinter 376:
1.47.2.1 dwinter 377: def isActive(self,name):
378: """teste ob subnavigation aktiv"""
379: for part in self.REQUEST['URL'].split("/"):
380: if part==name:
381: return True
382: return False
383:
384:
1.34 dwinter 385: def upDateSQL(self,fileName):
386: """updates SQL databases using fm.jar"""
387: fmJarPath=os.path.join(package_home(globals()), 'updateSQL/fm.jar')
388: xmlPath=os.path.join(package_home(globals()), "updateSQL/%s"%fileName)
1.40 dwinter 389: zLOG.LOG("MPIWG Web",zLOG.INFO,"java -classpath %s -Djava.awt.headless=true Convert %s"%(fmJarPath,xmlPath))
390: ret=os.popen("java -classpath %s -Djava.awt.headless=true Convert %s"%(fmJarPath,xmlPath),"r").read()
1.47.2.25 dwinter 391: zLOG.LOG("MPIWG Web",zLOG.INFO,"result convert: %s"%ret)
1.34 dwinter 392: return 1
393:
1.31 dwinter 394: def patchProjects(self,RESPONSE):
395: """patch"""
396: projects=self.ZopeFind(self.projects,obj_metatypes=['MPIWGProject'])
397: for project in projects:
1.47.2.25 dwinter 398: tmp=project[1].WEB_project_description[0].replace("/CD/projects/","")[0:]
399: setattr(project[1],'WEB_project_description',[tmp[0:]])
400: RESPONSE.write("<p>%s</p>\n"%project[0])
1.31 dwinter 401:
1.11 dwinter 402: def replaceNotEmpty(self,format,field):
403: """replace not empty"""
1.44 dwinter 404: if field and (not field.lstrip()==''):
1.11 dwinter 405: return format%field
406: else:
407: return ""
408:
1.29 dwinter 409:
1.45 dwinter 410: def isActual(self,project):
411: """checke if project is actual"""
412: actualTime=time.localtime()
413: obj= project.getObject()
414:
415: if getattr(obj,'archiveTime',actualTime)< actualTime:
416: return False
417: else:
418: return True
419:
1.29 dwinter 420: def redirectIndex_html(self,request):
421: #return request['URL1']+'/index_html'
1.11 dwinter 422:
1.29 dwinter 423: return urllib.urlopen(request['URL1']+'/index_html').read()
424:
425:
1.11 dwinter 426: def formatBibliography(self,here,found):
427: """format"""
428: return formatBibliography(here,found)
429:
1.21 dwinter 430: def getValue(self,fieldStr):
1.9 dwinter 431: """Inhalt des Feldes"""
432:
1.21 dwinter 433: if type(fieldStr)==StringType:
434: field=fieldStr
1.9 dwinter 435: else:
1.21 dwinter 436: field=fieldStr[0]
437: try:
438: if field[len(field)-1]==";":
439: field=field[0:len(field)-1]
440: except:
441:
442: """nothing"""
443: field=re.sub(r';([^\s])','; \g<1>',field)
444: return field.encode('utf-8')
445:
1.9 dwinter 446:
447:
1.8 dwinter 448: def sortedNames(self,list):
449: """sort names"""
450:
1.12 dwinter 451: def sortLastName(x_c,y_c):
1.13 dwinter 452: try:
453: x=urllib.unquote(x_c).encode('utf-8','ignore')
454: except:
455: x=urllib.unquote(x_c)
456:
457: try:
458: y=urllib.unquote(y_c).encode('utf-8','ignore')
459: except:
460: x=urllib.unquote(y_c)
461:
462:
1.12 dwinter 463:
1.8 dwinter 464: try:
465: last_x=x.split()[len(x.split())-1]
466: last_y=y.split()[len(y.split())-1]
467:
468: except:
469:
470: last_x=""
471: last_y=""
472:
473:
474:
475: if last_x<last_y:
476: return 1
477: elif last_x>last_y:
478: return -1
479: else:
480: return 0
481:
482: list.sort(sortLastName)
483: list.reverse()
484:
485: return list
1.1 dwinter 486:
487: def __init__(self, id, title):
488: """init"""
489: self.id=id
490: self.title=title
1.12 dwinter 491:
492: def urlQuote(self,str):
493: """quote"""
494: return urllib.quote(str)
495:
496: def urlUnQuote(self,str):
497: """quote"""
498: return urllib.unquote(str)
499:
1.8 dwinter 500: def harvestHistoricalPersons(self):
501: """erstelle liste aller erwaehnten actors"""
502:
503: def normalize(str):
504: """loesche fuhrendes space"""
505: if (len(str)>1) and (str[0]==" "):
506: ret=str[1:]
507: else:
508: ret=str
509: return ret
510:
511: list={}
512: projects=self.ZopeFind(self.projects,obj_metatypes=['MPIWGProject'])
513:
514: for project in projects:
515: lg=len(project[1].xdata_03[0])-1
516:
517: if (lg>1) and (project[1].xdata_03[0][lg]==";"):
1.12 dwinter 518: project[1].xdata_03[0]=project[1].xdata_03[0][0:lg]
1.8 dwinter 519:
520:
521:
522:
523: try:
524: if len(project[1].xdata_03[0].split(";"))>1: # guess if separator is ;
525: for person in project[1].xdata_03[0].split(";"):
526: personNormal=normalize(person)
527: if personNormal in list.keys():
1.12 dwinter 528: list[urllib.quote(personNormal)][1].append(project[1])
1.8 dwinter 529: else:
1.12 dwinter 530: list[urllib.quote(personNormal)]=(personNormal,[project[1]])
1.8 dwinter 531: else: #guess , is sepeator
532: for person in project[1].xdata_03[0].split(","):
533: personNormal=normalize(person)
1.12 dwinter 534: if urllib.quote(personNormal) in list.keys():
535: list[urllib.quote(personNormal)][1].append(project[1])
1.8 dwinter 536: else:
1.12 dwinter 537: list[urllib.quote(personNormal)]=(personNormal,[project[1]])
1.8 dwinter 538:
539: except:
1.47.2.30 dwinter 540: zLOG.LOG("MPIWG Web (harvestHistoricalPerson)",zLOG.ERROR,"cannot analyize: %s"%repr(project))
1.46 dwinter 541:
1.8 dwinter 542:
543: return list
544:
545: def storeHistoricalPersons(self,RESPONSE=None):
546: """store persons"""
547: self.personDict={}
548: personDict=self.harvestHistoricalPersons()
549: for person in personDict.keys():
1.12 dwinter 550: for project in personDict[person][1]:
1.8 dwinter 551: if person in self.personDict.keys():
1.12 dwinter 552: self.personDict[person][1].append((project.absolute_url(),project.WEB_title[0],project.xdata_01[0]))
1.8 dwinter 553: else:
1.12 dwinter 554: self.personDict[person]=(personDict[person][0],[(project.absolute_url(),project.WEB_title[0],project.xdata_01[0])])
1.1 dwinter 555:
1.8 dwinter 556: if RESPONSE is not None:
557: RESPONSE.redirect("showHistoricalPersons")
558:
1.13 dwinter 559:
560: def getPersonDict(self,name):
561: """name von dict"""
562:
563: try:
564: return self.personDict[name][0].encode('utf-8')
565: except:
566: return self.personDict[name][0]
567: return self.personDict[name][0].decode('latin-1').encode('utf-8')
568:
1.8 dwinter 569:
570: def showHistoricalPersons(self):
571: """show persons"""
1.45 dwinter 572: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','showHistoricalPersons')).__of__(self)
1.8 dwinter 573: return pt()
574:
575:
576: def editHistoricalPersonsForm(self):
577: """edit historical persons for consistency"""
1.45 dwinter 578: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editHistoricalPersonsForm')).__of__(self)
1.8 dwinter 579: return pt()
580:
1.47.2.19 dwinter 581: def getProjectsByFieldContent(self,fieldName,fieldContentsEntry, date=None):
1.8 dwinter 582: """gib alle Projekte aus mit Value von field mit fieldName enthält ein Element der Liste fieldContents"""
1.47.2.10 dwinter 583: def sort(x,y):
1.47.2.25 dwinter 584: return cmp(x.WEB_title[0],y.WEB_title[0])
1.47.2.10 dwinter 585:
1.47.2.25 dwinter 586: if type(fieldContentsEntry) is StringType:
1.47.2.13 dwinter 587: fieldContentsTmp=[fieldContentsEntry]
1.8 dwinter 588: else:
1.47.2.13 dwinter 589: fieldContentsTmp=fieldContentsEntry
590:
591: fieldContents=[]
592: for x in fieldContentsTmp:
593: fieldContents.append(" AND ".join(x.split()))
594: projects=self.ProjectCatalog({fieldName:string.join(fieldContents,' AND')})
1.8 dwinter 595: #print projects
1.47.2.25 dwinter 596: #ret=[x for x in projects]
1.47.2.19 dwinter 597: ret=[]
598: for x in projects:
599: obj=x.getObject()
600: obj=obj.getActualVersion(date)
601: if obj and (not getattr(obj,'invisible',None)):
602: #if not (x in ret):
603: ret.append(x)
604:
1.47.2.25 dwinter 605: ret.sort(sort)
1.47.2.10 dwinter 606: return ret
1.8 dwinter 607:
608: def changeMPIWGRootForm(self):
609: """edit"""
1.45 dwinter 610: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeMPIWGRootForm')).__of__(self)
1.8 dwinter 611: return pt()
612:
1.45 dwinter 613: def changeMPIWGRoot(self,title,disciplineList,themesList,connection_id,RESPONSE=None):
1.8 dwinter 614: """change"""
615: self.title=title
1.45 dwinter 616: self.connection_id=connection_id
1.8 dwinter 617: self.disciplineList=disciplineList
618: self.themesList=themesList
619:
620: if RESPONSE is not None:
621: RESPONSE.redirect('manage_main')
622:
1.9 dwinter 623: def getDisciplineList(self):
624: """get disciplines as list"""
1.47.2.12 dwinter 625: list= self.disciplineList.split("\n")
626: return [x.rstrip().lstrip() for x in list]
1.9 dwinter 627:
628: def getThemeList(self):
629: """get themes as list"""
1.47.2.12 dwinter 630: list= self.themesList.split("\n")
631: return [x.rstrip().lstrip() for x in list]
1.9 dwinter 632:
1.8 dwinter 633: def test(self):
634: """test"""
635: return self.getProjectsByFieldContent('xdata_09',['biology'])[0].absolute_url
1.9 dwinter 636:
1.47.2.18 dwinter 637: def getContexts(self,childs=None,parents=None,depth=None,date=None):
1.9 dwinter 638: """childs alle childs, alle parents"""
639: ret=[]
1.47.2.20 dwinter 640:
1.9 dwinter 641: if parents:
642: splitted=parents.split(".")
643: parentId=string.join(splitted[0:len(splitted)-1],".")
644:
1.47.2.18 dwinter 645: for project in self.getProjectFields('xdata_05',sort='int',date=date):
1.9 dwinter 646: if project[1]==parentId:
647: ret.append(project)
648:
649: if childs:
1.47.2.18 dwinter 650: for project in self.getProjectFields('xdata_05',sort='int',date=date):
1.9 dwinter 651: searchStr=childs+"(\..*)"
652: if re.match(searchStr,project[1]):
653:
654: if depth:
1.14 dwinter 655:
1.9 dwinter 656: if int(depth)>=len(project[1].split("."))-len(childs.split(".")):
657:
658: ret.append(project)
659: else:
660: ret.append(project)
661: return ret
1.8 dwinter 662:
1.47.2.18 dwinter 663: def getProjectFields(self,fieldName,date=None,folder=None,sort=None):
1.1 dwinter 664: """getListofFieldNames"""
665: ret=[]
1.38 dwinter 666:
1.44 dwinter 667: objects=self.ZopeFind(self.projects,obj_metatypes=['MPIWGProject'],search_sub=0)
1.5 dwinter 668:
1.38 dwinter 669:
670: for object in objects:
671: obj=object[1]
1.47.2.18 dwinter 672: obj=obj.getActualVersion(date)
673: if obj and (not getattr(obj,'invisible',None)):
1.41 dwinter 674: if fieldName=="WEB_title_or_short":
675:
676: if len(obj.getContent('xdata_07'))<3: # hack weil z.Z. manchmal noch ein Trennzeichen ; oder , im Feld statt leer
677: fieldNameTmp="WEB_title"
678: else:
679: fieldNameTmp="xdata_07"
1.38 dwinter 680: else:
1.41 dwinter 681: fieldNameTmp=fieldName
682:
683: ret.append((obj,obj.getContent(fieldNameTmp)))
1.5 dwinter 684:
1.38 dwinter 685:
1.5 dwinter 686: if sort=="int":
687: ret.sort(sortI)
688: else:
689: ret.sort(sortF)
1.1 dwinter 690:
691: return ret
692:
1.5 dwinter 693: def showNewProjects(self):
694: projects=[]
695: for objs in self.getProjectFields('WEB_title_or_short'): # Get all Projets
1.47.2.18 dwinter 696: if objs[0].xdata_05 and (objs[0].xdata_05[0] == ""):
1.5 dwinter 697:
698: projects.append(objs)
699:
700: return projects
701:
702:
1.1 dwinter 703: manage_options = Folder.manage_options+(
1.47.2.30 dwinter 704: {'label':'Update personal homepages','action':'updateHomepages'},
705: {'label':'Reindex catalogs','action':'reindexCatalogs'},
1.8 dwinter 706: {'label':'Main config','action':'changeMPIWGRootForm'},
1.47.2.30 dwinter 707: #{'label':'Edit Historical Persons','action':'editHistoricalPersonsForm'},
708: #{'label':'Store Historical Persons','action':'storeHistoricalPersons'},
1.1 dwinter 709: )
710:
711: def importNamesForm(self):
712: """Form"""
1.45 dwinter 713: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGNamesForm.zpt')).__of__(self)
1.1 dwinter 714: return pt()
715:
716: def importNames(self,fileupload,folderName,RESPONSE=None):
717: """import komma-sep list email,lastName,firstName"""
718: project=getattr(self,folderName)
1.9 dwinter 719: load=fileupload.read()
1.1 dwinter 720:
1.9 dwinter 721: for line in load.split('\r'):
722:
723:
1.1 dwinter 724: splitted=line.split(",")
1.26 dwinter 725: # print splitted
1.9 dwinter 726:
1.1 dwinter 727: if not (splitted[0]==""):
728: newObj=MPIWGStaff.MPIWGStaff(splitted[0],splitted[1],splitted[2])
1.9 dwinter 729:
1.1 dwinter 730: try:
731: project._setObject(splitted[0],newObj)
1.26 dwinter 732: #print "done:",splitted[0]
1.1 dwinter 733: except:
1.46 dwinter 734: zLOG.LOG("MPIWG Web (importNames)",zLOG.INFO,"cannot import: %s"%splitted[0])
735:
1.9 dwinter 736:
1.1 dwinter 737: if RESPONSE is not None:
738: RESPONSE.redirect('manage_main')
739:
1.47.2.26 dwinter 740: def updatePublicationDB(self,personId=None):
741: """updates the publication db, i.e. copy year into the main table"""
742:
743: if personId:
1.47.2.27 dwinter 744: founds = self.ZSQLInlineSearch(_table="publications",id_main=personId)
1.47.2.26 dwinter 745: else:
746: founds = self.ZSQLInlineSearch(_table="publications")
747:
748: for found in founds:
1.47.2.30 dwinter 749:
750: if found.id_institutsbibliographie and (not found.id_institutsbibliographie =="") and (not found.id_institutsbibliographie =="0"):
751:
1.47.2.26 dwinter 752: entries = self.ZSQLInlineSearch(_table="institutsbiblio",id=found.id_institutsbibliographie)
753: for entry in entries:
1.47.2.27 dwinter 754: self.ZSQLChange(_table='publications',_identify='oid=%s' % found.oid,year=entry.year,referencetype=entry.reference_type)
1.47.2.26 dwinter 755:
756: if found.id_gen_bib and (not found.id_gen_bib ==""):
757: entries = self.ZSQLInlineSearch(_table="bibliography",id=found.id_gen_bib)
758: for entry in entries:
1.47.2.27 dwinter 759: self.ZSQLChange(_table='publications',_identify='oid=%s' % found.oid,year=entry.year,referencetype=entry.reference_type)
1.47.2.26 dwinter 760:
761: return True
762:
1.47.2.30 dwinter 763: def updateHomepages(self,RESPONSE=None):
1.47.2.28 dwinter 764: """ update"""
1.47.2.32 dwinter 765: #FIXME: seite wird hinter apache mehrfach ausgefŸhrt
766: RESPONSE.setHeader('Content-type', 'text/html')
1.47.2.28 dwinter 767: RESPONSE.write("<html><body>\n")
768: url="http://itgroup.mpiwg-berlin.mpg.de:8050/FMPro?-db=personal-www&-format=-dso_xml&-lay=sql_export&-max=10000&-findall"
1.47.2.29 dwinter 769: dom = NonvalidatingReader.parseUri(url)
770: #fh=urllib.urlopen(url)
771: #dom=xml.dom.minidom.parse(fh)
1.47.2.30 dwinter 772: RESPONSE.write("got_xml_File\n")
1.47.2.28 dwinter 773:
774:
775: memberFolder=getattr(self,'members')
776: members=memberFolder.ZopeFind(memberFolder,obj_metatypes=["MPIWGStaff"])
777:
778: memberList=[x[0] for x in members]
1.47.2.29 dwinter 779: #print dom
780: #ctx=Context(dom,processorNss={EMPTY_NAMESPACE:'http://www.filemaker.com/fmpdsoresult'})
781: # Evaluate(u".//dn:ROW",contextNode=dom,explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})
782: #print dom.xpath(u'.//dn:ROW',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})
783: for row in dom.xpath(u'.//dn:ROW',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'}):
784:
785: username=getTextFromNode(row.xpath('./dn:username',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
786: id=getTextFromNode(row.xpath('./dn:ID',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
787: name=getTextFromNode(row.xpath('./dn:Name',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
788: vorname=getTextFromNode(row.xpath('./dn:Vorname',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
789: title=getTextFromNode(row.xpath('./dn:Title',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
790: e_mail=getTextFromNode(row.xpath('./dn:e_mail',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
791: e_mail_p=getTextFromNode(row.xpath('./dn:e_mail_p',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
792: date_from=getTextFromNode(row.xpath('./dn:Date_from',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
793: date_to=getTextFromNode(row.xpath('./dn:Date_to',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
794: abteilung=getTextFromNode(row.xpath('./dn:Abteilung',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
795: heimat_inst=getTextFromNode(row.xpath('./dn:heimat_inst',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
796: funded_by=getTextFromNode(row.xpath('./dn:funded_by',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
797: e_mail2=getTextFromNode(row.xpath('./dn:e_mail2',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
798: publish_the_data=getTextFromNode(row.xpath('./dn:publish_the_data',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
1.47.2.28 dwinter 799:
1.47.2.29 dwinter 800: #cwNode=row.xpath('./dn:current_work.current',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0]
801: cw=row.xpath('./dn:current_work/dn:DATA',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})
1.47.2.28 dwinter 802: if cw:
803: txt=getTextFromNode(cw[0])
804: else:
805: txt=""
806:
1.47.2.29 dwinter 807: #cwNode=row.xpath('.//dn:current_work.publish',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0]
808: cw=row.xpath('./dn:current_work/dn:DATA',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})
809:
1.47.2.28 dwinter 810: if cw:
811: txt_p=getTextFromNode(cw[0])
812: else:
813: txt_p=""
814:
815: project=getattr(self,'members')
816:
817: if not (username in memberList):#neuer eintrag
1.47.2.30 dwinter 818:
1.47.2.28 dwinter 819: try:
1.47.2.30 dwinter 820: newObj=MPIWGStaff.MPIWGStaff(str(username),name.encode('utf-8'),vorname.encode('utf-8'))
1.47.2.28 dwinter 821: memberFolder._setObject(str(username),newObj)
822: RESPONSE.write("<p>new:%s</p>\n"%username.encode('utf-8'))
823: obj=getattr(memberFolder,username)
1.47.2.29 dwinter 824: ret=obj.createNewDBEntry(publish_the_data,id,name,
825: vorname,username,title,e_mail,
1.47.2.28 dwinter 826: e_mail_p,date_from,date_to,
827: abteilung,heimat_inst,funded_by,
828: e_mail2,txt,txt_p)
1.47.2.30 dwinter 829: RESPONSE.write("""<p>%s</p>"""%ret[1].encode('utf-8'))
1.47.2.28 dwinter 830: except:
831: RESPONSE.write("<p>ERROR:%s %s %s</p>\n"%(username.encode('utf-8'),name.encode('utf-8'),vorname.encode('utf-8')))
832: RESPONSE.write("<p> : %s %s"%sys.exc_info()[:2])
833: else:
834: RESPONSE.write("<p>update:%s</p>\n"%username.encode('utf-8'))
1.47.2.29 dwinter 835:
836: xquery=".//dn:ROW[dn:username='%s']"%username
837: results=dom.xpath(xquery,explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})
838: if len(results)>1:
839: RESPONSE.write("<p>WARNING (update): username %s not unique</p>\n"%username.encode('utf-8'))
840: xquery=".//dn:ROW[dn:publish_the_data='yes' and dn:username='%s']"%username
841: rd=dom.xpath(xquery,explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})
842: if len(rd)>1:#mehrere published
843: RESPONSE.write("<p>ERROR (update): username %s not unique and more then one date set to be published</p>\n"%username.encode('utf-8'))
844: # elif len(rd)==1:#nur einer published, kein published dann mache nichts
845: # publish_the_data=getTextFromNode(rd[0].xpath('./dn:publish_the_data',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
846: # date_from=getTextFromNode(rd[0].xpath('./dn:Date_from',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
847: # date_to=getTextFromNode(rd[0].xpath('./dn:Date_to',explicitNss={'dn':'http://www.filemaker.com/fmpdsoresult'})[0])
848: #
849:
850: obj=getattr(memberFolder,username)
851:
852: obj.updateDBEntry(DBid=id,publish_the_data=publish_the_data,
1.47.2.28 dwinter 853: date_from=date_from,
854: date_to=date_to)
1.47.2.29 dwinter 855:
1.47.2.30 dwinter 856: self.reindexCatalogs(RESPONSE)
857:
858: self.updatePublicationDB()
859:
1.47.2.31 dwinter 860: RESPONSE.write("<h2>Done</h2></body></html>")
861:
862:
1.47.2.30 dwinter 863:
864: def reindexCatalogs(self,RESPONSE=None):
865: """reindex members and project catalog"""
866:
1.47.2.26 dwinter 867:
1.47.2.30 dwinter 868: try:
869: self.MembersCatalog.manage_catalogReindex(self.REQUEST,RESPONSE,self.REQUEST['URL1'])
870: self.ProjectCatalog.manage_catalogReindex(self.REQUEST,RESPONSE,self.REQUEST['URL1'])
871: except:
872: zLOG.LOG("MPIWG Root (updatehomepage)",zLOG.WARNING," %s %s"%sys.exc_info()[:2])
873:
874:
875:
876:
877: if RESPONSE:
878: RESPONSE.redirect('manage_main')
879:
880:
881:
882: def updateHomepages_old(self,RESPONSE):
883: """lege members an, alte version vollstaendige kopie aller fm-dateien per fm.jar"""
1.36 dwinter 884: self.upDateSQL('personalwww.xml')
1.39 dwinter 885: founds=self.ZSQLInlineSearch(_table='personal_www',publish_the_data='yes')
1.36 dwinter 886: project=getattr(self,'members')
887: for found in founds:
888:
889: if not (found.e_mail==""):
890: newObj=MPIWGStaff.MPIWGStaff(found.username,found.name,found.vorname)
891:
892: try:
893: project._setObject(found.username,newObj)
894: RESPONSE.write("<p>new:%s</p>\n"%found.username)
895: except:
896: RESPONSE.write("<p>old:%s (%s,%s)</p>\n"%(found.username,found.name,found.vorname))
897:
1.47.2.26 dwinter 898:
1.36 dwinter 899:
1.39 dwinter 900: #delete non existing
901:
902:
903: foundUserNames=[x.username for x in founds]
904: for member in self.ZopeFind(self,obj_metatypes=["MPIWGStaff"],search_sub=1):
905:
906: if member[1].getId() not in foundUserNames:
907: member[1].aq_parent.manage_delObjects(ids=[member[1].getId()])
908: RESPONSE.write("<p>deleted:%s</p>\n"%member[1].getId())
1.45 dwinter 909: try:
910: self.MembersCatalog.manage_catalogReindex(self.REQUEST,RESPONSE,self.REQUEST['URL1'])
911: except:
912: pass
913: self.ProjectCatalog.manage_catalogReindex(self.REQUEST,RESPONSE,self.REQUEST['URL1'])
1.39 dwinter 914:
1.47.2.26 dwinter 915: self.updatePublicationDB()
916:
1.36 dwinter 917: if RESPONSE is not None:
918: RESPONSE.redirect('manage_main')
919:
920:
1.3 dwinter 921: def getAllMembers(self):
922: """give list of all members"""
923: ret=[]
924:
1.9 dwinter 925: #for x in self.members.objectValues('MPIWGStaff'):
1.4 dwinter 926: #print x.title
1.9 dwinter 927: # ret.append(x.title.decode('utf-8'))
928:
929: for x in self.ZopeFind(self.members,obj_metatypes=['MPIWGStaff']):
1.47.2.30 dwinter 930: if x[1].isPublished():
1.9 dwinter 931: ret.append(x[1].title.decode('utf-8'))
1.3 dwinter 932:
1.18 dwinter 933: ret.sort()
1.9 dwinter 934: #print ret
935:
1.3 dwinter 936: return ret
937:
1.9 dwinter 938: def printAllMembers(self):
939: """prin"""
940: members=self.getAllMembers()
941: ret=""
942: for x in members:
943: ret+="<p>%s</p>"%x
944: return ret
945:
946:
1.5 dwinter 947: def makeList(self,entry):
948: """makes a list out of one entry or repeat a list"""
949: if type(entry) is StringType:
950: return [entry]
951: else:
952: return entry
953:
954:
1.47.2.18 dwinter 955: def getTree(self,date=None):
1.5 dwinter 956: """generate Tree from project list"""
1.47.2.20 dwinter 957:
1.5 dwinter 958: returnList=[]
1.47.2.18 dwinter 959: for project in self.getProjectFields('xdata_05',sort="int",date=date): # get Projects sorted by xdata_05
1.41 dwinter 960:
1.5 dwinter 961: for idNr in project[1].split(";"): # more than one number
962: if not idNr=="":
963: splittedId=idNr.split(".")
964: depth=len(splittedId)
965: nr=idNr
1.14 dwinter 966: #title=project[0].WEB_title
967: title=[project[0].getContent('WEB_title')]
968: #print title
1.47.2.25 dwinter 969: if idNr[0]!="x":
1.47.2.11 dwinter 970: returnList.append((depth,nr,title,project[0]))
1.5 dwinter 971:
972: return returnList
973:
1.47.2.3 dwinter 974: def formatElementsAsList(self,elements):
975: """formatiere tree als liste"""
976:
977: actualDepth=0
978: ret=""
979: for element in elements:
980: if (element[0]>actualDepth):
981: #fuege soviele ul ein wie unterschied in tiefe
982: if element[0]==1:
1.47.2.10 dwinter 983: ret+="""<div class="dept">\n<ul class="liste">\n"""
1.47.2.3 dwinter 984: else:
985: for i in range(element[0]-actualDepth):
1.47.2.12 dwinter 986: if i>0:
987: ret+="<li>"
1.47.2.10 dwinter 988: ret+="""<ul class="liste">\n"""
1.47.2.12 dwinter 989:
1.47.2.3 dwinter 990: actualDepth=element[0]
991:
992: elif (element[0]<actualDepth):
993: #fuege soviele /ul ein wie unterschied in tiefe
994: for i in range(-element[0]+actualDepth):
1.47.2.12 dwinter 995:
996: ret+="<br><br></li></ul>\n"
997:
998: #ret+="<br><br>\n</li>\n</ul>\n</li>\n"
999:
1.33 casties 1000:
1.47.2.3 dwinter 1001: if element[0]==1:
1002: department=int(element[3].getContent('xdata_05'))-1
1003:
1.47.2.10 dwinter 1004: ret+="""</ul></div>\n"""
1.47.2.25 dwinter 1005: if department==4: #hack
1006: department=3
1.47.2.11 dwinter 1007:
1.47.2.3 dwinter 1008: ret+="""<div class="bildspalte"><img src="../grafik/dept%i.jpg" width="160" height="120" vspace="40"></div>
1.47.2.10 dwinter 1009: <div class="dept">\n<ul class="liste">\n
1.47.2.3 dwinter 1010: """%department
1011:
1012: actualDepth=element[0]
1013: else:
1.47.2.10 dwinter 1014: ret+="""\n</li>\n"""
1.47.2.3 dwinter 1015: ret+="""<li>\n"""
1016:
1017: if actualDepth==1:
1.47.2.12 dwinter 1018: departmentName={'1':'Department I','2':'Department II','3':'Department III', '4':'Ind. Research Group','5':'Ind. Research Group'}
1.47.2.3 dwinter 1019: department=element[3].getContent('xdata_05')
1.47.2.10 dwinter 1020: ret+="""<a href="#top"><img src="../grafik/totop.gif" vspace="10" border="0"></a><br><a name="dept%s"></a>%s: """%(department,departmentName[department])
1.47.2.3 dwinter 1021:
1.47.2.18 dwinter 1022: if self.REQUEST.has_key('date'):
1023: ret+="""<a href="%s?date=%s">%s</a>"""%(self.generateUrlProject(element[3].absolute_url())+"/index.html",self.REQUEST['date'],element[3].getContent('WEB_title'))
1024: else:
1025: ret+="""<a href="%s">%s</a>"""%(self.generateUrlProject(element[3].absolute_url())+"/index.html",element[3].getContent('WEB_title'))
1.47.2.3 dwinter 1026: return ret
1027:
1.16 dwinter 1028: def formatElementForOverview(self,element):
1029: """format the element for output in overview"""
1030: if element[0]==1: #department
1.26 dwinter 1031: #print element[3].getContent('xdata_05')
1.23 dwinter 1032: if element[3].getContent('xdata_05') == "4":
1.33 casties 1033: return """<h2 class="hier"><a href="%s">Ind. Research Group I: %s</a></h2>"""%(element[3].absolute_url()+"/index.html",element[3].getContent('WEB_title'))
1.25 dwinter 1034: if element[3].getContent('xdata_05') == "5":
1.33 casties 1035: return """<h2 class="hier"><a href="%s">Ind. Research Group II: %s</a></h2>"""%(element[3].absolute_url()+"/index.html",element[3].getContent('WEB_title'))
1.23 dwinter 1036:
1.33 casties 1037: return """<h2 class="hier"><a href="%s">Department %s: %s</a></h2>"""%(element[3].absolute_url()+"/index.html",element[3].getContent('xdata_05'),element[3].getContent('WEB_title'))
1.16 dwinter 1038:
1039: elif element[0]==2: #mainprojects
1.33 casties 1040: return """<h3 class="hier"><a href="%s">%s</a></h3><p>"""%(element[3].absolute_url()+"/index.html",element[3].getContent('WEB_title'))
1.16 dwinter 1041:
1042: elif element[0]==3:
1.33 casties 1043: return """<p class="hier"><a href="%s">%s</a></p>"""%(element[3].absolute_url()+"/index.html",element[3].getContent('WEB_title'))
1044:
1.16 dwinter 1045:
1.5 dwinter 1046: def changePosition(self,treeId,select,RESPONSE=None):
1047: """Change Postion Entry"""
1048: numbers=[]
1049:
1050: # Suche hoechste bisherige nummer
1051: projects=self.getProjectFields('xdata_05') # get Projects sorted by xdata_05
1.8 dwinter 1052: #print "pj",projects
1.5 dwinter 1053: for project in projects: #suche alle subtrees der treeId
1054: #print treeId
1055:
1056: founds=re.match(treeId+"\.(.*)",project[1].split(";")[0])
1057: if founds:
1058: #print "x",founds.group(0),len(founds.group(0).split("."))
1059: if len(founds.group(0).split("."))==len(treeId.split("."))+1: # nur ein punkt mehr, d.h. untere ebene
1060: try:
1061: numbers.append(int(founds.group(0).split(".")[len(founds.group(0).split("."))-1]))
1062: except:
1.6 dwinter 1063: numbers.append(int(0))
1064:
1065: try:
1066: highest=max(numbers)
1067: except:
1068: highest=0
1.5 dwinter 1069: projects=self.showNewProjects()
1070: for i in self.makeList(select):
1071: highest+=10
1072: projects[int(i)][0].xdata_05=treeId+"."+str(highest)
1073:
1074:
1075: if RESPONSE is not None:
1076: RESPONSE.redirect('showTree')
1077:
1078: def changeTree(self,RESPONSE=None):
1079: """change the complete tree"""
1080: form=self.REQUEST.form
1081: hashList={}
1082: fields=self.getTree()
1083:
1084:
1085: for idNr in form.keys():
1.47.2.18 dwinter 1086: if not (fields[int(idNr)][3].xdata_05==form[idNr]):
1087: fields[int(idNr)][3].xdata_05=form[idNr]
1088: fields[int(idNr)][3].copyObjectToArchive()
1.5 dwinter 1089:
1090:
1091: if RESPONSE is not None:
1092: RESPONSE.redirect('showTree')
1093:
1094: def getProjectWithId(self,id):
1095: fields=self.getProjectFields('xdata_05')
1096: for field in fields:
1097: if field[1]==id:
1098: return field[0]
1099:
1100: return None
1101:
1102:
1103:
1104:
1.15 dwinter 1105: def getRelativeUrlFromPerson(self,list):
1106: """get urls to person list"""
1107: ret=[]
1108: persons=list.split(";")
1109: for person in persons:
1110:
1111: if len(person)>1: #nicht nur Trennzeichen
1112: splitted=person.split(",")
1113: if len(splitted)==1:
1114: splitted=person.split(" ")
1115: splittedNew=[re.sub(r'\s(.*)','$1',split) for split in splitted]
1116: if splittedNew[0]=='':
1117: del splittedNew[0]
1118: search=string.join(splittedNew,' AND ')
1119:
1120: if not search=='':
1121:
1122: try:
1123: proj=self.MembersCatalog({'title':search})
1124: except:
1125: proj=None
1126:
1127: if proj:
1128: #ret.append("<a href=%s >%s</a>"%(proj[0].absolute_url,person.encode('utf-8')))
1.29 dwinter 1129: ret.append("<a href=%s >%s</a>"%('members/'+proj[0].id+'/index.html',person))
1.15 dwinter 1130: else:
1131: #ret.append("%s"%person.encode('utf-8'))
1132: ret.append("%s"%person)
1133: return string.join(ret,";")
1.5 dwinter 1134:
1135:
1.3 dwinter 1136: def getUrlFromPerson(self,list):
1137: """get urls to person list"""
1138: ret=[]
1139: persons=list.split(";")
1140: for person in persons:
1141:
1.9 dwinter 1142: if len(person)>1: #nicht nur Trennzeichen
1143: splitted=person.split(",")
1144: if len(splitted)==1:
1.26 dwinter 1145: splitted=person.lstrip().rstrip().split(" ")
1.9 dwinter 1146: splittedNew=[re.sub(r'\s(.*)','$1',split) for split in splitted]
1147: if splittedNew[0]=='':
1148: del splittedNew[0]
1149: search=string.join(splittedNew,' AND ')
1.4 dwinter 1150:
1.9 dwinter 1151: if not search=='':
1152:
1153: try:
1154: proj=self.MembersCatalog({'title':search})
1155: except:
1156: proj=None
1157:
1.47.2.30 dwinter 1158: if proj and (proj[0].getObject().isPublished()):
1.47.2.25 dwinter 1159: if person =="Otto Sibum" : person="H. Otto Sibum"
1160: if person =="Norton Wise" : person="M. Norton Wise"
1.12 dwinter 1161: #ret.append("<a href=%s >%s</a>"%(proj[0].absolute_url,person.encode('utf-8')))
1.29 dwinter 1162: ret.append("<a href=%s >%s</a>"%(proj[0].absolute_url+"/index.html",person))
1.9 dwinter 1163: else:
1.12 dwinter 1164: #ret.append("%s"%person.encode('utf-8'))
1.9 dwinter 1165: ret.append("%s"%person)
1.3 dwinter 1166: return string.join(ret,";")
1167:
1.47.2.18 dwinter 1168: def getProjectsOfMembers(self,date=None):
1.3 dwinter 1169: """give tuple member /projects"""
1170: ret=[]
1171: members=self.getAllMembers()
1.9 dwinter 1172: #return str(members)
1.3 dwinter 1173: for x in members:
1.47.2.18 dwinter 1174: ret+=self.getProjectsOfMember(name=x,date=date)
1.18 dwinter 1175:
1.3 dwinter 1176: return ret
1.11 dwinter 1177:
1.47.2.18 dwinter 1178: def getProjectsOfMember(self,name=None,email=None,date=None):
1.11 dwinter 1179: """get project of a member"""
1180: def sortP(x,y):
1181: """sort by sorting number"""
1.18 dwinter 1182: #print x.xdata_05,y.xdata_05
1183: return cmp(x.WEB_title,y.WEB_title)
1.11 dwinter 1184:
1.18 dwinter 1185:
1.11 dwinter 1186: ret=[]
1187: splitNeu=[]
1188: if email:
1.47.2.15 dwinter 1189:
1.47.2.2 dwinter 1190: members=self.ZopeFind(self.members,obj_metatypes=['MPIWGStaff'],obj_ids=[email],search_sub=1)
1.11 dwinter 1191: name = members[0][1].title.decode('utf-8')
1192:
1193: y=name
1.28 dwinter 1194: splitted=y.split(",")
1195: #XXXX
1196: splitNeu=["\'"+splitted[1]+" "+splitted[0]+"\'"]
1197:
1198: #for s in splitted:
1199: # splitNeu.append("\""+s+"\"")
1.11 dwinter 1200: search=string.join(splitNeu,' AND ')
1.28 dwinter 1201:
1.11 dwinter 1202: proj=self.ProjectCatalog({'xdata_01':search})
1.28 dwinter 1203:
1.11 dwinter 1204: if proj:
1.28 dwinter 1205: proj2=[]
1206: for x in proj:
1.47.2.18 dwinter 1207: if (not getattr(x.getObject(),'invisible',None)) and (getattr(x.getObject(),'archiveTime','')==''):
1.41 dwinter 1208: if not((splitted[1]==" Christoph") and (splitted[0]=="Hoffmann") and (str(x.WEB_title).find('Einstein')>0)):
1.28 dwinter 1209: proj2.append(x)
1.41 dwinter 1210:
1.18 dwinter 1211: else:
1212: proj2=[]
1213:
1.11 dwinter 1214: proj=self.ProjectCatalog({'xdata_08':search})
1215: if proj:
1.18 dwinter 1216: names=[x.WEB_title for x in proj]
1217: for x in proj:
1.47.2.18 dwinter 1218:
1219: if (not x.WEB_title in names) and (getattr(x.getObject(),'archiveTime','')==''):
1.18 dwinter 1220: proj2.append(x)
1221:
1222:
1223: proj2.sort(sortP)
1224:
1225: if len(proj2)>0:
1.11 dwinter 1226: ret.append((y,proj2))
1227:
1228: return ret
1229:
1.1 dwinter 1230: def givePersonList(self,name):
1231: """check if person is in personfolder and return list of person objects"""
1.3 dwinter 1232:
1233: splitted=name.split(",")
1234: if len(splitted)==1:
1.26 dwinter 1235: splitted=name.lstrip().rstrip().split(" ")
1236: splittedNew=[split.lstrip() for split in splitted]
1237:
1.3 dwinter 1238: if splittedNew[0]=='':
1239: del splittedNew[0]
1240: search=string.join(splittedNew,' AND ')
1241: if not search=='':
1242: proj=self.MembersCatalog({'title':search})
1243:
1244: if proj:
1245: return [[x.lastName,x.firstName] for x in proj]
1246: else:
1247: return []
1248:
1249: ## splitted=name.split(",") # version nachname, vorname...
1250: ## if len(splitted)>1:
1251: ## lastName=splitted[0]
1252: ## firstName=splitted[1]
1253: ## else:
1254: ## splitted=name.split(" ") #version vorname irgenwas nachnamae
1255:
1256: ## lastName=splitted[len(splitted)-1]
1257: ## firstName=string.join(splitted[0:len(splitted)-1])
1258:
1259: ## objs=[]
1.1 dwinter 1260:
1.3 dwinter 1261: #print self.members
1262: ## for x in self.members.__dict__:
1263: ## obj=getattr(self.members,x)
1264: ## if hasattr(obj,'lastName') and hasattr(obj,'firstName'):
1.1 dwinter 1265:
1.3 dwinter 1266: ## if (re.match(".*"+obj.lastName+".*",lastName) or re.match(".*"+lastName+".*",obj.lastName)) and (re.match(".*"+obj.firstName+".*",firstName) or re.match(".*"+firstName+".*",obj.firstName)):
1.1 dwinter 1267:
1.3 dwinter 1268: ## objs.append((obj,lastName+", "+firstName))
1.1 dwinter 1269:
1.3 dwinter 1270:
1.1 dwinter 1271: return objs
1272:
1273:
1274: def personCheck(self,names):
1275: """all persons for list"""
1.4 dwinter 1276: #print "names",names
1.1 dwinter 1277: splitted=names.split(";")
1278: ret={}
1279: for name in splitted:
1280:
1281: if not (name==""):
1.3 dwinter 1282: try:
1283: ret[name]=self.givePersonList(name)
1284: except:
1285: """NOTHIHN"""
1.4 dwinter 1286: #print "RET",ret
1.1 dwinter 1287: return ret
1288:
1289: def giveCheckList(self,person,fieldname):
1290: """return checklist"""
1291: #print "GCL",fieldname
1292: if fieldname=='xdata_01':
1293: x=self.personCheck(person.getContent(fieldname))
1.4 dwinter 1294: #print "GCLBACKX",x
1.1 dwinter 1295: return x
1296:
1297:
1298: def isCheckField(self,fieldname):
1299: """return chechfield"""
1300:
1301: return (fieldname in checkFields)
1302:
1303:
1304: def manage_addMPIWGRootForm(self):
1305: """form for adding the root"""
1.45 dwinter 1306: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMPIWGRootForm.zpt')).__of__(self)
1.1 dwinter 1307: return pt()
1308:
1.45 dwinter 1309: def manage_addMPIWGRoot(self,id,title,connection_id="",RESPONSE=None):
1.1 dwinter 1310: """add a root folder"""
1311: newObj=MPIWGRoot(id,title)
1312: self._setObject(id,newObj)
1.45 dwinter 1313: ob=getattr(self,id)
1314: setattr(ob,'connection_id',connection_id)
1.1 dwinter 1315: if RESPONSE is not None:
1316: RESPONSE.redirect('manage_main')
1317:
1318:
1.47.2.22 dwinter 1319: class MPIWGProject_publication(SimpleItem):
1320: """publications object fuer project"""
1321:
1322: meta_type="MPIWGProject_publication"
1323:
1324: def editPublication(self,text=None,RESPONSE=None):
1325: """edit a publication"""
1326:
1327: if (not text):
1328: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_publicationForm.zpt')).__of__(self)
1329: return pt()
1330:
1331:
1332: self.text=text[0:]
1333:
1334: if RESPONSE:
1335: RESPONSE.redirect("../managePublications")
1336:
1337: class MPIWGProject_image(Image):
1338: """Images for Projects"""
1339:
1340: meta_type="MPIWGProject_image"
1341:
1342: def showImage(self,imageUrl=None):
1343: """show Images at an extra page"""
1344: self.getContent('WEB_project_description',filter='yes') #get the content and store image infos into session
1345: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','projectImageView.zpt')).__of__(self)
1346: return pt()
1347:
1348: def editImage(self,file=None,caption=None,RESPONSE=None):
1349: """edit the Image"""
1350: if (not file) and (not caption):
1351: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_imageForm.zpt')).__of__(self)
1352: return pt()
1353:
1354: if file and (not file.filename.lstrip().rstrip()==""):
1355: self.manage_upload(file)
1356:
1357: if caption:
1358: self.caption=caption[0:]
1359:
1360: if RESPONSE:
1361: RESPONSE.redirect("../manageImages")
1362:
1.45 dwinter 1363: class MPIWGProject(CatalogAware,Folder):
1.1 dwinter 1364: """Class for Projects"""
1.47.2.22 dwinter 1365:
1366:
1.47.2.21 dwinter 1367: security=ClassSecurityInfo()
1.1 dwinter 1368: meta_type='MPIWGProject'
1.45 dwinter 1369: default_catalog='ProjectCatalog'
1.47.2.22 dwinter 1370:
1371: def sortedByPlace(self,metatype):
1372: """find metatype and sort by place"""
1373: def sort(x,y):
1374: return cmp(getattr(x[1],'place',0),getattr(y[1],'place',0))
1375:
1376: founds=self.ZopeFind(self,obj_metatypes=[metatype]);
1377:
1378: founds.sort(sort)
1379:
1380: return founds
1.45 dwinter 1381:
1.47.2.22 dwinter 1382:
1383: def copyPublicationsToList(self,RESPONSE=None):
1384: """copy publications in to list"""
1385:
1386: publicationTxt=self.getContent('WEB_related_pub')
1387:
1388: pubSplits=publicationTxt.split("<p>")
1389:
1390: for pubSplit in pubSplits:
1391: pubSplit=pubSplit.replace("</p>","")
1392: self.addPublication(pubSplit)
1393:
1394: if RESPONSE:
1395: RESPONSE.redirect('managePublications')
1396:
1397:
1398: def copyImageToMargin(self,RESPONSE=None):
1.47.2.34 dwinter 1399: #TODO: copy more than one image
1.47.2.22 dwinter 1400: """copy inline images to marginal images"""
1401: self.getContent('WEB_project_description',filter='yes')
1402:
1403: filename=self.imageURL.split("/")[-1]
1404: #lege neues images object an, mit leerem bild
1405:
1406: if self.ZopeFind(self,obj_ids=[filename]):
1407: #existiert das bild schon, dann neueun filenamen
1408: filename="project_image_"+filename
1409:
1410: self.addImage(None,self.imagecap,filename=filename)
1411: #hole die bilddaten aus der url
1.47.2.34 dwinter 1412: url=self.absolute_url()+"/"+self.imageURL
1413: #url=self.absolute_url()+"/"+filename
1414:
1415: try:#relative url
1416: data=urllib.urlopen(url).read()
1417: except:
1418: try:#absolute
1419: data=urllib.urlopen(self.imageURL).read()
1420: except:
1421: zLOG.LOG("MPIWG Project",zLOG.ERROR,"can't open: %s"%url)
1422:
1.47.2.22 dwinter 1423: obj=getattr(self,filename)
1424: obj.update_data(data)
1425:
1426: if RESPONSE:
1427: RESPONSE.redirect('manageImages')
1428:
1429: def manageImages(self,imageName=None,op=None):
1430: """managage images"""
1431:
1432:
1433: if imageName and op:
1434: if op=='up':
1435: images=self.getImages()
1436: for image in images:
1437: if image[0]==imageName:
1438: nr=images.index(image)
1439: if not nr==0:
1440: images[nr-1][1].place+=1
1441: images[nr][1].place-=1
1442: pass
1443: elif op=='down':
1444: images=self.getImages()
1445: for image in images:
1446: if image[0]==imageName:
1447: nr=images.index(image)
1448: if not (nr==len(images)-1):
1449: images[nr+1][1].place-=1
1450: images[nr][1].place+=1
1451: pass
1452:
1453:
1454: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGProject_manageImagesForm.zpt')).__of__(self)
1455: return pt()
1456:
1457: def managePublications(self,pubName=None,op=None):
1458: """managage images"""
1459:
1460:
1461: if pubName and op:
1462: if op=='up':
1463: publications=self.getPublications()
1464: for publication in publications:
1465: if publication[0]==pubName:
1466: nr=publications.index(publication)
1467: if not nr==0:
1468: publications[nr-1][1].place+=1
1469: publications[nr][1].place-=1
1470: pass
1471: elif op=='down':
1472: publications=self.getPublications()
1473: for publication in publications:
1474: if publication[0]==pubName:
1475: nr=publications.index(publication)
1476: if not (nr==len(publications)-1):
1477: publications[nr+1][1].place-=1
1478: publications[nr][1].place+=1
1479: pass
1480:
1481:
1482: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGProject_managePublicationsForm.zpt')).__of__(self)
1483: return pt()
1484:
1485: def getPublications(self):
1486: """get all Publications"""
1487: def sort_images(x,y):
1488: return cmp(getattr(x[1],'place',0),getattr(y[1],'place',0))
1.47.2.25 dwinter 1489:
1.47.2.22 dwinter 1490: publications=self.ZopeFind(self,obj_metatypes=['MPIWGProject_publication'])
1491:
1492: publications.sort(sort_images)
1493: return publications
1494:
1495: def addPublication(self,text,RESPONSE=None):
1496: """add an MPIWG_Publication"""
1497:
1498: name="publication_"+str(self.getLastPublicationNumber()+1)
1499:
1500: newPublication=MPIWGProject_publication(name)
1501:
1502: self._setObject(name,newPublication)
1503: obj=getattr(self,name)
1504: obj.text=text[0:]
1505: obj.enabled=True;
1506: obj.place=self.getLastPublicationNumber()+1
1507: obj.id=name
1508:
1509: if RESPONSE is not None:
1510: RESPONSE.redirect('managePublications')
1511:
1512:
1513: def getLastPublicationNumber(self):
1514: publications=self.getPublications()
1515:
1516: if not publications:
1517: return 0
1518: else:
1519: return getattr(publications[-1][1],'place',0)
1520:
1521: def deletePublication(self,id,RESPONSE=None):
1522: """delete Publication id"""
1523: self.manage_delObjects([id])
1524: if RESPONSE:
1525: RESPONSE.redirect('managePublications')
1526:
1527: def getImages(self):
1528: """get all Images"""
1529: def sort_images(x,y):
1530: return cmp(getattr(x[1],'place',0),getattr(y[1],'place',0))
1.47.2.25 dwinter 1531:
1.47.2.22 dwinter 1532: images=self.ZopeFind(self,obj_metatypes=['MPIWGProject_image'])
1533:
1534: images.sort(sort_images)
1535: return images
1536:
1537: def getLastImageNumber(self):
1538: images=self.getImages()
1539:
1540: if not images:
1541: return 0
1542: else:
1543: return getattr(images[-1][1],'place',0)
1544:
1545: def deleteImage(self,id,RESPONSE=None):
1546: """delete Image id"""
1547: self.manage_delObjects([id])
1548: if RESPONSE:
1549: RESPONSE.redirect('manageImages')
1550:
1551: def addImage(self,fileHd,caption,RESPONSE=None,filename=None):
1552: """add an MPIWG_Project_image"""
1553:
1554: if not filename:
1555: filename=fileHd.filename
1556:
1557: if not fileHd:
1558: fileHd=file(os.path.join(package_home(globals()),'blank.gif'))
1559:
1560: newImage=MPIWGProject_image(filename,filename,fileHd)
1561:
1562: self._setObject(filename,newImage)
1563: obj=getattr(self,filename)
1564: obj.caption=caption[0:]
1565: obj.enabled=True;
1566: obj.place=self.getLastImageNumber()+1
1567:
1568: if RESPONSE is not None:
1569: RESPONSE.redirect('manageImages')
1570:
1.45 dwinter 1571: def PrincipiaSearchSource(self):
1572: """Return cataloguable key for ourselves."""
1573: return str(self)
1.42 dwinter 1574:
1575: def versionHeader(self):
1576: """version Header, gibt header text entsprechend der aktuellen version aus"""
1577:
1578: actualTime=time.localtime()
1579: retTXT="""<h2>This is an outdated version, for the actual version please refer to <a href="%s">%s</a></h2>"""
1580: s=self.aq_parent.absolute_url()
1.43 dwinter 1581: #print getattr(self,'archiveTime',actualTime)
1.42 dwinter 1582: if getattr(self,'archiveTime',actualTime)< actualTime:
1583: return retTXT%(s,s)
1584: else:
1585: return ""
1.47.2.18 dwinter 1586:
1587: def getActualVersion(self,date=None):
1588: """actuelle version"""
1589: def sortProjectsByTime(x,y):
1590: return cmp(x[1].archiveTime,y[1].archiveTime)
1591:
1592: if not date:
1593: if self.isActual():
1594: return self
1595: else:
1596: return None
1597:
1598: #suche ob aeltere versionen vorhanden sind
1599:
1600: finds=self.ZopeFind(self,obj_metatypes=['MPIWGProject'])
1601: if not finds: #wenn nicht dann teste ob die aktuelle version schon existiert hat.
1602: ad=getattr(self,'creationTime','20050101000000')
1603: if int(date)>int(ad):
1604: return self
1605: else:
1606: return None
1607:
1608:
1609: else:
1610: finds.sort(sortProjectsByTime)
1611:
1612: for find in finds:
1613: #gehe durch die alten Projekte und finde das entprechende
1614: if (int(find[1].archiveTime) > int(date)) and (int(date)>int(getattr(find[1],'creationTime','20050101000000'))):
1615: return find[1]
1616:
1617: #kein passendes gefunden, dann teste ob das aktuelle in frage kommt
1618: ad=getattr(self,'creationTime','20050101000000')
1619:
1620: if int(date)>int(ad):
1621:
1622: return self
1623: else:
1624: return None
1625:
1626:
1.43 dwinter 1627: def isActual(self):
1628: """gibt 1 zurueck wenn aktuell, 0 sonst"""
1629: actualTime=time.localtime()
1630:
1631:
1632: #print getattr(self,'archiveTime',actualTime)
1633: if getattr(self,'archiveTime',actualTime)< actualTime:
1634: return 0
1635: else:
1636: return 1
1.42 dwinter 1637:
1638: def copyObjectToArchive(self):
1639: """kopiere aktuelles objekt ins archiv"""
1640: cb=self.aq_parent.manage_copyObjects(self.getId())
1641: self.manage_pasteObjects(cb)
1642: actualTime=time.localtime()
1643:
1644: self.manage_renameObject(self.getId(),self.getId()+"_"+time.strftime("%Y%m%d%H%M%S",actualTime))
1645: obj=getattr(self,self.getId()+"_"+time.strftime("%Y%m%d%H%M%S",actualTime))
1646: obj.setArchiveTime(time.strftime("%Y%m%d%H%M%S",actualTime))
1647: ids=[x[0] for x in self.ZopeFind(obj,obj_metatypes=['MPIWGProject'])]
1648: obj.manage_delObjects(ids)
1649:
1650: def setArchiveTime(self,time):
1651: """set Archive Time"""
1652: self.archiveTime=time[0:]
1653:
1.41 dwinter 1654: def versionManageForm(self):
1655: """version Manage form:currently only set to invisible"""
1656: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGProject_versionManageForm.zpt')).__of__(self)
1657: return pt()
1658:
1659: def versionManage(self,invisible=None,RESPONSE=None):
1660: """version Manage form:currently only set to invisible"""
1661: self.invisible=invisible
1662:
1663: if RESPONSE is not None:
1664: RESPONSE.redirect('manage_main')
1665:
1.38 dwinter 1666:
1.3 dwinter 1667: def crossLinker(self):
1668: """experimental crosslinker"""
1669: splitted=self.WEB_project_description[0].split()
1670: new=[]
1671: for split in splitted:
1672: try:
1673: found=self.DescriptionCatalog({'fulltext':split})
1674:
1675: if len(found)>1:
1676:
1677: new.append("<a href=%s>%s</a>"%(split,split))
1678: else:
1679: new.append(split)
1680: except:
1681: new.append(split)
1682: return string.join(new)
1683:
1684:
1685:
1.1 dwinter 1686:
1687: def generateTemplate(self,RESPONSE=None):
1688: """Erzeuge Template für defined fields not_used"""
1689:
1690: id="index_html"
1691: title=id
1692: if self._getOb('index_html'):
1693: self._delObject('index_html')
1694:
1695:
1696: newObj=ZopePageTemplate(id,'TEXT')
1697: self._setObject(id,newObj)
1698: #self.manage_addPageTemplate(id,title)
1699: if RESPONSE is not None:
1700: RESPONSE.redirect('manage_main')
1701:
1.5 dwinter 1702: def __init__(self, id, argv=None):
1.47.2.18 dwinter 1703: """initiere classe"""
1704:
1705: self.creationTime=time.strftime("%Y%m%d%H%M%S",time.localtime())[0:]
1.1 dwinter 1706: self.id=id
1707: self.title=id
1.5 dwinter 1708: if argv:
1709: for arg in definedFields:
1.47.2.25 dwinter 1710: try:
1711: setattr(self,arg,argv[arg])
1712: except:
1713: setattr(self,arg,"")
1.5 dwinter 1714: else:
1715: for arg in definedFields:
1716: setattr(self,arg,'')
1.1 dwinter 1717:
1718: manage_options = Folder.manage_options+(
1719: {'label':'Load New File','action':'loadNewFileForm'},
1720: {'label':'Edit ProjectInfo','action':'editMPIWGProjectForm'},
1721: {'label':'Edit BasisInfo','action':'editMPIWGBasisForm'},
1722: {'label':'Edit Publications','action':'editMPIWGRelatedPublicationsForm'},
1.9 dwinter 1723: {'label':'Edit Themes & Disciplines','action':'editMPIWGDisciplinesThemesForm'},
1.41 dwinter 1724: {'label':'Versionmanager','action':'versionManageForm'},
1.1 dwinter 1725: )
1.33 casties 1726:
1727:
1.42 dwinter 1728: def checkDate(self,date):
1729: """teste ob zum Zeitpunkt date eine andere version existierte"""
1730:
1731:
1732: def sortProjectsByTime(x,y):
1733: return cmp(x[1].archiveTime,y[1].archiveTime)
1.47.2.18 dwinter 1734:
1735: #suche ob aeltere versionen vorhanden sind
1736:
1.42 dwinter 1737: finds=self.ZopeFind(self,obj_metatypes=['MPIWGProject'])
1.47.2.18 dwinter 1738: if not finds: #wenn nicht dann teste ob die aktuelle version schon existiert hat.
1739: ad=getattr(self,'creationTime','20050101000000')
1740: if int(date)>int(ad):
1741: return self.REQUEST['URL1']+"/"+self.getId()
1742: else:
1743: return self.REQUEST['URL1']+"/no_project"
1744:
1745:
1.42 dwinter 1746: else:
1747: finds.sort(sortProjectsByTime)
1748:
1749: for find in finds:
1.47.2.18 dwinter 1750: #gehe durch die alten Projekte und finde das entprechende
1751: if (int(find[1].archiveTime) > int(date)) and (int(date)>int(getattr(find[1],'creationTime','20050101000000'))):
1752: return self.REQUEST['URL1']+"/"+find[1].getId()
1.42 dwinter 1753:
1.47.2.18 dwinter 1754: #kein passendes gefunden, dann teste ob das aktuelle in frage kommt
1755: ad=getattr(self,'creationTime','20050101000000')
1756:
1757: if int(date)>int(ad):
1758:
1759: return self.REQUEST['URL1']+"/"+self.getId()
1760: else:
1761: return self.REQUEST['URL1']+"/no_project"
1.42 dwinter 1762:
1763:
1.47.2.18 dwinter 1764: def no_project(self):
1765: """warnung: project noch nicht existent"""
1766: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','no_project')).__of__(self)
1767: return pt()
1768:
1.47.2.20 dwinter 1769: def index_html(self,request=True,context=None):
1.33 casties 1770: """show homepage"""
1.47.2.20 dwinter 1771: if not context:
1772: context=self
1773: if request:
1774: if self.REQUEST.has_key('date') and self.REQUEST.SESSION.get('MPI_redirected',None)==None:
1775: self.REQUEST.SESSION['MPI_redirected']=1
1776: self.REQUEST.RESPONSE.redirect(self.checkDate(self.REQUEST['date'])+"?date="+self.REQUEST['date'])
1777: else:
1778: self.REQUEST.SESSION['MPI_redirected']=None
1.42 dwinter 1779:
1.47.2.25 dwinter 1780: #ext=self.ZopeFind(self.aq_parent,obj_ids=["project_main"])
1.47.2.18 dwinter 1781: ext=getattr(self,"project_main",None)
1.33 casties 1782: if ext:
1.47.2.18 dwinter 1783: return getattr(self,ext.getId())()
1.33 casties 1784:
1.47.2.20 dwinter 1785: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','project_main')).__of__(context)
1786:
1.33 casties 1787: return pt()
1.1 dwinter 1788:
1.38 dwinter 1789:
1.1 dwinter 1790: def getDataFields(self):
1791: """giveListofDatafields"""
1792: ret=[]
1793: for x in range(1,14):
1.17 dwinter 1794: if not x in [6,10,9]: # not used fields
1795: ret.append('xdata_%02i'%x)
1.1 dwinter 1796: return ret
1797:
1798: def getDefinedFields(self):
1799: """show all defined fields"""
1800:
1801: return definedFields
1802:
1803: def getAttribute(self,field):
1804: """get attrbiute"""
1805: return getattr(self,field)
1806:
1.47.2.4 dwinter 1807: def getContent(self,field,filter=None):
1.1 dwinter 1808: """Inhalt des Feldes"""
1809:
1810: text=u''
1.46 dwinter 1811:
1.1 dwinter 1812: for x in getattr(self,field):
1813:
1814: try:
1.46 dwinter 1815: text +=x
1.1 dwinter 1816: except:
1.46 dwinter 1817: text = x
1818:
1.9 dwinter 1819:
1.46 dwinter 1820:
1.9 dwinter 1821: try:
1822: if text[len(text)-1]==";":
1.21 dwinter 1823: text=text[0:len(text)-1]
1824:
1825:
1.9 dwinter 1826: except:
1.46 dwinter 1827: pass
1828:
1829: if text=='':
1830: text2=text
1831: else:
1832: text2=re.sub(r';([^\s])','; \g<1>',text)
1.16 dwinter 1833:
1.30 dwinter 1834: #teste ob ergebnis leer und header dann nehme title
1835:
1836: if (text2=='') and (field=='WEB_project_header'):
1837: return self.getContent('WEB_title')
1838:
1.47.2.4 dwinter 1839: if filter:
1840: splitted=text2.split("""<p class="picture">""")
1.47.2.5 dwinter 1841: if len(splitted)>1:
1842: tmp=splitted[1].split("</p>")
1.47.2.25 dwinter 1843: #return repr(splitted[1])
1.47.2.10 dwinter 1844: try:
1.47.2.25 dwinter 1845: self.imageURL=tmp[0].split("\"")[1].encode('utf-8')
1846: except:
1847: self.imageURL=tmp[0].split("src=")[1].split(" ")[0].encode('utf-8')
1848:
1.47.2.5 dwinter 1849: split2="</p>".join(tmp[1:])
1850:
1851: text3=splitted[0]+split2
1852:
1853: splitted=text3.split("""<p class="picturetitle">""")
1854: if len(splitted)>1:
1855: tmp=splitted[1].split("</p>")
1.47.2.25 dwinter 1856: self.imagecap=tmp[0].encode('utf-8')
1.47.2.11 dwinter 1857:
1.47.2.5 dwinter 1858: split4="".join(tmp[1:])
1.47.2.4 dwinter 1859:
1.47.2.5 dwinter 1860: text5=splitted[0]+split4
1861: else:
1862: #keine caption
1863: text5=text3
1864: else:
1865: #kein bild
1866: text5=text2
1.47.2.4 dwinter 1867: else:
1868: text5=text2
1869:
1.30 dwinter 1870: #teste ob WEB_project_description und keine führenden p tags
1.47.2.4 dwinter 1871: if (len(text5)>4) and (not text5[0:3]=='<p>') and (field=='WEB_project_description'):
1.47.2.11 dwinter 1872: text5= "<p>"+text5+"</p>"
1.46 dwinter 1873:
1874:
1.47.2.4 dwinter 1875: #filter image
1876:
1.47.2.11 dwinter 1877:
1.47.2.4 dwinter 1878: return text5.encode('utf-8')
1.47.2.9 dwinter 1879:
1880: def showImagesOfPage(self,imageUrl=None):
1881: """show Images of project"""
1882: self.getContent('WEB_project_description',filter='yes') #get the content and store image infos into session
1883: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','projectImageView.zpt')).__of__(self)
1884: return pt()
1885:
1.47.2.22 dwinter 1886:
1.1 dwinter 1887: def show_html(self):
1888: """simple index"""
1889: #return "HI"
1.45 dwinter 1890: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGProject_index.zpt')).__of__(self)
1.1 dwinter 1891: return pt()
1892:
1.47.2.20 dwinter 1893: def saveFromPreview(self):
1894: """save content aus preview"""
1895: self.WEB_project_description=self.previewTemplate.WEB_project_description[0:]
1896: self.REQUEST.RESPONSE.redirect("./index.html")
1897:
1898: def saveEditedContent(self,kupu=None,preview=None):
1899: """save Edited content"""
1900:
1.47.2.23 dwinter 1901: if preview:
1902: kupu=preview
1.47.2.20 dwinter 1903: #find content of body tags
1904: start=kupu.find("<body>")
1905: end=kupu.find("</body>")
1906: newcontent= kupu[start+6:end]
1907:
1908: if preview:
1.47.2.23 dwinter 1909:
1.47.2.20 dwinter 1910: return self.preview(newcontent)
1911:
1.47.2.23 dwinter 1912: self.copyObjectToArchive()
1.47.2.20 dwinter 1913: self.WEB_project_description=newcontent[0:]
1914:
1.47.2.23 dwinter 1915: self.REQUEST.RESPONSE.redirect("./index.html")
1.47.2.20 dwinter 1916:
1917: return True
1.47.2.21 dwinter 1918:
1.47.2.33 dwinter 1919: security.declareProtected('View management screens','edit')
1.47.2.24 dwinter 1920: def edit(self,western=None):
1.47.2.20 dwinter 1921: """Edit pages"""
1.47.2.24 dwinter 1922: if western:
1923: self.REQUEST.RESPONSE.setCookie("MP_debug_code","western",path="/")
1924:
1925:
1.47.2.20 dwinter 1926: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGProjectNeu.zpt')).__of__(self)
1927: return pt()
1928:
1929: def preview(self,description):
1930: """preview"""
1931: tmpPro=getattr(self,"previewTemplate",None)
1932: if not tmpPro:
1933: tmpPro=MPIWGProject("previewTemplate")
1934: self._setObject("previewTemplate",tmpPro)
1935: for field in definedFields:
1936: setattr(tmpPro,field,getattr(self,field))
1937: tmpPro.WEB_project_description=description[0:]
1938:
1939: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','previewFrame.zpt')).__of__(self)
1940: return pt()
1941:
1942: #return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+"/previewTemplate")
1943:
1944:
1945: def getWebProject_description(self):
1946: """get description"""
1.47.2.24 dwinter 1947: debug= self.REQUEST.cookies.get("MP_debug_code",None)
1.47.2.20 dwinter 1948:
1.47.2.24 dwinter 1949: if debug and debug=="western":
1.47.2.23 dwinter 1950: return """
1951: <html>
1952: <head>
1953: <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
1954: </head>
1955: <body>%s
1956: </html></body>
1.47.2.24 dwinter 1957: """%self.WEB_project_description[0]
1958:
1959: return """
1960: <html>
1961: <head>
1962: <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
1963: </head>
1964: <body>%s
1965: </html></body>
1.47.2.23 dwinter 1966: """%self.getContent('WEB_project_description')
1.47.2.24 dwinter 1967:
1.47.2.20 dwinter 1968:
1969:
1.1 dwinter 1970: def editMPIWGProjectForm(self):
1971: """editform"""
1.45 dwinter 1972: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGProject.zpt')).__of__(self)
1.1 dwinter 1973: return pt()
1974:
1.47.2.21 dwinter 1975:
1.47.2.20 dwinter 1976: def editMPIWGProject(self,RESPONSE=None,fromEdit=None):
1.42 dwinter 1977: """edit the project and archive the old version"""
1978:
1979: self.copyObjectToArchive() # archive the object
1980:
1.22 dwinter 1981:
1.1 dwinter 1982: for x in definedFields:
1983: if self.REQUEST.has_key(x):
1984:
1.9 dwinter 1985: setattr(self,x,[self.REQUEST[x].decode('utf-8')])
1.42 dwinter 1986:
1.47.2.20 dwinter 1987: if fromEdit and (RESPONSE is not None):
1988: RESPONSE.redirect('./editMPIWGBasisEditor')
1.42 dwinter 1989:
1.47.2.20 dwinter 1990: else:
1991: if RESPONSE is not None:
1992: RESPONSE.redirect('manage_main')
1.1 dwinter 1993:
1.47.2.20 dwinter 1994:
1.47.2.21 dwinter 1995:
1996: security.declareProtected('View managment screens','editMPIWGDisciplinesThemesEditor')
1.47.2.20 dwinter 1997: def editMPIWGDisciplinesThemesEditor(self):
1998: """edit from edit"""
1999: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGDisciplinesThemesNeu.zpt')).__of__(self)
2000: return pt()
2001:
2002:
1.9 dwinter 2003: def editMPIWGDisciplinesThemesForm(self):
2004: """edit the disciplines and themes Form"""
1.47.2.20 dwinter 2005:
1.45 dwinter 2006: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGDisciplinesThemes.zpt')).__of__(self)
1.9 dwinter 2007: return pt()
2008:
1.47.2.20 dwinter 2009: def editMPIWGDisciplinesThemes(self,disciplines=None,themes=None,RESPONSE=None,fromEdit=None):
1.9 dwinter 2010: """edit disciplin and form"""
2011: if disciplines:
2012: if type(disciplines) is StringType:
2013: self.xdata_09=disciplines
2014: else:
2015: self.xdata_09=string.join(disciplines,";")
2016: else:
2017: self.xdata_09=""
2018: if themes:
2019: if type(themes) is StringType:
2020: self.xdata_10=themes
2021: else:
2022: self.xdata_10=string.join(themes,";")
2023: else:
2024: self.xdata_10=""
1.47.2.20 dwinter 2025:
2026: if fromEdit and (RESPONSE is not None):
2027: RESPONSE.redirect('./editMPIWGDisciplinesThemesEditor')
2028:
2029: else:
2030: if RESPONSE is not None:
2031: RESPONSE.redirect('manage_main')
1.9 dwinter 2032:
2033:
2034: def isChecked(self,wert,list):
2035: """check if wert is in ; seperated list"""
1.46 dwinter 2036:
1.9 dwinter 2037: #felder sind manchmnal als liste mit einem element definiert
2038: if type(list) is StringType or UnicodeType:
2039: splitted=list.split(";")
2040: else:
2041: splitted=list[0].split(";")
2042:
1.47.2.12 dwinter 2043: splitted=[y.rstrip().lstrip() for y in splitted]
2044:
1.9 dwinter 2045: for x in splitted:
1.47.2.35! dwinter 2046: x=re.sub(r"[^A-z ]","",x)
1.9 dwinter 2047: if (not x==u'') and x in wert:
2048: return 1
2049: return 0
1.47.2.20 dwinter 2050:
1.47.2.21 dwinter 2051: security.declareProtected('View management screens','editMPIWGBasisEditor')
1.47.2.20 dwinter 2052: def editMPIWGBasisEditor(self):
2053: """editform"""
2054: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGBasisNeu.zpt')).__of__(self)
2055: return pt()
2056:
1.47.2.33 dwinter 2057: security.declareProtected('View management screens','editMPIWGBasisForm')
1.9 dwinter 2058: def editMPIWGBasisForm(self):
2059: """editform"""
1.45 dwinter 2060: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGBasis.zpt')).__of__(self)
1.9 dwinter 2061: return pt()
1.47.2.20 dwinter 2062:
1.47.2.33 dwinter 2063: security.declareProtected('View management screens','editMPIWGRelatedPublicationsForm')
1.9 dwinter 2064: def editMPIWGRelatedPublicationsForm(self):
2065: """Edit related Publications"""
1.45 dwinter 2066: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','edit_MPIWGRelatedPublications.zpt')).__of__(self)
1.9 dwinter 2067: return pt()
1.1 dwinter 2068:
1.9 dwinter 2069:
1.1 dwinter 2070: def loadNewFileForm(self):
2071: """Neues XML-File einlesen"""
1.45 dwinter 2072: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','MPIWGProject_newfile.zpt')).__of__(self)
1.1 dwinter 2073: return pt()
2074:
2075: def loadNewFile(self,RESPONSE=None):
2076: """einlesen des neuen files"""
2077: fileupload=self.REQUEST['fileupload']
2078: if fileupload:
2079: file_name=fileupload.filename
2080: filedata=fileupload.read()
2081:
2082: argv=xmlhelper.proj2hash(filedata)
2083: #print argv.keys()
2084: for arg in definedFields:
2085:
2086: #print arg,argv[arg],getattr(self,arg)
2087: try:
2088: temp=argv[arg][0:]
2089: #old=getattr(self,arg)
2090: setattr(self,arg,temp)
2091: #print old,getattr(self,arg)
2092: except:
2093: """nothing"""
2094:
2095: if RESPONSE is not None:
2096: RESPONSE.redirect('manage_main')
2097:
2098: def manage_addMPIWGProjectForm(self):
2099: """form for adding the project"""
1.45 dwinter 2100: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMPIWGProjectForm.zpt')).__of__(self)
1.1 dwinter 2101: return pt()
2102:
2103: def manage_addMPIWGProject(self,id,RESPONSE=None):
2104: """method to add a project"""
2105: #print argv
1.20 dwinter 2106: fileupload=self.REQUEST.get('fileupload',None)
2107: if fileupload:
1.46 dwinter 2108:
1.20 dwinter 2109: file_name=fileupload.filename
2110: filedata=fileupload.read()
2111:
2112: argv=xmlhelper.proj2hash(filedata)
2113:
2114: #print argv
1.5 dwinter 2115: newObj=MPIWGProject(id,argv)
2116: else:
2117: newObj=MPIWGProject(id)
1.1 dwinter 2118:
2119: self._setObject(id,newObj)
2120:
1.47.2.18 dwinter 2121:
1.1 dwinter 2122: if RESPONSE is not None:
2123: RESPONSE.redirect('manage_main')
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>