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