Annotation of ECHO_content/ECHO_collection.py, revision 1.3
1.1 casties 1:
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: """
13: import string
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:
28:
29: import urllib
30: import xml.dom.minidom
31:
32:
33: def toList(field):
34: """Einzelfeld in Liste umwandeln"""
35: if type(field)==StringType:
36: return [field]
37: else:
38: return field
39:
40: def getText(nodelist):
41:
42: rc = ""
43: for node in nodelist:
44: if node.nodeType == node.TEXT_NODE:
45: rc = rc + node.data
46: return rc
47:
48:
49: def readMetadata(url):
50: """Methoden zum Auslesen der Metadateninformation zu einer Resource
51: Vorerst noch Typ bib"""
52:
53: metadict={}
54: try:
55: geturl=""
56: for line in urllib.urlopen(url).readlines():
57: geturl=geturl+line
58:
59:
60: except:
61: return (None,"Cannot open: "+url)
62:
63: try:
64: dom=xml.dom.minidom.parseString(geturl)
65: except:
66: return (None,"Cannot parse: "+url+"<br>"+geturl)
67:
68: metanode=dom.getElementsByTagName('bib')
69: metadict['bib_type']='Book'
70: if len(metanode)==0:
71: metanode=dom.getElementsByTagName('archimedes')
72: metadict['bib_type']='Archimedes'
73: #print "HELLO"
74:
75: if not len(metanode)==0:
76: metacontent=metanode[0].childNodes
77:
78: try:
79: metadict['bib_type']=getText(dom.getElementsByTagName('bib')[0].attributes['type'].childNodes)
80: except:
81: """nothing"""
82:
83: for node in metacontent:
84: try:
85: metadict[node.tagName.lower()]=getText(node.childNodes)
86: except:
87: """nothing"""
88:
89: #print metadict
90: return metadict,""
91:
92:
93: def setECHO_CollectionInformation(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coords):
94:
95: """Allegemeine Informationen zu einer ECHO Collection"""
96:
97: self.label = label
98: self.title=title
99: self.description=description
100: self.content_type=content_type
101: self.responsible=responsible
102: self.credits=toList(credits)
103: self.weight=weight
104:
105: self.scientific_Information.source_type=source_type
106: self.scientific_Information.period=period
107: self.scientific_Information.scientific_Classification.context=context
108: self.scientific_Information.scientific_Classification.science=science
109: self.scientific_Information.scientific_Classification.practice=practice
110:
111:
112: #coordinates of for rectangles
113: self.coords=coords
114:
115:
116: class scientificClassification(SimpleItem,Persistent,Implicit):
117: """subclass"""
118: security=ClassSecurityInfo()
119:
120: def __init__(self,context,science,practice):
121: self.context=context
122: self.science=science
123: self.practice=practice
124: self.id="scientific_Classification"
125:
126: security.declarePublic('get_context')
127: def get_context(self):
128: return self.context
129:
130: security.declarePublic('get_science')
131: def get_science(self):
132: return self.science
133:
134: security.declarePublic('get_practice')
135: def get_practice(self):
136: return self.practice
137:
138:
139: class scientificInformation(Folder,Persistent,Implicit):
140: """subclass scientificInformation"""
141: security=ClassSecurityInfo()
142:
143:
144:
145: def __init__(self,source_type,period):
146:
147: self.id="scientific_Information"
148: self.source_type=source_type
149: self.period=period
150:
151:
152:
153: security.declarePublic('get_source_type')
154: def get_source_type(self):
155: return self.source_type
156:
157: security.declarePublic('get_period')
158: def get_period(self):
159: return self.period
160:
161:
162: class ECHO_resource(Folder):
163: """ECHO Ressource"""
164: meta_type='ECHO_resource'
165:
166:
167: def __init__(self,id,link,metalink,title,label,description,content_type,responsible,credits,weight,coords):
168:
169: self.id = id
170: """Festlegen der ID"""
171:
172: self.label = label
173: self.link= link
174: self.metalink=metalink
175: self.title=title
176: self.weight=weight
177: self.credits=toList(credits)
178: self.description=description
179: self.content_type=content_type
180: self.responsible=responsible
181: coordsnew=[ string.split(x,",") for x in coords]
182: self.coords=coordsnew
183:
1.3 ! dwinter 184:
! 185: def getCoords(self):
! 186: try:
! 187: return [ string.join(x,",") for x in self.coords]
! 188: except:
! 189: return []
! 190:
1.1 casties 191:
192: def ECHO_resource_config(self):
193: """Main configuration"""
194:
195: if not hasattr(self,'weight'):
196: self.weight=""
197: if not hasattr(self,'coords'):
198: self.coords=[]
199:
200: pt=PageTemplateFile('Products/ECHO_content/ChangeECHO_resource.zpt').__of__(self)
201: return pt()
202:
203:
204: def changeECHO_resource(self,metalink,link,context,science,practice,source_type,period,title,label,description,content_type,responsible,credits,weight,coords,RESPONSE=None):
205:
206: """Änderung der Properties"""
207:
208:
209: setECHO_CollectionInformation(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coords)
210:
211:
212: self.link=link
213: self.metalink=metalink
214:
215: if RESPONSE is not None:
216: RESPONSE.redirect('manage_main')
217:
218:
219: manage_options = Folder.manage_options+(
220: {'label':'Main Config','action':'ECHO_resource_config'},
221: {'label':'Metadata','action':'ECHO_getResourceMD'},
1.3 ! dwinter 222: {'label':'Graphics','action':'ECHO_graphicEntry'},
1.1 casties 223: )
224:
1.3 ! dwinter 225: def ECHO_graphicEntry(self):
! 226: """DO nothing"""
! 227: if 'overview' in self.aq_parent.__dict__.keys():
! 228: pt=PageTemplateFile('Products/ECHO_content/ECHO_draw.zpt').__of__(self)
! 229: return pt()
! 230: else:
! 231: return "NO OVERVIEW GRAPHICS"
! 232:
! 233: def ECHO_enterCoords(self,coordstr,RESPONSE=None):
! 234: """Enter coords"""
! 235: coords=self.coords
! 236: coords.append(coordstr.split(","))
! 237: self.coords=coords[0:]
! 238: #pt=PageTemplateFile('Products/ECHO_content/ECHO_draw.zpt').__of__(self)
! 239: if RESPONSE is not None:
! 240: RESPONSE.redirect('ECHO_graphicEntry')
! 241:
1.1 casties 242: def ECHO_getResourceMD(self,template="yes"):
243: """Einlesen der Metadaten und Anlegen dieser Metadaten als Informationen zur Resource"""
244: (metadict, error)=readMetadata(self.metalink)
245:
246: #print "BLA"
247:
248: if not error=="": #Fehler beim Auslesen des Metafiles
249: return "ERROR:",error
250: for key in metadict.keys():#Hinzufügen der Felder
251:
252: setattr(self,key,metadict[key].encode('ascii','replace'))
253:
254:
255: self.metadata=metadict.keys()
256: #return "BLUccssB"
257: self.label=self.generate_label()
258:
259: if template=="yes":
260: pt=PageTemplateFile('Products/ECHO_content/ECHO_resourceMD.zpt').__of__(self)
261: return pt()
262:
263: def ECHO_getMD(self,item):
264: """Ausgabe der MD"""
265: return getattr(self,item)
266:
267: def index_html(self):
268: """standard page"""
269:
270: return self.REQUEST.RESPONSE.redirect(self.link)
271:
272: def generate_label(self):
273: """Erzeugt_standard_Label aus Template"""
274: pt=getattr(self,"label_template_"+self.bib_type)
275: #return pt
276: #pt.content_type="text/html; charset=utf-8"
277: return pt()
278:
279: def manage_AddECHO_resourceForm(self):
280: """Nothing yet"""
281: pt=PageTemplateFile('Products/ECHO_content/AddECHO_resourceForm.zpt').__of__(self)
282: return pt()
283:
284:
285: def manage_AddECHO_resource(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,link,metalink,credits,weight,coords,RESPONSE=None):
286:
287: """nothing yet"""
288: scientificClassificationObj=scientificClassification(context,science,practice)
289:
290: scientificInformationObj=scientificInformation(source_type,period)
291:
292:
293: newObj=ECHO_resource(id,link,metalink,title,label,description,content_type,responsible,credits,weight,coords)
294:
295: self._setObject(id,newObj)
296: getattr(self,id)._setObject('scientific_Information',scientificInformationObj)
297: getattr(self,id).scientific_Information._setObject('scientific_Classification',scientificClassificationObj)
298: if RESPONSE is not None:
299: RESPONSE.redirect('manage_main')
300:
301:
302: class ECHO_externalLink(Folder):
303: """Link zu einer externen Ressource"""
304: security=ClassSecurityInfo()
305: meta_type='ECHO_externalLink'
306:
307:
308: def __init__(self,id,link,title,label,description,content_type,responsible,credits,weight,coords):
309:
310: self.id = id
311: """Festlegen der ID"""
312:
313: self.credits=toList(credits)
314: self.label = label
315: self.link= link
316: self.title=title
317: self.weight=weight
318: self.description=description
319: self.content_type=content_type
320: self.responsible=responsible
321: coordsnew=[ string.split(x,",") for x in coords]
322: self.coords=coordsnew
323:
324: def ECHO_externalLink_config(self):
325: """Main configuration"""
326:
327: if not hasattr(self,'weight'):
328: self.weight=""
329: if not hasattr(self,'coords'):
330: print "HI"
331: self.coords=['']
332: print "G",self.coords
333:
334: pt=PageTemplateFile('Products/ECHO_content/ChangeECHO_externalLink.zpt').__of__(self)
335: return pt()
336:
337:
338: def changeECHO_externalLink(self,link,context,science,practice,source_type,period,title,label,description,content_type,responsible,credits,weight,coords,RESPONSE=None):
339:
340: """Änderung der Properties"""
341:
342:
343: setECHO_CollectionInformation(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coords)
344:
345:
346: self.link=link
347: if RESPONSE is not None:
348: RESPONSE.redirect('manage_main')
349:
350:
351: manage_options = Folder.manage_options+(
352: {'label':'Main Config','action':'ECHO_externalLink_config'},
353: )
354:
355: def index_html(self):
356: """standard page"""
357:
358: return self.REQUEST.RESPONSE.redirect(self.link)
359:
360: def manage_AddECHO_externalLinkForm(self):
361: """Nothing yet"""
362: pt=PageTemplateFile('Products/ECHO_content/AddECHO_externalLinkForm.zpt').__of__(self)
363: return pt()
364:
365:
366: def manage_AddECHO_externalLink(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,link,credits,weight,coords,RESPONSE=None):
367:
368: """nothing yet"""
369: scientificClassificationObj=scientificClassification(context,science,practice)
370:
371: scientificInformationObj=scientificInformation(source_type,period)
372:
373:
374: newObj=ECHO_externalLink(id,link,title,label,description,content_type,responsible,credits,weight,coords)
375:
376: self._setObject(id,newObj)
377: getattr(self,id)._setObject('scientific_Information',scientificInformationObj)
378: getattr(self,id).scientific_Information._setObject('scientific_Classification',scientificClassificationObj)
379: if RESPONSE is not None:
380: RESPONSE.redirect('manage_main')
381:
382:
383: class ECHO_collection(Folder, Persistent, Implicit):
384: """ECHO Collection"""
385: security=ClassSecurityInfo()
386: meta_type='ECHO_collection'
387:
388:
389:
390: security.declarePublic('getCreditObject')
391: def getCreditObject(self,name):
392: """credit id to credititem"""
393: return getattr(self.partners,name)
394:
395: security.declarePublic('ECHO_generateNavBar')
396: def ECHO_generateNavBar(self):
397: """Erzeuge Navigationsbar"""
398: link=""
399: object="self"
400: ret=[]
401: path=self.getPhysicalPath()
402: for element in path:
403:
404:
405: if not element=="":
406: object+="."+element
407:
408: label=eval(object).label
409: link+="/"+element
410: if not label=="":
411: ret.append((label,link))
412: return ret
413:
414: security.declarePublic('ECHO_rerenderLinksMD')
415: def ECHO_rerenderLinksMD(self):
416: """Rerender all Links"""
417: #print "HI"
418: #return "OK"
419: for entry in self.__dict__.keys():
420: object=getattr(self,entry)
421:
422:
423: try:
424:
425: if object.meta_type == 'ECHO_resource':
426:
427: object.ECHO_getResourceMD(template="no")
428:
429: except:
430: """nothing"""
431:
432: return "Rerenderd all links to resources in: "+self.title
433:
434:
435:
436: security.declarePublic('printall')
437: def printall(self):
438: return self.scientific_information.__dict__.keys()
439:
440:
441: def getCoords(self):
442: try:
443: return [ string.join(x,",") for x in self.coords]
444: except:
445: return []
1.3 ! dwinter 446:
1.1 casties 447: def __init__(self,id,title,label,description,content_type,responsible,credits,weight,sortfield,coords):
448: print "CO",coords
449:
450: self.id = id
451: """Festlegen der ID"""
452: self.credits=toList(credits)
453: self.label = label
454: self.title=title
455: self.description=description
456: self.content_type=content_type
457: self.responsible=responsible
458:
459: self.weight=weight
460: self.sortfield=sortfield
461: coordsnew=[ string.split(x,",") for x in coords]
462: self.coords=coordsnew
463:
464:
465: manage_options = Folder.manage_options+(
466: {'label':'Main Config','action':'ECHO_Collection_config'},
467: {'label':'Rerender Links','action':'ECHO_rerenderLinksMD'},
468: {'label':'Graphics','action':'ECHO_graphicEntry'},
469:
470: )
471:
472: def ECHO_graphicEntry(self):
473: """DO nothing"""
474: if 'overview' in self.aq_parent.__dict__.keys():
475: pt=PageTemplateFile('Products/ECHO_content/ECHO_draw.zpt').__of__(self)
476: return pt()
477: else:
478: return "NO OVERVIEW GRAPHICS"
479:
1.2 dwinter 480: def ECHO_enterCoords(self,coordstr,RESPONSE=None):
1.1 casties 481: """Enter coords"""
1.2 dwinter 482: coords=self.coords
483: coords.append(coordstr.split(","))
484: self.coords=coords[0:]
485: #pt=PageTemplateFile('Products/ECHO_content/ECHO_draw.zpt').__of__(self)
486: if RESPONSE is not None:
487: RESPONSE.redirect('ECHO_graphicEntry')
1.1 casties 488:
489:
490: security.declarePublic('ECHO_Collection_config')
491: def ECHO_Collection_config(self):
492: """Main configuration"""
493:
494: if not hasattr(self,'weight'):
495: self.weight=""
496:
497: if not hasattr(self,'sortfield'):
498: self.sortfield="weight"
499: #print "HI"
500: if not hasattr(self,'coords'):
501: self.coords=[]
502:
503: pt=PageTemplateFile('Products/ECHO_content/ChangeECHO_Collection.zpt').__of__(self)
504: return pt()
505:
506:
507: security.declarePublic('changeECHO_Collection')
508:
509: def changeECHO_Collection(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coords,sortfield="weight",RESPONSE=None):
510:
511: """Änderung der Properties"""
512:
513: coordsnew=[ string.split(x,",") for x in coords]
514: setECHO_CollectionInformation(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coordsnew)
515:
516: self.sortfield=sortfield
517:
518: if RESPONSE is not None:
519: RESPONSE.redirect('manage_main')
520:
521: security.declarePublic('index_html')
522:
523: showOverview=DTMLFile('ECHO_content_overview',globals())
524:
525:
526: def index_html(self):
527: """standard page"""
528: #print self.objectIDs()
529:
530: if 'index.html' in self.__dict__.keys():
531: return getattr(self,'index.html')()
532: elif 'overview' in self.__dict__.keys():
1.3 ! dwinter 533: #print "HI"
1.1 casties 534: return self.showOverview()
535:
536:
537: pt=PageTemplateFile('Products/ECHO_content/ECHO_content_standard.zpt').__of__(self)
538: pt.content_type="text/html"
539: return pt()
540:
541:
542: def getGraphicCoords(self):
543: """Give list of coordinates"""
544: subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
545: ids=[]
546: for entry in self.__dict__.keys():
547: object=getattr(self,entry)
548: #print "OB:",object
549:
550: try:
1.3 ! dwinter 551: #print "MT:",object.meta_type
1.1 casties 552: if object.meta_type in subColTypes:
1.3 ! dwinter 553: #print "MT:",object.meta_type,object.getId()
1.1 casties 554: for coord in object.coords:
555: if len(coord)==4:
1.3 ! dwinter 556: if hasattr(object,'title'):
! 557: if not object.title=="":
! 558: ids.append([string.join(coord,", "),object.getId(),object.title])
! 559: else:
! 560: ids.append([string.join(coord,", "),object.getId(),object.getId()])
! 561: else:
! 562: ids.append([string.join(coord,", "),object.getId(),object.getId()])
1.1 casties 563:
564: except:
565: """nothing"""
1.2 dwinter 566: #print "IDS",ids
1.1 casties 567: return ids
568:
569: def getSubCols(self,sortfield="weight"):
570:
571: subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
572: ids=[]
573: for entry in self.__dict__.keys():
574: object=getattr(self,entry)
575: #print "OB:",object
576:
577: try:
578: #print "MT:",object.meta_type
579: if object.meta_type in subColTypes:
580: ids.append(object)
581:
582: except:
583: """nothing"""
584: try:
585: sortfield=self.sortfield
586: except:
587: """nothing"""
588:
589: tmplist=[]
590: for x in ids:
591: if hasattr(x,sortfield):
592: try:
593: x=int(x)
594: except:
595: """nothing"""
596: tmp=getattr(x,sortfield)
597: else:
598: tmp=10000000
599: tmplist.append((tmp,x))
600: tmplist.sort()
601: return [x for (key,x) in tmplist]
602:
603:
604:
605:
606:
607:
608: def manage_AddECHO_collectionForm(self):
609: """Nothing yet"""
610: pt=PageTemplateFile('Products/ECHO_content/AddECHO_collectionForm.zpt').__of__(self)
611: return pt()
612:
613:
614: def manage_AddECHO_collection(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,sortfield,coords,RESPONSE=None):
615:
616: """nothing yet"""
617: scientificClassificationObj=scientificClassification(context,science,practice)
618:
619: scientificInformationObj=scientificInformation(source_type,period)
620:
621:
622: newObj=ECHO_collection(id,title,label,description,content_type,responsible,credits,weight,sortfield,coords)
623:
624: self._setObject(id,newObj)
625: getattr(self,id)._setObject('scientific_Information',scientificInformationObj)
626: getattr(self,id).scientific_Information._setObject('scientific_Classification',scientificClassificationObj)
627: if RESPONSE is not None:
628: RESPONSE.redirect('manage_main')
629:
630: class ECHO_root(Folder,Persistent,Implicit):
631: """ECHO Root Folder"""
632: meta_type="ECHO_root"
633:
634: def __init__(self,id,title):
635: """init"""
636: self.id = id
637: self.title=title
638:
639: def getPartners(self):
640: """Get list of Partners. Presently only from a subfolder partners"""
641: partnerTypes=['ECHO_partner']
642: ids=[]
643: for entry in self.partners.__dict__.keys():
644: object=getattr(self.partners,entry)
645:
646: try:
647:
648: if object.meta_type in partnerTypes:
649: ids.append(object)
650:
651: except:
652: """nothing"""
653: return ids
654:
655: def getCollectionTree(self):
656: """get the collection tree (list of triples (parent,child, depth)"""
657:
658: def getCollection(object,depth=0):
659: depth+=1
660: collections=[]
661: for entry in object.__dict__.keys():
662: element=getattr(object,entry)
663: try:
664: if element.meta_type=="ECHO_collection":
665: collections.append((object,element,depth))
666: collections+=getCollection(element,depth)
667: except:
668: """nothing"""
669: return collections
670:
671:
672: return getCollection(self)
673:
674: def getCollectionTreeIds(self):
675: """Show the IDs of the Tree"""
676: ret=[]
677: for collection in self.getCollectionTree():
678: ret.append((collection[0].getId(),collection[1].getId(),collection[2]))
679: return ret
680:
681:
682:
683: def manage_AddECHO_root(self,id,title,RESPONSE=None):
684: """Add an ECHO_root"""
685: self._setObject(id,ECHO_root(id,title))
686:
687: if RESPONSE is not None:
688: RESPONSE.redirect('manage_main')
689:
690: def manage_AddECHO_rootForm(self):
691: """Nothing yet"""
692: pt=PageTemplateFile('Products/ECHO_content/AddECHO_root.zpt').__of__(self)
693: return pt()
694:
695: class ECHO_partner(Image,Persistent):
696: """ECHO Partner"""
697:
698: meta_type="ECHO_partner"
699:
700: def __init__(self, id, title,url, file, content_type='', precondition=''):
701: self.__name__=id
702: self.title=title
703: self.url=url
704: self.precondition=precondition
705:
706: data, size = self._read_data(file)
707: content_type=self._get_content_type(file, data, id, content_type)
708: self.update_data(data, content_type, size)
709:
710: manage_options = Image.manage_options+(
711: {'label':'Partner Information','action':'ECHO_partner_config'},
712: )
713:
714: def changeECHO_partner(self,url,RESPONSE=None):
715: """Change main information"""
716: self.url=url
717: if RESPONSE is not None:
718: RESPONSE.redirect('manage_main')
719:
720:
721:
722: def ECHO_partner_config(self):
723: """Main configuration"""
724: if not hasattr(self,'url'):
725: self.url=""
726: pt=PageTemplateFile('Products/ECHO_content/ChangeECHO_partner.zpt').__of__(self)
727: return pt()
728:
729:
730: manage_AddECHO_partnerForm=DTMLFile('ECHO_partnerAdd',globals(),
731: Kind='ECHO_partner',kind='ECHO_partner')
732:
733:
734:
735: def manage_AddECHO_partner(self, id, file,url, title='', precondition='', content_type='',
736: REQUEST=None):
737: """
738: Add a new ECHO_partner object.
739:
740: Creates a new ECHO_partner object 'id' with the contents of 'file'.
741: Based on Image.manage_addImage
742: """
743:
744: id=str(id)
745: title=str(title)
746: content_type=str(content_type)
747: precondition=str(precondition)
748:
749: id, title = OFS.Image.cookId(id, title, file)
750:
751: self=self.this()
752:
753: # First, we create the image without data:
754: self._setObject(id, ECHO_partner(id,title,url,'',content_type, precondition))
755:
756: # Now we "upload" the data. By doing this in two steps, we
757: # can use a database trick to make the upload more efficient.
758: if file:
759: self._getOb(id).manage_upload(file)
760: if content_type:
761: self._getOb(id).content_type=content_type
762:
763: if REQUEST is not None:
764: try: url=self.DestinationURL()
765: except: url=REQUEST['URL1']
766: REQUEST.RESPONSE.redirect('%s/manage_main' % url)
767: return id
768:
769:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>