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