Annotation of ECHO_content/ECHO_collection.py, revision 1.14
1.13 dwinter 1: """New version of the product started February, 8th. Without scientific classification, use content-type for further classification."""
1.1 casties 2: """Echo collection provides the classes for the ECHO content web-site.
3:
4: class ECHO_collection is the basis class for an ECHO collection.
5:
6: class ECHO_resource contains information on ECHO resources (e.g. an Display environment for Metadata
7:
8: class ECHO_externalLink contains information on externalLinks
9:
10:
11: """
12: import string
1.14 ! dwinter 13: import re
1.1 casties 14: import OFS.Image
15: from types import *
16: from OFS.Image import Image
17: from Globals import DTMLFile
18: from OFS.Folder import Folder
19: from OFS.SimpleItem import SimpleItem
20: from AccessControl import ClassSecurityInfo
21: from Globals import InitializeClass
22: from Globals import DTMLFile
23: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
24: from Products.PageTemplates.PageTemplate import PageTemplate
25: from Globals import Persistent
26: from Acquisition import Implicit
1.13 dwinter 27: from pyPgSQL import libpq
1.14 ! dwinter 28: import xml.dom.minidom
1.1 casties 29:
30: import urllib
31: import xml.dom.minidom
32:
33:
1.6 dwinter 34: #List of different types for the graphical linking viewer
35: viewClassificationListMaster=['view point','area']
36:
37:
1.1 casties 38: def toList(field):
39: """Einzelfeld in Liste umwandeln"""
40: if type(field)==StringType:
41: return [field]
42: else:
43: return field
44:
45: def getText(nodelist):
46:
47: rc = ""
48: for node in nodelist:
49: if node.nodeType == node.TEXT_NODE:
50: rc = rc + node.data
51: return rc
52:
53:
54: def readMetadata(url):
55: """Methoden zum Auslesen der Metadateninformation zu einer Resource
56: Vorerst noch Typ bib"""
57:
58: metadict={}
59: try:
60: geturl=""
61: for line in urllib.urlopen(url).readlines():
62: geturl=geturl+line
63:
64:
65: except:
66: return (None,"Cannot open: "+url)
67:
68: try:
69: dom=xml.dom.minidom.parseString(geturl)
70: except:
71: return (None,"Cannot parse: "+url+"<br>"+geturl)
72:
73: metanode=dom.getElementsByTagName('bib')
74: metadict['bib_type']='Book'
75: if len(metanode)==0:
76: metanode=dom.getElementsByTagName('archimedes')
77: metadict['bib_type']='Archimedes'
78: #print "HELLO"
79:
80: if not len(metanode)==0:
81: metacontent=metanode[0].childNodes
82:
83: try:
84: metadict['bib_type']=getText(dom.getElementsByTagName('bib')[0].attributes['type'].childNodes)
85: except:
86: """nothing"""
87:
88: for node in metacontent:
89: try:
90: metadict[node.tagName.lower()]=getText(node.childNodes)
91: except:
92: """nothing"""
93:
94: #print metadict
95: return metadict,""
96:
97:
1.13 dwinter 98: def setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coordstrs,viewClassification=""):
1.1 casties 99:
100: """Allegemeine Informationen zu einer ECHO Collection"""
101:
1.6 dwinter 102: self.viewClassification=viewClassification
103:
1.1 casties 104: self.label = label
105: self.title=title
106: self.description=description
107: self.content_type=content_type
108: self.responsible=responsible
109: self.credits=toList(credits)
110: self.weight=weight
111:
1.5 dwinter 112: coords=[]
1.1 casties 113: #coordinates of for rectangles
1.10 dwinter 114:
1.9 dwinter 115: #print "cs", coordstrs
116: if coordstrs:
117: for coordstr in coordstrs:
1.12 dwinter 118: #print "cs", coordstr
1.9 dwinter 119: try:
120: temco=coordstr.split(",")
121: except:
122: temco=[]
123: #temco.append(angle)
124: coords.append(temco)
125:
1.10 dwinter 126:
1.5 dwinter 127: self.coords=coords[0:]
1.1 casties 128:
129:
130: class scientificClassification(SimpleItem,Persistent,Implicit):
1.13 dwinter 131: """outdated will be deleeted in the next versions: subclass"""
1.1 casties 132: security=ClassSecurityInfo()
133:
134: def __init__(self,context,science,practice):
135: self.context=context
136: self.science=science
137: self.practice=practice
138: self.id="scientific_Classification"
139:
140: security.declarePublic('get_context')
141: def get_context(self):
142: return self.context
143:
144: security.declarePublic('get_science')
145: def get_science(self):
146: return self.science
147:
148: security.declarePublic('get_practice')
149: def get_practice(self):
150: return self.practice
151:
152:
153: class scientificInformation(Folder,Persistent,Implicit):
1.13 dwinter 154: """outdated will be deleted in the next versions: subclass scientificInformation"""
1.1 casties 155: security=ClassSecurityInfo()
156:
157:
158:
159: def __init__(self,source_type,period):
160:
161: self.id="scientific_Information"
162: self.source_type=source_type
163: self.period=period
164:
165:
166:
167: security.declarePublic('get_source_type')
168: def get_source_type(self):
169: return self.source_type
170:
171: security.declarePublic('get_period')
172: def get_period(self):
173: return self.period
174:
175:
176: class ECHO_resource(Folder):
177: """ECHO Ressource"""
178: meta_type='ECHO_resource'
179:
1.6 dwinter 180: viewClassificationList=viewClassificationListMaster
1.1 casties 181:
1.6 dwinter 182: def getViewClassification(self):
183: if hasattr(self,'viewClassification'):
184: return self.viewClassification
185: else:
186: return ""
1.13 dwinter 187:
1.9 dwinter 188: def getCredits(self):
189: """Ausgabe der credits"""
190: if self.credits:
191: return self.credits
192: else:
193: return []
1.6 dwinter 194:
1.1 casties 195: def __init__(self,id,link,metalink,title,label,description,content_type,responsible,credits,weight,coords):
196:
197: self.id = id
198: """Festlegen der ID"""
199:
200: self.label = label
201: self.link= link
202: self.metalink=metalink
203: self.title=title
204: self.weight=weight
205: self.credits=toList(credits)
206: self.description=description
207: self.content_type=content_type
208: self.responsible=responsible
1.9 dwinter 209:
210: if coords:
211: coordsnew=[ string.split(x,",") for x in coords]
212: else:
213: coordsnew=[]
214:
1.1 casties 215: self.coords=coordsnew
216:
1.3 dwinter 217:
218: def getCoords(self):
219: try:
1.4 dwinter 220: return [string.join(x,",") for x in self.coords]
1.3 dwinter 221: except:
222: return []
223:
1.1 casties 224:
225: def ECHO_resource_config(self):
226: """Main configuration"""
227:
228: if not hasattr(self,'weight'):
229: self.weight=""
230: if not hasattr(self,'coords'):
231: self.coords=[]
232:
1.13 dwinter 233: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_resource.zpt').__of__(self)
1.1 casties 234: return pt()
235:
236:
1.13 dwinter 237: def changeECHO_resource(self,metalink,link,title,label,description,content_type,responsible,weight,viewClassification="",coords=None,credits=None,RESPONSE=None):
1.10 dwinter 238:
1.1 casties 239:
240: """Änderung der Properties"""
241:
242:
1.13 dwinter 243: setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coords,viewClassification)
1.1 casties 244:
245:
246: self.link=link
247: self.metalink=metalink
248:
249: if RESPONSE is not None:
250: RESPONSE.redirect('manage_main')
251:
252:
253: manage_options = Folder.manage_options+(
254: {'label':'Main Config','action':'ECHO_resource_config'},
255: {'label':'Metadata','action':'ECHO_getResourceMD'},
1.3 dwinter 256: {'label':'Graphics','action':'ECHO_graphicEntry'},
1.1 casties 257: )
258:
1.3 dwinter 259: def ECHO_graphicEntry(self):
260: """DO nothing"""
261: if 'overview' in self.aq_parent.__dict__.keys():
1.13 dwinter 262: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
1.3 dwinter 263: return pt()
264: else:
265: return "NO OVERVIEW GRAPHICS"
266:
1.4 dwinter 267: def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
1.3 dwinter 268: """Enter coords"""
269: coords=self.coords
1.4 dwinter 270: temco=coordstr.split(",")
271: temco.append(angle)
272: coords.append(temco)
273:
1.3 dwinter 274: self.coords=coords[0:]
1.13 dwinter 275:
1.3 dwinter 276: if RESPONSE is not None:
277: RESPONSE.redirect('ECHO_graphicEntry')
278:
1.1 casties 279: def ECHO_getResourceMD(self,template="yes"):
280: """Einlesen der Metadaten und Anlegen dieser Metadaten als Informationen zur Resource"""
281: (metadict, error)=readMetadata(self.metalink)
282:
1.13 dwinter 283:
1.1 casties 284:
285: if not error=="": #Fehler beim Auslesen des Metafiles
286: return "ERROR:",error
287: for key in metadict.keys():#Hinzufügen der Felder
288:
289: setattr(self,key,metadict[key].encode('ascii','replace'))
290:
291:
292: self.metadata=metadict.keys()
1.13 dwinter 293:
1.1 casties 294: self.label=self.generate_label()
295:
296: if template=="yes":
1.13 dwinter 297: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_resourceMD.zpt').__of__(self)
1.1 casties 298: return pt()
299:
300: def ECHO_getMD(self,item):
301: """Ausgabe der MD"""
302: return getattr(self,item)
303:
304: def index_html(self):
305: """standard page"""
306:
307: return self.REQUEST.RESPONSE.redirect(self.link)
308:
309: def generate_label(self):
310: """Erzeugt_standard_Label aus Template"""
311: pt=getattr(self,"label_template_"+self.bib_type)
1.13 dwinter 312:
1.1 casties 313: return pt()
314:
1.13 dwinter 315: def manage_addECHO_resourceForm(self):
316: """Form for adding a ressource"""
317: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_resourceForm.zpt').__of__(self)
1.1 casties 318: return pt()
319:
320:
1.10 dwinter 321:
1.13 dwinter 322: def manage_addECHO_resource(self,id,title,label,description,content_type,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None):
323: """addaresource"""
1.1 casties 324:
325: newObj=ECHO_resource(id,link,metalink,title,label,description,content_type,responsible,credits,weight,coords)
326:
327: self._setObject(id,newObj)
1.13 dwinter 328:
1.1 casties 329: if RESPONSE is not None:
330: RESPONSE.redirect('manage_main')
331:
332:
333: class ECHO_externalLink(Folder):
334: """Link zu einer externen Ressource"""
335: security=ClassSecurityInfo()
336: meta_type='ECHO_externalLink'
337:
338:
339: def __init__(self,id,link,title,label,description,content_type,responsible,credits,weight,coords):
340:
341: self.id = id
342: """Festlegen der ID"""
343:
344: self.credits=toList(credits)
345: self.label = label
346: self.link= link
347: self.title=title
348: self.weight=weight
349: self.description=description
350: self.content_type=content_type
351: self.responsible=responsible
352: coordsnew=[ string.split(x,",") for x in coords]
353: self.coords=coordsnew
354:
355: def ECHO_externalLink_config(self):
356: """Main configuration"""
357:
358: if not hasattr(self,'weight'):
359: self.weight=""
360: if not hasattr(self,'coords'):
1.9 dwinter 361:
1.1 casties 362: self.coords=['']
1.12 dwinter 363: #print "G",self.coords
1.1 casties 364:
1.13 dwinter 365: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_externalLink.zpt').__of__(self)
1.1 casties 366: return pt()
367:
368:
1.13 dwinter 369: def changeECHO_externalLink(self,link,title,label,description,content_type,responsible,weight,coords=None,credits=None,RESPONSE=None):
1.1 casties 370:
371: """Änderung der Properties"""
372:
373:
1.13 dwinter 374: setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coords)
1.1 casties 375:
376:
377: self.link=link
378: if RESPONSE is not None:
379: RESPONSE.redirect('manage_main')
380:
381:
382: manage_options = Folder.manage_options+(
383: {'label':'Main Config','action':'ECHO_externalLink_config'},
384: )
385:
386: def index_html(self):
387: """standard page"""
388:
389: return self.REQUEST.RESPONSE.redirect(self.link)
390:
1.13 dwinter 391: def manage_addECHO_externalLinkForm(self):
392: """Form for external Links"""
393: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_externalLinkForm.zpt').__of__(self)
1.1 casties 394: return pt()
395:
396:
1.13 dwinter 397: def manage_addECHO_externalLink(self,id,title,label,description,content_type,responsible,link,weight,coords=None,credits=None,RESPONSE=None):
398: """Add an external Link"""
1.1 casties 399:
400: newObj=ECHO_externalLink(id,link,title,label,description,content_type,responsible,credits,weight,coords)
401:
402: self._setObject(id,newObj)
1.13 dwinter 403:
1.1 casties 404: if RESPONSE is not None:
405: RESPONSE.redirect('manage_main')
406:
407:
408: class ECHO_collection(Folder, Persistent, Implicit):
409: """ECHO Collection"""
410: security=ClassSecurityInfo()
411: meta_type='ECHO_collection'
412:
413:
414:
415: security.declarePublic('getCreditObject')
416: def getCreditObject(self,name):
417: """credit id to credititem"""
418: return getattr(self.partners,name)
419:
420: security.declarePublic('ECHO_generateNavBar')
421: def ECHO_generateNavBar(self):
422: """Erzeuge Navigationsbar"""
423: link=""
424: object="self"
425: ret=[]
426: path=self.getPhysicalPath()
427: for element in path:
428:
429:
430: if not element=="":
431: object+="."+element
432:
433: label=eval(object).label
434: link+="/"+element
435: if not label=="":
436: ret.append((label,link))
437: return ret
438:
439: security.declarePublic('ECHO_rerenderLinksMD')
440: def ECHO_rerenderLinksMD(self):
441: """Rerender all Links"""
1.13 dwinter 442:
1.1 casties 443: for entry in self.__dict__.keys():
444: object=getattr(self,entry)
445:
446:
447: try:
448:
449: if object.meta_type == 'ECHO_resource':
450:
451: object.ECHO_getResourceMD(template="no")
452:
453: except:
454: """nothing"""
455:
456: return "Rerenderd all links to resources in: "+self.title
457:
458:
459: def getCoords(self):
460: try:
1.11 dwinter 461:
462: x= [string.join(x,",") for x in self.coords]
463: return x
1.4 dwinter 464:
1.11 dwinter 465: except:
1.4 dwinter 466:
1.1 casties 467: return []
1.3 dwinter 468:
1.1 casties 469: def __init__(self,id,title,label,description,content_type,responsible,credits,weight,sortfield,coords):
1.9 dwinter 470: #print "CO",coords
1.1 casties 471:
472: self.id = id
473: """Festlegen der ID"""
474: self.credits=toList(credits)
475: self.label = label
476: self.title=title
477: self.description=description
478: self.content_type=content_type
479: self.responsible=responsible
480:
481: self.weight=weight
482: self.sortfield=sortfield
483: coordsnew=[ string.split(x,",") for x in coords]
484: self.coords=coordsnew
485:
486:
487: manage_options = Folder.manage_options+(
1.13 dwinter 488: {'label':'Main Config','action':'ECHO_collection_config'},
1.1 casties 489: {'label':'Rerender Links','action':'ECHO_rerenderLinksMD'},
490: {'label':'Graphics','action':'ECHO_graphicEntry'},
491:
492: )
493:
494: def ECHO_graphicEntry(self):
495: """DO nothing"""
496: if 'overview' in self.aq_parent.__dict__.keys():
1.13 dwinter 497: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
1.1 casties 498: return pt()
499: else:
500: return "NO OVERVIEW GRAPHICS"
501:
1.4 dwinter 502: def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
1.1 casties 503: """Enter coords"""
1.2 dwinter 504: coords=self.coords
1.4 dwinter 505: temco=coordstr.split(",")
506: temco.append(angle)
507: coords.append(temco)
1.2 dwinter 508: self.coords=coords[0:]
1.13 dwinter 509:
1.2 dwinter 510: if RESPONSE is not None:
511: RESPONSE.redirect('ECHO_graphicEntry')
1.1 casties 512:
513:
1.13 dwinter 514: security.declarePublic('ECHO_collection_config')
515: def ECHO_collection_config(self):
1.1 casties 516: """Main configuration"""
517:
518: if not hasattr(self,'weight'):
519: self.weight=""
520:
521: if not hasattr(self,'sortfield'):
522: self.sortfield="weight"
1.13 dwinter 523:
1.1 casties 524: if not hasattr(self,'coords'):
525: self.coords=[]
526:
1.13 dwinter 527: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_collection.zpt').__of__(self)
1.1 casties 528: return pt()
529:
530:
1.13 dwinter 531: security.declarePublic('changeECHO_collection')
1.1 casties 532:
1.10 dwinter 533:
1.13 dwinter 534: def changeECHO_collection(self,title,label,description,content_type,responsible,weight,credits=None,sortfield="weight",coords=None,RESPONSE=None):
535: """Änderung der Properties"""
1.10 dwinter 536:
1.13 dwinter 537: coordsnew=[ string.split(x,",") for x in coords]
1.1 casties 538:
1.13 dwinter 539: setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coordsnew)
1.1 casties 540:
541: self.sortfield=sortfield
542:
543: if RESPONSE is not None:
544: RESPONSE.redirect('manage_main')
545:
546: security.declarePublic('index_html')
547:
548: showOverview=DTMLFile('ECHO_content_overview',globals())
549:
550:
551: def index_html(self):
552: """standard page"""
553:
554: if 'index.html' in self.__dict__.keys():
555: return getattr(self,'index.html')()
556: elif 'overview' in self.__dict__.keys():
557: return self.showOverview()
558:
559:
1.13 dwinter 560: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_standard.zpt').__of__(self)
1.1 casties 561: pt.content_type="text/html"
562: return pt()
563:
1.11 dwinter 564: def getCredits(self):
565: """Ausgabe der credits"""
566: if self.credits:
567: return self.credits
568: else:
569: return []
1.1 casties 570:
571: def getGraphicCoords(self):
572: """Give list of coordinates"""
573: subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
574: ids=[]
575: for entry in self.__dict__.keys():
576: object=getattr(self,entry)
577: try:
578: if object.meta_type in subColTypes:
1.4 dwinter 579: for coordtemp in object.coords:
580: if len(coordtemp)>3:
581: coord=coordtemp[0:4]
1.3 dwinter 582: if hasattr(object,'title'):
583: if not object.title=="":
584: ids.append([string.join(coord,", "),object.getId(),object.title])
585: else:
586: ids.append([string.join(coord,", "),object.getId(),object.getId()])
587: else:
588: ids.append([string.join(coord,", "),object.getId(),object.getId()])
1.1 casties 589:
590: except:
591: """nothing"""
1.13 dwinter 592:
1.1 casties 593: return ids
594:
595: def getSubCols(self,sortfield="weight"):
596:
597: subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
598: ids=[]
599: for entry in self.__dict__.keys():
600: object=getattr(self,entry)
601: try:
602: if object.meta_type in subColTypes:
603: ids.append(object)
604:
605: except:
606: """nothing"""
607: try:
608: sortfield=self.sortfield
609: except:
610: """nothing"""
611:
612: tmplist=[]
613: for x in ids:
614: if hasattr(x,sortfield):
615: try:
616: x=int(x)
617: except:
618: """nothing"""
619: tmp=getattr(x,sortfield)
620: else:
621: tmp=10000000
622: tmplist.append((tmp,x))
623: tmplist.sort()
624: return [x for (key,x) in tmplist]
625:
626:
627:
628:
629:
630:
1.13 dwinter 631: def manage_addECHO_collectionForm(self):
632: """Add collection form"""
633: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_collectionForm.zpt').__of__(self)
1.1 casties 634: return pt()
635:
636:
1.13 dwinter 637: def manage_addECHO_collection(self,id,title,label,description,content_type,responsible,weight,sortfield,coords="",credits=None,RESPONSE=None):
638: """add a echo collection"""
1.1 casties 639:
640:
641: newObj=ECHO_collection(id,title,label,description,content_type,responsible,credits,weight,sortfield,coords)
642:
643: self._setObject(id,newObj)
1.13 dwinter 644:
1.1 casties 645: if RESPONSE is not None:
646: RESPONSE.redirect('manage_main')
647:
648: class ECHO_root(Folder,Persistent,Implicit):
649: """ECHO Root Folder"""
650: meta_type="ECHO_root"
651:
652: def __init__(self,id,title):
653: """init"""
654: self.id = id
655: self.title=title
1.13 dwinter 656:
1.14 ! dwinter 657: def deleteSpace(self,str):
! 658: """delete space at the end of a line"""
! 659: if str[len(str)-1]==" ":
! 660: return str[0:len(str)-1]
! 661: else:
! 662: return str
! 663:
! 664:
! 665:
! 666: # zusaetliche methoden fuer das vlp muessen in ein eigenes produkt
! 667:
! 668: def formatAscii(self,str,url=None):
! 669: """ersetze ascii umbrueche durch <br>"""
! 670: #url=None
! 671: if url:
! 672:
! 673: retStr=""
! 674: words=str.split("\n")
! 675:
! 676: for word in words:
! 677: strUrl=url%word
! 678: print "str",strUrl
! 679: retStr+="""<a href="%s">%s</a><br/>"""%(strUrl,word)
! 680: str=retStr
! 681: if str:
! 682: return re.sub(r"[\n]","<br/>",str)
! 683: else:
! 684: return ""
! 685:
! 686: def link2html(self,str):
! 687: """link2html fuer VLP muss hier noch raus"""
! 688: if str:
! 689: print str
! 690: str=re.sub("\&","&",str)
! 691: dom=xml.dom.minidom.parseString("<?xml version='1.0' ?><txt>"+str+"</txt>")
! 692: links=dom.getElementsByTagName("link")
! 693:
! 694: print "link",links
! 695: for link in links:
! 696: link.tagName="a"
! 697: ref=link.getAttribute("ref")
! 698: if self.checkRef(ref):
! 699: link.setAttribute("href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref)
! 700:
! 701: return dom.toxml('utf-8')
! 702: return ""
! 703:
! 704:
! 705: def checkRef(self,ref):
! 706: dbs={'vl_literature':'AND CD LIKE \'%lise%\'','vl_technology':'','vl_people':''}
! 707: res=None
! 708: for db in dbs.keys():
! 709: #print ref,"select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])
! 710:
! 711: res=res or self.search(var=str("select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])))
! 712: return res
! 713:
! 714: #Ende Methode fuer vlp
! 715:
1.13 dwinter 716: def PgQuoteString(self,string):
717: """Quote string"""
1.14 ! dwinter 718: #print "PG",string
1.13 dwinter 719: return libpq.PgQuoteString(string)
1.1 casties 720:
721: def getPartners(self):
722: """Get list of Partners. Presently only from a subfolder partners"""
723: partnerTypes=['ECHO_partner']
724: ids=[]
1.13 dwinter 725: try:
726: for entry in self.partners.__dict__.keys():
727: object=getattr(self.partners,entry)
728:
729: try:
1.1 casties 730:
1.13 dwinter 731: if object.meta_type in partnerTypes:
732: ids.append(object)
1.1 casties 733:
1.13 dwinter 734: except:
735: """nothing"""
736: except:
737: ids=[] # no partners
1.1 casties 738: return ids
739:
740: def getCollectionTree(self):
741: """get the collection tree (list of triples (parent,child, depth)"""
742:
743: def getCollection(object,depth=0):
744: depth+=1
745: collections=[]
746: for entry in object.__dict__.keys():
747: element=getattr(object,entry)
748: try:
749: if element.meta_type=="ECHO_collection":
750: collections.append((object,element,depth))
751: collections+=getCollection(element,depth)
752: except:
753: """nothing"""
754: return collections
755:
756:
757: return getCollection(self)
758:
759: def getCollectionTreeIds(self):
760: """Show the IDs of the Tree"""
761: ret=[]
762: for collection in self.getCollectionTree():
763: ret.append((collection[0].getId(),collection[1].getId(),collection[2]))
764: return ret
765:
766:
767:
1.13 dwinter 768: def manage_addECHO_root(self,id,title,RESPONSE=None):
1.1 casties 769: """Add an ECHO_root"""
770: self._setObject(id,ECHO_root(id,title))
771:
772: if RESPONSE is not None:
773: RESPONSE.redirect('manage_main')
774:
1.13 dwinter 775: def manage_addECHO_rootForm(self):
1.1 casties 776: """Nothing yet"""
1.13 dwinter 777: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_root.zpt').__of__(self)
1.1 casties 778: return pt()
779:
780: class ECHO_partner(Image,Persistent):
781: """ECHO Partner"""
782:
783: meta_type="ECHO_partner"
784:
785: def __init__(self, id, title,url, file, content_type='', precondition=''):
786: self.__name__=id
787: self.title=title
788: self.url=url
789: self.precondition=precondition
790:
791: data, size = self._read_data(file)
792: content_type=self._get_content_type(file, data, id, content_type)
793: self.update_data(data, content_type, size)
794:
795: manage_options = Image.manage_options+(
796: {'label':'Partner Information','action':'ECHO_partner_config'},
797: )
798:
799: def changeECHO_partner(self,url,RESPONSE=None):
800: """Change main information"""
801: self.url=url
802: if RESPONSE is not None:
803: RESPONSE.redirect('manage_main')
804:
805:
806:
807: def ECHO_partner_config(self):
808: """Main configuration"""
809: if not hasattr(self,'url'):
810: self.url=""
1.13 dwinter 811: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_partner.zpt').__of__(self)
1.1 casties 812: return pt()
813:
814:
1.13 dwinter 815: manage_addECHO_partnerForm=DTMLFile('dtml/ECHO_partnerAdd',globals(),
1.1 casties 816: Kind='ECHO_partner',kind='ECHO_partner')
817:
818:
819:
1.13 dwinter 820: def manage_addECHO_partner(self, id, file,url, title='', precondition='', content_type='',
1.1 casties 821: REQUEST=None):
822: """
823: Add a new ECHO_partner object.
824:
825: Creates a new ECHO_partner object 'id' with the contents of 'file'.
826: Based on Image.manage_addImage
827: """
828:
829: id=str(id)
830: title=str(title)
831: content_type=str(content_type)
832: precondition=str(precondition)
833:
834: id, title = OFS.Image.cookId(id, title, file)
835:
836: self=self.this()
837:
838: # First, we create the image without data:
839: self._setObject(id, ECHO_partner(id,title,url,'',content_type, precondition))
840:
841: # Now we "upload" the data. By doing this in two steps, we
842: # can use a database trick to make the upload more efficient.
843: if file:
844: self._getOb(id).manage_upload(file)
845: if content_type:
846: self._getOb(id).content_type=content_type
847:
848: if REQUEST is not None:
849: try: url=self.DestinationURL()
850: except: url=REQUEST['URL1']
851: REQUEST.RESPONSE.redirect('%s/manage_main' % url)
852: return id
853:
854:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>