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: class ECHO_collection(Folder, Persistent, Implicit):
425: """ECHO Collection"""
426: security=ClassSecurityInfo()
427: meta_type='ECHO_collection'
428:
429: def createJavaScript(self):
430: """CreateJava"""
431: ret=javaScriptMain
432:
433: dynamical=""
434: for ob in self.getGraphicCoords():
435: dynamical+="""Coords.push(new Coord('%s', Img, %s));\n"""%(ob[1],ob[0])
436: ret+=javaHandler%dynamical
437: return ret
438:
439: security.declarePublic('getCreditObject')
440: def getCreditObject(self,name):
441: """credit id to credititem"""
442: try:
443: return getattr(self.partners,name)
444: except:
445: return ""
446:
447: security.declarePublic('ECHO_generateNavBar')
448: def ECHO_generateNavBar(self):
449: """Erzeuge Navigationsbar"""
450: link=""
451: object="self"
452: ret=[]
453: path=self.getPhysicalPath()
454: for element in path:
455:
456:
457: if not element=="":
458: object+="."+element
459:
460: label=eval(object).label
461: link+="/"+element
462: if not label=="":
463: ret.append((label,link))
464: return ret
465:
466: security.declarePublic('ECHO_rerenderLinksMD')
467: def ECHO_rerenderLinksMD(self):
468: """Rerender all Links"""
469:
470: for entry in self.__dict__.keys():
471: object=getattr(self,entry)
472:
473:
474: try:
475:
476: if object.meta_type == 'ECHO_resource':
477:
478: object.ECHO_getResourceMD(template="no")
479:
480: except:
481: """nothing"""
482:
483: return "Rerenderd all links to resources in: "+self.title
484:
485: security.declarePublic('ECHO_newViewerLink')
486:
487:
488: def getCoords(self):
489: try:
490:
491: x= [string.join(x,",") for x in self.coords]
492: return x
493:
494: except:
495:
496: return []
497:
498: def __init__(self,id,title,label,description,content_type,responsible,credits,weight,sortfield,coords):
499: #print "CO",coords
500:
501: self.id = id
502: """Festlegen der ID"""
503: self.credits=toList(credits)
504: self.label = label
505: self.title=title
506: self.description=description
507: self.content_type=content_type
508: self.responsible=responsible
509:
510: self.weight=weight
511: self.sortfield=sortfield
512: coordsnew=[ string.split(x,",") for x in coords]
513: self.coords=coordsnew
514:
515:
516: manage_options = Folder.manage_options+(
517: {'label':'Main Config','action':'ECHO_collection_config'},
518: {'label':'Rerender Links','action':'ECHO_rerenderLinksMD'},
519: {'label':'Graphics','action':'ECHO_graphicEntry'},
520:
521: )
522:
523: def getOverview(self):
524: """overview graphics"""
525:
526: return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
527:
528:
529: def ECHO_graphicEntry(self):
530: """DO nothing"""
531: overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
532:
533:
534: if overview:
535: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
536: return pt()
537: else:
538: return "NO OVERVIEW GRAPHICS"
539:
540: def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
541: """Enter coords"""
542: coords=self.coords
543: temco=coordstr.split(",")
544: temco.append(angle)
545: coords.append(temco)
546: self.coords=coords[0:]
547:
548: if RESPONSE is not None:
549: RESPONSE.redirect('ECHO_graphicEntry')
550:
551:
552: security.declarePublic('ECHO_collection_config')
553: def ECHO_collection_config(self):
554: """Main configuration"""
555:
556: if not hasattr(self,'weight'):
557: self.weight=""
558:
559: if not hasattr(self,'sortfield'):
560: self.sortfield="weight"
561:
562: if not hasattr(self,'coords'):
563: self.coords=[]
564:
565: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_collection.zpt').__of__(self)
566: return pt()
567:
568:
569: security.declarePublic('changeECHO_collection')
570:
571:
572: def changeECHO_collection(self,title,label,description,content_type,responsible,weight,credits=None,sortfield="weight",coords=None,RESPONSE=None):
573: """Änderung der Properties"""
574:
575:
576: coordsnew=[ string.split(x,",") for x in coords]
577:
578: setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coordsnew)
579:
580: self.coords=coordsnew[0:]
581: self.sortfield=sortfield
582:
583: if RESPONSE is not None:
584: RESPONSE.redirect('manage_main')
585:
586: security.declarePublic('index_html')
587:
588:
589: def showOverview(self):
590: """overview"""
591: if 'ECHO_overview.html' in self.__dict__.keys():
592: return getattr(self,'ECHO_overview.html')()
593: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_overview.zpt').__of__(self)
594: return pt()
595:
596:
597: def index_html(self):
598: """standard page"""
599:
600: if 'index.html' in self.__dict__.keys():
601: return getattr(self,'index.html')()
602: elif 'overview' in self.__dict__.keys():
603: return self.showOverview()
604:
605:
606: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_standard.zpt').__of__(self)
607: pt.content_type="text/html"
608: return pt()
609:
610: def getCredits(self):
611: """Ausgabe der credits"""
612: if self.credits:
613: return self.credits
614: else:
615: return []
616:
617:
618:
619: def getGraphicCoords(self):
620: """Give list of coordinates"""
621: subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
622: ids=[]
623: for entry in self.__dict__.keys():
624: object=getattr(self,entry)
625: try:
626: if object.meta_type in subColTypes:
627: for coordtemp in object.coords:
628: if len(coordtemp)>3:
629: coord=coordtemp[0:4]
630: if hasattr(object,'label') and not object.label=="":
631: ids.append([string.join(coord,", "),object.getId(),object.label,object])
632: elif hasattr(object,'title'):
633: if not object.title=="":
634: ids.append([string.join(coord,", "),object.getId(),object.title,object])
635: else:
636: ids.append([string.join(coord,", "),object.getId(),object.getId(),object])
637: else:
638: ids.append([string.join(coord,", "),object.getId(),object.getId(),object])
639:
640: except:
641: """nothing"""
642:
643: return ids
644:
645: def getSubCols(self,sortfield="weight"):
646:
647: subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
648: ids=[]
649: for entry in self.__dict__.keys():
650: object=getattr(self,entry)
651: try:
652: if object.meta_type in subColTypes:
653: ids.append(object)
654:
655: except:
656: """nothing"""
657: try:
658: sortfield=self.sortfield
659: except:
660: """nothing"""
661:
662: tmplist=[]
663: for x in ids:
664: if hasattr(x,sortfield):
665: try:
666: x=int(x)
667: except:
668: """nothing"""
669: tmp=getattr(x,sortfield)
670: else:
671: tmp=10000000
672: tmplist.append((tmp,x))
673: tmplist.sort()
674: return [x for (key,x) in tmplist]
675:
676:
677:
678:
679:
680:
681: def manage_addECHO_collectionForm(self):
682: """Add collection form"""
683: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_collectionForm.zpt').__of__(self)
684: return pt()
685:
686:
687: def manage_addECHO_collection(self,id,title,label,description,content_type,responsible,weight,sortfield,coords="",credits=None,RESPONSE=None):
688: """add a echo collection"""
689:
690:
691: newObj=ECHO_collection(id,title,label,description,content_type,responsible,credits,weight,sortfield,coords)
692:
693: self._setObject(id,newObj)
694:
695: if RESPONSE is not None:
696: RESPONSE.redirect('manage_main')
697:
698: class ECHO_root(Folder,Persistent,Implicit):
699: """ECHO Root Folder"""
700: meta_type="ECHO_root"
701:
702:
703:
704: def ECHO_newViewerLink(self,obj=None):
705: """change links (:86 faellt weg)"""
706:
707: if not obj:
708: obj = self
709:
710: entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection'])
711:
712: for entry in entries:
713:
714: if entry[1].meta_type == 'ECHO_resource':
715:
716: entry[1].link=re.sub('\:86','',entry[1].link)
717:
718: else:
719:
720: entry[1].ECHO_newViewerLink(entry[1])
721:
722: return "Rerenderd all links to resources in: "+self.title
723:
724: def __init__(self,id,title):
725: """init"""
726: self.id = id
727: self.title=title
728:
729: def deleteSpace(self,str):
730: """delete space at the end of a line"""
731: if str[len(str)-1]==" ":
732: return str[0:len(str)-1]
733: else:
734: return str
735:
736:
737:
738: # zusaetliche methoden fuer das vlp muessen in ein eigenes produkt
739:
740: def formatAscii(self,str,url=None):
741: """ersetze ascii umbrueche durch <br>"""
742: #url=None
743: if url:
744:
745: retStr=""
746: words=str.split("\n")
747:
748: for word in words:
749: strUrl=url%word
750: print "str",strUrl
751: retStr+="""<a href="%s">%s</a><br/>"""%(strUrl,word)
752: str=retStr
753: if str:
754: return re.sub(r"[\n]","<br/>",str)
755: else:
756: return ""
757:
758: def link2html(self,str):
759: """link2html fuer VLP muss hier noch raus"""
760: if str:
761: print str
762: str=re.sub("\&","&",str)
763: dom=xml.dom.minidom.parseString("<?xml version='1.0' ?><txt>"+str+"</txt>")
764: links=dom.getElementsByTagName("link")
765:
766: print "link",links
767: for link in links:
768: link.tagName="a"
769: ref=link.getAttribute("ref")
770: if self.checkRef(ref):
771: link.setAttribute("href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref)
772:
773: return dom.toxml('utf-8')
774: return ""
775:
776:
777: def checkRef(self,ref):
778: dbs={'vl_literature':'AND CD LIKE \'%lise%\'','vl_technology':'','vl_people':''}
779: res=None
780: for db in dbs.keys():
781: #print ref,"select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])
782:
783: res=res or self.search(var=str("select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])))
784: return res
785:
786: #Ende Methode fuer vlp
787:
788: def PgQuoteString(self,string):
789: """Quote string"""
790: #print "PG",string
791: return libpq.PgQuoteString(string)
792:
793: def getPartners(self):
794: """Get list of Partners. Presently only from a subfolder partners"""
795: partnerTypes=['ECHO_partner']
796: ids=[]
797: try:
798: for entry in self.partners.__dict__.keys():
799: object=getattr(self.partners,entry)
800:
801: try:
802:
803: if object.meta_type in partnerTypes:
804: ids.append(object)
805:
806: except:
807: """nothing"""
808: except:
809: ids=[] # no partners
810: return ids
811:
812: def getCollectionTree(self):
813: """get the collection tree (list of triples (parent,child, depth)"""
814:
815: def getCollection(object,depth=0):
816: depth+=1
817: collections=[]
818: for entry in object.__dict__.keys():
819: element=getattr(object,entry)
820: try:
821: if element.meta_type=="ECHO_collection":
822: collections.append((object,element,depth))
823: collections+=getCollection(element,depth)
824: except:
825: """nothing"""
826: return collections
827:
828:
829: return getCollection(self)
830:
831: def getCollectionTreeIds(self):
832: """Show the IDs of the Tree"""
833: ret=[]
834: for collection in self.getCollectionTree():
835: ret.append((collection[0].getId(),collection[1].getId(),collection[2]))
836: return ret
837:
838:
839:
840: def manage_addECHO_root(self,id,title,RESPONSE=None):
841: """Add an ECHO_root"""
842: self._setObject(id,ECHO_root(id,title))
843:
844: if RESPONSE is not None:
845: RESPONSE.redirect('manage_main')
846:
847: def manage_addECHO_rootForm(self):
848: """Nothing yet"""
849: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_root.zpt').__of__(self)
850: return pt()
851:
852: class ECHO_partner(Image,Persistent):
853: """ECHO Partner"""
854:
855: meta_type="ECHO_partner"
856:
857: def __init__(self, id, title,url, file, content_type='', precondition=''):
858: self.__name__=id
859: self.title=title
860: self.url=url
861: self.precondition=precondition
862:
863: data, size = self._read_data(file)
864: content_type=self._get_content_type(file, data, id, content_type)
865: self.update_data(data, content_type, size)
866:
867: manage_options = Image.manage_options+(
868: {'label':'Partner Information','action':'ECHO_partner_config'},
869: )
870:
871: def changeECHO_partner(self,url,RESPONSE=None):
872: """Change main information"""
873: self.url=url
874: if RESPONSE is not None:
875: RESPONSE.redirect('manage_main')
876:
877:
878:
879: def ECHO_partner_config(self):
880: """Main configuration"""
881: if not hasattr(self,'url'):
882: self.url=""
883: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_partner.zpt').__of__(self)
884: return pt()
885:
886:
887: manage_addECHO_partnerForm=DTMLFile('dtml/ECHO_partnerAdd',globals(),
888: Kind='ECHO_partner',kind='ECHO_partner')
889:
890:
891:
892: def manage_addECHO_partner(self, id, file,url, title='', precondition='', content_type='',
893: REQUEST=None):
894: """
895: Add a new ECHO_partner object.
896:
897: Creates a new ECHO_partner object 'id' with the contents of 'file'.
898: Based on Image.manage_addImage
899: """
900:
901: id=str(id)
902: title=str(title)
903: content_type=str(content_type)
904: precondition=str(precondition)
905:
906: id, title = OFS.Image.cookId(id, title, file)
907:
908: self=self.this()
909:
910: # First, we create the image without data:
911: self._setObject(id, ECHO_partner(id,title,url,'',content_type, precondition))
912:
913: # Now we "upload" the data. By doing this in two steps, we
914: # can use a database trick to make the upload more efficient.
915: if file:
916: self._getOb(id).manage_upload(file)
917: if content_type:
918: self._getOb(id).content_type=content_type
919:
920: if REQUEST is not None:
921: try: url=self.DestinationURL()
922: except: url=REQUEST['URL1']
923: REQUEST.RESPONSE.redirect('%s/manage_main' % url)
924: return id
925:
926:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>