Annotation of MPIWGWeb/MPIWGProjects.py, revision 1.15
1.9 dwinter 1: """This contains the class MPIWG Projects
1.6 dwinter 2: for organizing and maintaining the different projectspages
3:
4: """
1.1 dwinter 5: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
6: from Products.PageTemplates.PageTemplate import PageTemplate
7: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
1.11 dwinter 8: from Products.ZSQLExtend.ZSQLExtend import ZSQLExtendFolder
1.1 dwinter 9:
1.12 dwinter 10: import urllib
1.1 dwinter 11: import MPIWGStaff
12: import string
13: import re
1.5 dwinter 14: from types import *
1.1 dwinter 15:
16: import xmlhelper # Methoden zur Verwaltung der projekt xmls
17: from OFS.SimpleItem import SimpleItem
18: from OFS.Folder import Folder
19:
1.11 dwinter 20: from bibliography import *
21:
1.1 dwinter 22: 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']
23:
24: checkFields = ['xdata_01']
25:
1.9 dwinter 26:
27:
1.1 dwinter 28: def sortF(x,y):
1.9 dwinter 29: try:
30: return cmp(x[1],y[1])
31: except:
32: return 0
1.5 dwinter 33:
34: def sortI(x,y):
35: xsplit=x[1].split(".")
36: ysplit=y[1].split(".")
37: xret=""
38: yret=""
39: try:
40: for i in range(5):
41: try:
42: yret=yret+"%04i"%int(xsplit[i])
43: except:
44: yret=yret+"%04i"%0
45:
46: try:
47: xret=xret+"%04i"%int(ysplit[i])
48: except:
49: xret=xret+"%04i"%0
50:
51:
52: return cmp(int(yret),int(xret))
53: except:
54: return cmp(x[1],y[1])
1.1 dwinter 55:
1.5 dwinter 56:
1.11 dwinter 57: class MPIWGRoot(ZSQLExtendFolder):
1.1 dwinter 58: """Stammordner für den Web-Server"""
59:
1.9 dwinter 60: fieldLabels={'WEB_title':'WEB_Title','xdata_01':'Responsible Scientists','xdata_02':'Department',
61: 'xdata_03':'Historical Persons','xdata_04':'Time period',
62: 'xdata_05':'Sorting number','xdata_06':'Keywords','xdata_07':'Short title',
63: 'xdata_08':'Other involved scholars' ,'xdata_09':'Part of','xdata_10':'Covered by',
64: 'xdata_11':'Object Digitallibrary','xdata_12':'Cooperation partners',
65: 'xdata_13':'Funding institutions','WEB_project_header':'WEB_project_header',
66: 'WEB_project_description':'WEB_project_description','WEB_related_pub':'WEB_related_pub'}
67:
1.1 dwinter 68: folders=['MPIWGProject','Folder']
69: meta_type='MPIWGRoot'
1.8 dwinter 70:
1.11 dwinter 71: def replaceNotEmpty(self,format,field):
72: """replace not empty"""
73: if field and (not field==''):
74: return format%field
75: else:
76: return ""
77:
78:
79: def formatBibliography(self,here,found):
80: """format"""
81: return formatBibliography(here,found)
82:
1.9 dwinter 83: def getValue(self,field):
84: """Inhalt des Feldes"""
85:
86: if type(field)==StringType:
87: try:
88: if field[len(field)-1]==";":
89: field=field[0:len(text)-1]
90: except:
91: """nothing"""
92:
93: return field.encode('utf-8')
94:
95: else:
96: return field[0].encode('utf-8')
97:
98:
1.8 dwinter 99: def sortedNames(self,list):
100: """sort names"""
101:
1.12 dwinter 102: def sortLastName(x_c,y_c):
1.13 dwinter 103: try:
104: x=urllib.unquote(x_c).encode('utf-8','ignore')
105: except:
106: x=urllib.unquote(x_c)
107:
108: try:
109: y=urllib.unquote(y_c).encode('utf-8','ignore')
110: except:
111: x=urllib.unquote(y_c)
112:
113:
1.12 dwinter 114:
1.8 dwinter 115: try:
116: last_x=x.split()[len(x.split())-1]
117: last_y=y.split()[len(y.split())-1]
118:
119: except:
120:
121: last_x=""
122: last_y=""
123:
124:
125:
126: if last_x<last_y:
127: return 1
128: elif last_x>last_y:
129: return -1
130: else:
131: return 0
132:
133: list.sort(sortLastName)
134: list.reverse()
135:
136: return list
1.1 dwinter 137:
138: def __init__(self, id, title):
139: """init"""
140: self.id=id
141: self.title=title
1.12 dwinter 142:
143: def urlQuote(self,str):
144: """quote"""
145: return urllib.quote(str)
146:
147: def urlUnQuote(self,str):
148: """quote"""
149: return urllib.unquote(str)
150:
1.8 dwinter 151: def harvestHistoricalPersons(self):
152: """erstelle liste aller erwaehnten actors"""
153:
154: def normalize(str):
155: """loesche fuhrendes space"""
156: if (len(str)>1) and (str[0]==" "):
157: ret=str[1:]
158: else:
159: ret=str
160: return ret
161:
162: list={}
163: projects=self.ZopeFind(self.projects,obj_metatypes=['MPIWGProject'])
164:
165: for project in projects:
166: lg=len(project[1].xdata_03[0])-1
167:
168: if (lg>1) and (project[1].xdata_03[0][lg]==";"):
1.12 dwinter 169: project[1].xdata_03[0]=project[1].xdata_03[0][0:lg]
1.8 dwinter 170:
171:
172:
173:
174: try:
175: if len(project[1].xdata_03[0].split(";"))>1: # guess if separator is ;
176: for person in project[1].xdata_03[0].split(";"):
177: personNormal=normalize(person)
178: if personNormal in list.keys():
1.12 dwinter 179: list[urllib.quote(personNormal)][1].append(project[1])
1.8 dwinter 180: else:
1.12 dwinter 181: list[urllib.quote(personNormal)]=(personNormal,[project[1]])
1.8 dwinter 182: else: #guess , is sepeator
183: for person in project[1].xdata_03[0].split(","):
184: personNormal=normalize(person)
1.12 dwinter 185: if urllib.quote(personNormal) in list.keys():
186: list[urllib.quote(personNormal)][1].append(project[1])
1.8 dwinter 187: else:
1.12 dwinter 188: list[urllib.quote(personNormal)]=(personNormal,[project[1]])
1.8 dwinter 189:
190: except:
191: print "ERROR",project
192:
193: return list
194:
195: def storeHistoricalPersons(self,RESPONSE=None):
196: """store persons"""
197: self.personDict={}
198: personDict=self.harvestHistoricalPersons()
199: for person in personDict.keys():
1.12 dwinter 200: for project in personDict[person][1]:
1.8 dwinter 201: if person in self.personDict.keys():
1.12 dwinter 202: self.personDict[person][1].append((project.absolute_url(),project.WEB_title[0],project.xdata_01[0]))
1.8 dwinter 203: else:
1.12 dwinter 204: self.personDict[person]=(personDict[person][0],[(project.absolute_url(),project.WEB_title[0],project.xdata_01[0])])
1.1 dwinter 205:
1.8 dwinter 206: if RESPONSE is not None:
207: RESPONSE.redirect("showHistoricalPersons")
208:
1.13 dwinter 209:
210: def getPersonDict(self,name):
211: """name von dict"""
212:
213: try:
214: return self.personDict[name][0].encode('utf-8')
215: except:
216: return self.personDict[name][0]
217: return self.personDict[name][0].decode('latin-1').encode('utf-8')
218:
1.8 dwinter 219:
220: def showHistoricalPersons(self):
221: """show persons"""
222: pt=PageTemplateFile('Products/MPIWGWeb/zpt/showHistoricalPersons').__of__(self)
223: return pt()
224:
225:
226: def editHistoricalPersonsForm(self):
227: """edit historical persons for consistency"""
228: pt=PageTemplateFile('Products/MPIWGWeb/zpt/editHistoricalPersonsForm').__of__(self)
229: return pt()
230:
231: def getProjectsByFieldContent(self,fieldName,fieldContentsEntry):
232: """gib alle Projekte aus mit Value von field mit fieldName enthält ein Element der Liste fieldContents"""
233: if type(fieldContentsEntry) is StringType:
234: fieldContents=[fieldContentsEntry]
235: else:
236: fieldContents=fieldContentsEntry
237:
238: projects=self.ProjectCatalog({fieldName:string.join(fieldContents,' OR')})
239: #print projects
240: return projects
241:
242: def changeMPIWGRootForm(self):
243: """edit"""
244: pt=PageTemplateFile('Products/MPIWGWeb/zpt/changeMPIWGRootForm').__of__(self)
245: return pt()
246:
247: def changeMPIWGRoot(self,title,disciplineList,themesList,RESPONSE=None):
248: """change"""
249: self.title=title
250: self.disciplineList=disciplineList
251: self.themesList=themesList
252:
253: if RESPONSE is not None:
254: RESPONSE.redirect('manage_main')
255:
1.9 dwinter 256: def getDisciplineList(self):
257: """get disciplines as list"""
258: return self.disciplineList.split("\n")
259:
260: def getThemeList(self):
261: """get themes as list"""
262: return self.themesList.split("\n")
263:
1.8 dwinter 264: def test(self):
265: """test"""
266: return self.getProjectsByFieldContent('xdata_09',['biology'])[0].absolute_url
1.9 dwinter 267:
268: def getContexts(self,childs=None,parents=None,depth=None):
269: """childs alle childs, alle parents"""
270: ret=[]
271: if parents:
272: splitted=parents.split(".")
273: parentId=string.join(splitted[0:len(splitted)-1],".")
274:
275: for project in self.getProjectFields('xdata_05',sort='int'):
276: if project[1]==parentId:
277: ret.append(project)
278:
279: if childs:
280: for project in self.getProjectFields('xdata_05',sort='int'):
281: searchStr=childs+"(\..*)"
282: if re.match(searchStr,project[1]):
283:
284: if depth:
1.14 dwinter 285:
1.9 dwinter 286: if int(depth)>=len(project[1].split("."))-len(childs.split(".")):
287:
288: ret.append(project)
289: else:
290: ret.append(project)
291: return ret
1.8 dwinter 292:
1.5 dwinter 293: def getProjectFields(self,fieldName,folder=None,sort=None):
1.1 dwinter 294: """getListofFieldNames"""
295: ret=[]
296: #print "FN",fieldName
297: if not folder:
298: folder=self
299: for object in folder.__dict__:
300:
301: obj=getattr(folder,object)
302: if hasattr(obj,'meta_type'):
1.5 dwinter 303: #print obj.meta_type
1.1 dwinter 304: if obj.meta_type=='MPIWGProject':
1.5 dwinter 305: if fieldName=="WEB_title_or_short":
306: #print "HI!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
307: #print len(obj.getContent('xdata_07'))
308: if len(obj.getContent('xdata_07'))<3: # hack weil z.Z. manchmal noch ein Trennzeichen ; oder , im Feld statt leer
309: fieldNameTmp="WEB_title"
310: else:
311: fieldNameTmp="xdata_07"
312: else:
313: fieldNameTmp=fieldName
1.1 dwinter 314:
1.5 dwinter 315: ret.append((obj,obj.getContent(fieldNameTmp)))
316:
1.1 dwinter 317: if obj.meta_type in self.folders:
318:
319: ret += self.getProjectFields(fieldName,obj)
1.5 dwinter 320:
321: if sort=="int":
322: ret.sort(sortI)
323: else:
324: ret.sort(sortF)
1.1 dwinter 325:
326: return ret
327:
1.5 dwinter 328: def showNewProjects(self):
329: projects=[]
330: for objs in self.getProjectFields('WEB_title_or_short'): # Get all Projets
331: if objs[0].xdata_05[0] == "":
332:
333: projects.append(objs)
334:
335: return projects
336:
337:
1.1 dwinter 338: manage_options = Folder.manage_options+(
339: {'label':'Import Persons','action':'importNamesForm'},
1.8 dwinter 340: {'label':'Main config','action':'changeMPIWGRootForm'},
1.9 dwinter 341: {'label':'Edit Historical Persons','action':'editHistoricalPersonsForm'},
1.8 dwinter 342: {'label':'Store Historical Persons','action':'storeHistoricalPersons'},
1.1 dwinter 343: )
344:
345: def importNamesForm(self):
346: """Form"""
347: pt=PageTemplateFile('Products/MPIWGWeb/zpt/MPIWGNamesForm.zpt').__of__(self)
348: return pt()
349:
350: def importNames(self,fileupload,folderName,RESPONSE=None):
351: """import komma-sep list email,lastName,firstName"""
352: project=getattr(self,folderName)
1.9 dwinter 353: load=fileupload.read()
1.1 dwinter 354:
1.9 dwinter 355: for line in load.split('\r'):
356:
357:
1.1 dwinter 358: splitted=line.split(",")
1.9 dwinter 359: print splitted
360:
1.1 dwinter 361: if not (splitted[0]==""):
362: newObj=MPIWGStaff.MPIWGStaff(splitted[0],splitted[1],splitted[2])
1.9 dwinter 363:
1.1 dwinter 364: try:
365: project._setObject(splitted[0],newObj)
1.9 dwinter 366: print "done:",splitted[0]
1.1 dwinter 367: except:
368: print "not done:",splitted[0]
1.9 dwinter 369:
1.1 dwinter 370: if RESPONSE is not None:
371: RESPONSE.redirect('manage_main')
372:
1.3 dwinter 373: def getAllMembers(self):
374: """give list of all members"""
375: ret=[]
376:
1.9 dwinter 377: #for x in self.members.objectValues('MPIWGStaff'):
1.4 dwinter 378: #print x.title
1.9 dwinter 379: # ret.append(x.title.decode('utf-8'))
380:
381: for x in self.ZopeFind(self.members,obj_metatypes=['MPIWGStaff']):
382: ret.append(x[1].title.decode('utf-8'))
1.3 dwinter 383:
1.9 dwinter 384: #ret.sort()
385: #print ret
386:
1.3 dwinter 387: return ret
388:
1.9 dwinter 389: def printAllMembers(self):
390: """prin"""
391: members=self.getAllMembers()
392: ret=""
393: for x in members:
394: ret+="<p>%s</p>"%x
395: return ret
396:
397:
1.5 dwinter 398: def makeList(self,entry):
399: """makes a list out of one entry or repeat a list"""
400: if type(entry) is StringType:
401: return [entry]
402: else:
403: return entry
404:
405:
406: def getTree(self):
407: """generate Tree from project list"""
408: returnList=[]
409: for project in self.getProjectFields('xdata_05',sort="int"): # get Projects sorted by xdata_05
410: for idNr in project[1].split(";"): # more than one number
411: if not idNr=="":
412: splittedId=idNr.split(".")
413: depth=len(splittedId)
414: nr=idNr
1.14 dwinter 415: #title=project[0].WEB_title
416: title=[project[0].getContent('WEB_title')]
417: #print title
1.9 dwinter 418:
1.5 dwinter 419: returnList.append((depth,nr,title,project[0]))
420:
421: return returnList
422:
423: def changePosition(self,treeId,select,RESPONSE=None):
424: """Change Postion Entry"""
425: numbers=[]
426:
427: # Suche hoechste bisherige nummer
428: projects=self.getProjectFields('xdata_05') # get Projects sorted by xdata_05
1.8 dwinter 429: #print "pj",projects
1.5 dwinter 430: for project in projects: #suche alle subtrees der treeId
431: #print treeId
432:
433: founds=re.match(treeId+"\.(.*)",project[1].split(";")[0])
434: if founds:
435: #print "x",founds.group(0),len(founds.group(0).split("."))
436: if len(founds.group(0).split("."))==len(treeId.split("."))+1: # nur ein punkt mehr, d.h. untere ebene
437: try:
438: numbers.append(int(founds.group(0).split(".")[len(founds.group(0).split("."))-1]))
439: except:
1.6 dwinter 440: numbers.append(int(0))
441:
442: try:
443: highest=max(numbers)
444: except:
445: highest=0
1.5 dwinter 446: projects=self.showNewProjects()
447: for i in self.makeList(select):
448: highest+=10
449: projects[int(i)][0].xdata_05=treeId+"."+str(highest)
450:
451:
452: if RESPONSE is not None:
453: RESPONSE.redirect('showTree')
454:
455: def changeTree(self,RESPONSE=None):
456: """change the complete tree"""
457: form=self.REQUEST.form
458: hashList={}
459: fields=self.getTree()
460:
461:
462: for idNr in form.keys():
463: fields[int(idNr)][3].xdata_05=form[idNr]
464:
465:
466:
467: if RESPONSE is not None:
468: RESPONSE.redirect('showTree')
469:
470: def getProjectWithId(self,id):
471: fields=self.getProjectFields('xdata_05')
472: for field in fields:
473: if field[1]==id:
474: return field[0]
475:
476: return None
477:
478:
479:
480:
1.15 ! dwinter 481: def getRelativeUrlFromPerson(self,list):
! 482: """get urls to person list"""
! 483: ret=[]
! 484: persons=list.split(";")
! 485: for person in persons:
! 486:
! 487: if len(person)>1: #nicht nur Trennzeichen
! 488: splitted=person.split(",")
! 489: if len(splitted)==1:
! 490: splitted=person.split(" ")
! 491: splittedNew=[re.sub(r'\s(.*)','$1',split) for split in splitted]
! 492: if splittedNew[0]=='':
! 493: del splittedNew[0]
! 494: search=string.join(splittedNew,' AND ')
! 495:
! 496: if not search=='':
! 497:
! 498: try:
! 499: proj=self.MembersCatalog({'title':search})
! 500: except:
! 501: proj=None
! 502:
! 503: if proj:
! 504: #ret.append("<a href=%s >%s</a>"%(proj[0].absolute_url,person.encode('utf-8')))
! 505: ret.append("<a href=%s >%s</a>"%('members/'+proj[0].id,person))
! 506: else:
! 507: #ret.append("%s"%person.encode('utf-8'))
! 508: ret.append("%s"%person)
! 509: return string.join(ret,";")
1.5 dwinter 510:
511:
1.3 dwinter 512: def getUrlFromPerson(self,list):
513: """get urls to person list"""
514: ret=[]
515: persons=list.split(";")
516: for person in persons:
517:
1.9 dwinter 518: if len(person)>1: #nicht nur Trennzeichen
519: splitted=person.split(",")
520: if len(splitted)==1:
521: splitted=person.split(" ")
522: splittedNew=[re.sub(r'\s(.*)','$1',split) for split in splitted]
523: if splittedNew[0]=='':
524: del splittedNew[0]
525: search=string.join(splittedNew,' AND ')
1.4 dwinter 526:
1.9 dwinter 527: if not search=='':
528:
529: try:
530: proj=self.MembersCatalog({'title':search})
531: except:
532: proj=None
533:
534: if proj:
1.12 dwinter 535: #ret.append("<a href=%s >%s</a>"%(proj[0].absolute_url,person.encode('utf-8')))
1.9 dwinter 536: ret.append("<a href=%s >%s</a>"%(proj[0].absolute_url,person))
537: else:
1.12 dwinter 538: #ret.append("%s"%person.encode('utf-8'))
1.9 dwinter 539: ret.append("%s"%person)
1.3 dwinter 540: return string.join(ret,";")
541:
542: def getProjectsOfMembers(self):
543: """give tuple member /projects"""
544: ret=[]
545: members=self.getAllMembers()
1.9 dwinter 546: #return str(members)
1.3 dwinter 547: for x in members:
1.11 dwinter 548: ret+=self.getProjectsOfMember(name=x)
1.10 dwinter 549:
1.3 dwinter 550: return ret
1.11 dwinter 551:
552: def getProjectsOfMember(self,name=None,email=None):
553: """get project of a member"""
554: def sortP(x,y):
555: """sort by sorting number"""
556:
557: return cmp(x.xdata_05,y.xdata_05)
558:
559:
560: ret=[]
561: splitNeu=[]
562: if email:
563: members=self.ZopeFind(self.members,obj_metatypes=['MPIWGStaff'],obj_ids=[email])
564: name = members[0][1].title.decode('utf-8')
565:
566: y=name
567: splitted=y.split(",")
568: for s in splitted:
569: splitNeu.append("\""+s+"\"")
570: search=string.join(splitNeu,' AND ')
571:
572: proj=self.ProjectCatalog({'xdata_01':search})
573: if proj:
574: proj2=[x for x in proj]
575: proj2.sort(sortP)
576: ret.append((y,proj2))
577:
578: proj=self.ProjectCatalog({'xdata_08':search})
579: if proj:
580: proj2=[x for x in proj]
581: proj2.sort(sortP)
582: ret.append((y,proj2))
583:
584:
585: return ret
586:
1.1 dwinter 587: def givePersonList(self,name):
588: """check if person is in personfolder and return list of person objects"""
1.3 dwinter 589:
590: splitted=name.split(",")
591: if len(splitted)==1:
592: splitted=name.split(" ")
593: splittedNew=[re.sub(r'\s(.*)','$1',split) for split in splitted]
594: if splittedNew[0]=='':
595: del splittedNew[0]
596: search=string.join(splittedNew,' AND ')
597: if not search=='':
598: proj=self.MembersCatalog({'title':search})
599:
600: if proj:
601: return [[x.lastName,x.firstName] for x in proj]
602: else:
603: return []
604:
605: ## splitted=name.split(",") # version nachname, vorname...
606: ## if len(splitted)>1:
607: ## lastName=splitted[0]
608: ## firstName=splitted[1]
609: ## else:
610: ## splitted=name.split(" ") #version vorname irgenwas nachnamae
611:
612: ## lastName=splitted[len(splitted)-1]
613: ## firstName=string.join(splitted[0:len(splitted)-1])
614:
615: ## objs=[]
1.1 dwinter 616:
1.3 dwinter 617: #print self.members
618: ## for x in self.members.__dict__:
619: ## obj=getattr(self.members,x)
620: ## if hasattr(obj,'lastName') and hasattr(obj,'firstName'):
1.1 dwinter 621:
1.3 dwinter 622: ## 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 623:
1.3 dwinter 624: ## objs.append((obj,lastName+", "+firstName))
1.1 dwinter 625:
1.3 dwinter 626:
1.1 dwinter 627: return objs
628:
629:
630: def personCheck(self,names):
631: """all persons for list"""
1.4 dwinter 632: #print "names",names
1.1 dwinter 633: splitted=names.split(";")
634: ret={}
635: for name in splitted:
636:
637: if not (name==""):
1.3 dwinter 638: try:
639: ret[name]=self.givePersonList(name)
640: except:
641: """NOTHIHN"""
1.4 dwinter 642: #print "RET",ret
1.1 dwinter 643: return ret
644:
645: def giveCheckList(self,person,fieldname):
646: """return checklist"""
647: #print "GCL",fieldname
648: if fieldname=='xdata_01':
649: x=self.personCheck(person.getContent(fieldname))
1.4 dwinter 650: #print "GCLBACKX",x
1.1 dwinter 651: return x
652:
653:
654: def isCheckField(self,fieldname):
655: """return chechfield"""
656:
657: return (fieldname in checkFields)
658:
1.9 dwinter 659:
1.1 dwinter 660:
661:
662:
663: def manage_addMPIWGRootForm(self):
664: """form for adding the root"""
665: pt=PageTemplateFile('Products/MPIWGWeb/zpt/addMPIWGRootForm.zpt').__of__(self)
666: return pt()
667:
668: def manage_addMPIWGRoot(self,id,title,RESPONSE=None):
669: """add a root folder"""
670: newObj=MPIWGRoot(id,title)
671: self._setObject(id,newObj)
672:
673: if RESPONSE is not None:
674: RESPONSE.redirect('manage_main')
675:
676:
677: class MPIWGProject(Folder):
678: """Class for Projects"""
679:
680: meta_type='MPIWGProject'
681:
1.3 dwinter 682: def crossLinker(self):
683: """experimental crosslinker"""
684: splitted=self.WEB_project_description[0].split()
685: new=[]
686: for split in splitted:
687: try:
688: found=self.DescriptionCatalog({'fulltext':split})
689:
690: if len(found)>1:
691:
692: new.append("<a href=%s>%s</a>"%(split,split))
693: else:
694: new.append(split)
695: except:
696: new.append(split)
697: return string.join(new)
698:
699:
700:
1.1 dwinter 701:
702: def generateTemplate(self,RESPONSE=None):
703: """Erzeuge Template für defined fields not_used"""
704:
705: id="index_html"
706: title=id
707: if self._getOb('index_html'):
708: self._delObject('index_html')
709:
710:
711: newObj=ZopePageTemplate(id,'TEXT')
712: self._setObject(id,newObj)
713: #self.manage_addPageTemplate(id,title)
714: if RESPONSE is not None:
715: RESPONSE.redirect('manage_main')
716:
1.5 dwinter 717: def __init__(self, id, argv=None):
1.1 dwinter 718: """initieriere classe"""
719:
720: self.id=id
721: self.title=id
1.5 dwinter 722: if argv:
723: for arg in definedFields:
1.7 dwinter 724: try:
725: setattr(self,arg,argv[arg])
726: except:
727: setattr(self,arg,"")
1.5 dwinter 728: else:
729: for arg in definedFields:
730: setattr(self,arg,'')
1.1 dwinter 731:
732: manage_options = Folder.manage_options+(
733: {'label':'Load New File','action':'loadNewFileForm'},
734: {'label':'Edit ProjectInfo','action':'editMPIWGProjectForm'},
735: {'label':'Edit BasisInfo','action':'editMPIWGBasisForm'},
736: {'label':'Edit Publications','action':'editMPIWGRelatedPublicationsForm'},
1.9 dwinter 737: {'label':'Edit Themes & Disciplines','action':'editMPIWGDisciplinesThemesForm'},
1.1 dwinter 738: )
739:
740: def getDataFields(self):
741: """giveListofDatafields"""
742: ret=[]
743: for x in range(1,14):
744: ret.append('xdata_%02i'%x)
745: return ret
746:
747: def getDefinedFields(self):
748: """show all defined fields"""
749:
750: return definedFields
751:
752: def getAttribute(self,field):
753: """get attrbiute"""
754: return getattr(self,field)
755:
756: def getContent(self,field):
757: """Inhalt des Feldes"""
758:
759: text=u''
760: #print "FIELD",field
761: for x in getattr(self,field):
762: #print "HIHIIII"
763:
764: try:
1.9 dwinter 765: text +=x.encode('utf-8')
1.1 dwinter 766: except:
767: try:
1.9 dwinter 768: text =x.encode('utf-8')
1.1 dwinter 769: except:
1.14 dwinter 770: text=x.decode('latin-1').encode('utf-8')
1.9 dwinter 771:
772: #delete separator (;) if is there is one
773: try:
774: if text[len(text)-1]==";":
1.12 dwinter 775: text=text[0:len(text)-1].encode('utf-8')
1.9 dwinter 776: except:
777: """nothing"""
778:
1.1 dwinter 779: return text
1.9 dwinter 780:
1.1 dwinter 781:
782: def show_html(self):
783: """simple index"""
784: #return "HI"
785: pt=PageTemplateFile('Products/MPIWGWeb/zpt/MPIWGProject_index.zpt').__of__(self)
786: return pt()
787:
788: def editMPIWGProjectForm(self):
789: """editform"""
790: pt=PageTemplateFile('Products/MPIWGWeb/zpt/edit_MPIWGProject.zpt').__of__(self)
791: return pt()
792:
793: def editMPIWGProject(self,RESPONSE=None):
794: """edit the project"""
795:
796: #return self.REQUEST
797: for x in definedFields:
798: if self.REQUEST.has_key(x):
799:
1.9 dwinter 800: setattr(self,x,[self.REQUEST[x].decode('utf-8')])
1.1 dwinter 801:
802: if RESPONSE is not None:
803: RESPONSE.redirect('manage_main')
804:
1.9 dwinter 805: def editMPIWGDisciplinesThemesForm(self):
806: """edit the disciplines and themes Form"""
807: pt=PageTemplateFile('Products/MPIWGWeb/zpt/edit_MPIWGDisciplinesThemes.zpt').__of__(self)
808: return pt()
809:
810: def editMPIWGDisciplinesThemes(self,disciplines=None,themes=None,RESPONSE=None):
811: """edit disciplin and form"""
812: if disciplines:
813: if type(disciplines) is StringType:
814: self.xdata_09=disciplines
815: else:
816: self.xdata_09=string.join(disciplines,";")
817: else:
818: self.xdata_09=""
819: if themes:
820: if type(themes) is StringType:
821: self.xdata_10=themes
822: else:
823: self.xdata_10=string.join(themes,";")
824: else:
825: self.xdata_10=""
826:
827: if RESPONSE is not None:
828: RESPONSE.redirect('manage_main')
829:
830:
831: def isChecked(self,wert,list):
832: """check if wert is in ; seperated list"""
833: print "W:",wert
834: print "L:",list,type(list)
835: #felder sind manchmnal als liste mit einem element definiert
836: if type(list) is StringType or UnicodeType:
837: splitted=list.split(";")
838: else:
839: splitted=list[0].split(";")
840:
841: print splitted
842: for x in splitted:
843: if (not x==u'') and x in wert:
844: return 1
845: return 0
846:
847: def editMPIWGBasisForm(self):
848: """editform"""
849: pt=PageTemplateFile('Products/MPIWGWeb/zpt/edit_MPIWGBasis.zpt').__of__(self)
850: return pt()
851: def editMPIWGRelatedPublicationsForm(self):
852: """Edit related Publications"""
853: pt=PageTemplateFile('Products/MPIWGWeb/zpt/edit_MPIWGRelatedPublications.zpt').__of__(self)
854: return pt()
1.1 dwinter 855:
1.9 dwinter 856:
1.1 dwinter 857: def loadNewFileForm(self):
858: """Neues XML-File einlesen"""
859: pt=PageTemplateFile('Products/MPIWGWeb/zpt/MPIWGProject_newfile.zpt').__of__(self)
860: return pt()
861:
862: def loadNewFile(self,RESPONSE=None):
863: """einlesen des neuen files"""
864: fileupload=self.REQUEST['fileupload']
865: if fileupload:
866: file_name=fileupload.filename
867: filedata=fileupload.read()
868:
869: argv=xmlhelper.proj2hash(filedata)
870: #print argv.keys()
871: for arg in definedFields:
872:
873: #print arg,argv[arg],getattr(self,arg)
874: try:
875: temp=argv[arg][0:]
876: #old=getattr(self,arg)
877: setattr(self,arg,temp)
878: #print old,getattr(self,arg)
879: except:
880: """nothing"""
881:
882: if RESPONSE is not None:
883: RESPONSE.redirect('manage_main')
884:
885: def manage_addMPIWGProjectForm(self):
886: """form for adding the project"""
887: pt=PageTemplateFile('Products/MPIWGWeb/zpt/addMPIWGProjectForm.zpt').__of__(self)
888: return pt()
889:
890: def manage_addMPIWGProject(self,id,RESPONSE=None):
891: """method to add a project"""
892: #print argv
1.5 dwinter 893: if self.REQUEST.has_key('fileupload'):
894: fileupload=self.REQUEST['fileupload']
895: if fileupload:
896: file_name=fileupload.filename
897: filedata=fileupload.read()
1.1 dwinter 898:
1.5 dwinter 899: argv=xmlhelper.proj2hash(filedata)
1.1 dwinter 900:
1.5 dwinter 901: #print argv
902: newObj=MPIWGProject(id,argv)
903: else:
904: newObj=MPIWGProject(id)
1.1 dwinter 905:
906: self._setObject(id,newObj)
907:
908:
909: if RESPONSE is not None:
910: RESPONSE.redirect('manage_main')
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>