![]() ![]() | ![]() |
Neu-Import wegen Problemen im repository...
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: 184: 185: 186: def ECHO_resource_config(self): 187: """Main configuration""" 188: 189: if not hasattr(self,'weight'): 190: self.weight="" 191: if not hasattr(self,'coords'): 192: self.coords=[] 193: 194: pt=PageTemplateFile('Products/ECHO_content/ChangeECHO_resource.zpt').__of__(self) 195: return pt() 196: 197: 198: def changeECHO_resource(self,metalink,link,context,science,practice,source_type,period,title,label,description,content_type,responsible,credits,weight,coords,RESPONSE=None): 199: 200: """Änderung der Properties""" 201: 202: 203: setECHO_CollectionInformation(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coords) 204: 205: 206: self.link=link 207: self.metalink=metalink 208: 209: if RESPONSE is not None: 210: RESPONSE.redirect('manage_main') 211: 212: 213: manage_options = Folder.manage_options+( 214: {'label':'Main Config','action':'ECHO_resource_config'}, 215: {'label':'Metadata','action':'ECHO_getResourceMD'}, 216: 217: ) 218: 219: 220: def ECHO_getResourceMD(self,template="yes"): 221: """Einlesen der Metadaten und Anlegen dieser Metadaten als Informationen zur Resource""" 222: (metadict, error)=readMetadata(self.metalink) 223: 224: #print "BLA" 225: 226: if not error=="": #Fehler beim Auslesen des Metafiles 227: return "ERROR:",error 228: for key in metadict.keys():#Hinzufügen der Felder 229: 230: setattr(self,key,metadict[key].encode('ascii','replace')) 231: 232: 233: self.metadata=metadict.keys() 234: #return "BLUccssB" 235: self.label=self.generate_label() 236: 237: if template=="yes": 238: pt=PageTemplateFile('Products/ECHO_content/ECHO_resourceMD.zpt').__of__(self) 239: return pt() 240: 241: def ECHO_getMD(self,item): 242: """Ausgabe der MD""" 243: return getattr(self,item) 244: 245: def index_html(self): 246: """standard page""" 247: 248: return self.REQUEST.RESPONSE.redirect(self.link) 249: 250: def generate_label(self): 251: """Erzeugt_standard_Label aus Template""" 252: pt=getattr(self,"label_template_"+self.bib_type) 253: #return pt 254: #pt.content_type="text/html; charset=utf-8" 255: return pt() 256: 257: def manage_AddECHO_resourceForm(self): 258: """Nothing yet""" 259: pt=PageTemplateFile('Products/ECHO_content/AddECHO_resourceForm.zpt').__of__(self) 260: return pt() 261: 262: 263: 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): 264: 265: """nothing yet""" 266: scientificClassificationObj=scientificClassification(context,science,practice) 267: 268: scientificInformationObj=scientificInformation(source_type,period) 269: 270: 271: newObj=ECHO_resource(id,link,metalink,title,label,description,content_type,responsible,credits,weight,coords) 272: 273: self._setObject(id,newObj) 274: getattr(self,id)._setObject('scientific_Information',scientificInformationObj) 275: getattr(self,id).scientific_Information._setObject('scientific_Classification',scientificClassificationObj) 276: if RESPONSE is not None: 277: RESPONSE.redirect('manage_main') 278: 279: 280: class ECHO_externalLink(Folder): 281: """Link zu einer externen Ressource""" 282: security=ClassSecurityInfo() 283: meta_type='ECHO_externalLink' 284: 285: 286: def __init__(self,id,link,title,label,description,content_type,responsible,credits,weight,coords): 287: 288: self.id = id 289: """Festlegen der ID""" 290: 291: self.credits=toList(credits) 292: self.label = label 293: self.link= link 294: self.title=title 295: self.weight=weight 296: self.description=description 297: self.content_type=content_type 298: self.responsible=responsible 299: coordsnew=[ string.split(x,",") for x in coords] 300: self.coords=coordsnew 301: 302: def ECHO_externalLink_config(self): 303: """Main configuration""" 304: 305: if not hasattr(self,'weight'): 306: self.weight="" 307: if not hasattr(self,'coords'): 308: print "HI" 309: self.coords=[''] 310: print "G",self.coords 311: 312: pt=PageTemplateFile('Products/ECHO_content/ChangeECHO_externalLink.zpt').__of__(self) 313: return pt() 314: 315: 316: def changeECHO_externalLink(self,link,context,science,practice,source_type,period,title,label,description,content_type,responsible,credits,weight,coords,RESPONSE=None): 317: 318: """Änderung der Properties""" 319: 320: 321: setECHO_CollectionInformation(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coords) 322: 323: 324: self.link=link 325: if RESPONSE is not None: 326: RESPONSE.redirect('manage_main') 327: 328: 329: manage_options = Folder.manage_options+( 330: {'label':'Main Config','action':'ECHO_externalLink_config'}, 331: ) 332: 333: def index_html(self): 334: """standard page""" 335: 336: return self.REQUEST.RESPONSE.redirect(self.link) 337: 338: def manage_AddECHO_externalLinkForm(self): 339: """Nothing yet""" 340: pt=PageTemplateFile('Products/ECHO_content/AddECHO_externalLinkForm.zpt').__of__(self) 341: return pt() 342: 343: 344: def manage_AddECHO_externalLink(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,link,credits,weight,coords,RESPONSE=None): 345: 346: """nothing yet""" 347: scientificClassificationObj=scientificClassification(context,science,practice) 348: 349: scientificInformationObj=scientificInformation(source_type,period) 350: 351: 352: newObj=ECHO_externalLink(id,link,title,label,description,content_type,responsible,credits,weight,coords) 353: 354: self._setObject(id,newObj) 355: getattr(self,id)._setObject('scientific_Information',scientificInformationObj) 356: getattr(self,id).scientific_Information._setObject('scientific_Classification',scientificClassificationObj) 357: if RESPONSE is not None: 358: RESPONSE.redirect('manage_main') 359: 360: 361: class ECHO_collection(Folder, Persistent, Implicit): 362: """ECHO Collection""" 363: security=ClassSecurityInfo() 364: meta_type='ECHO_collection' 365: 366: 367: 368: security.declarePublic('getCreditObject') 369: def getCreditObject(self,name): 370: """credit id to credititem""" 371: return getattr(self.partners,name) 372: 373: security.declarePublic('ECHO_generateNavBar') 374: def ECHO_generateNavBar(self): 375: """Erzeuge Navigationsbar""" 376: link="" 377: object="self" 378: ret=[] 379: path=self.getPhysicalPath() 380: for element in path: 381: 382: 383: if not element=="": 384: object+="."+element 385: 386: label=eval(object).label 387: link+="/"+element 388: if not label=="": 389: ret.append((label,link)) 390: return ret 391: 392: security.declarePublic('ECHO_rerenderLinksMD') 393: def ECHO_rerenderLinksMD(self): 394: """Rerender all Links""" 395: #print "HI" 396: #return "OK" 397: for entry in self.__dict__.keys(): 398: object=getattr(self,entry) 399: 400: 401: try: 402: 403: if object.meta_type == 'ECHO_resource': 404: 405: object.ECHO_getResourceMD(template="no") 406: 407: except: 408: """nothing""" 409: 410: return "Rerenderd all links to resources in: "+self.title 411: 412: 413: 414: security.declarePublic('printall') 415: def printall(self): 416: return self.scientific_information.__dict__.keys() 417: 418: 419: def getCoords(self): 420: try: 421: return [ string.join(x,",") for x in self.coords] 422: except: 423: return [] 424: def __init__(self,id,title,label,description,content_type,responsible,credits,weight,sortfield,coords): 425: print "CO",coords 426: 427: self.id = id 428: """Festlegen der ID""" 429: self.credits=toList(credits) 430: self.label = label 431: self.title=title 432: self.description=description 433: self.content_type=content_type 434: self.responsible=responsible 435: 436: self.weight=weight 437: self.sortfield=sortfield 438: coordsnew=[ string.split(x,",") for x in coords] 439: self.coords=coordsnew 440: 441: 442: manage_options = Folder.manage_options+( 443: {'label':'Main Config','action':'ECHO_Collection_config'}, 444: {'label':'Rerender Links','action':'ECHO_rerenderLinksMD'}, 445: {'label':'Graphics','action':'ECHO_graphicEntry'}, 446: 447: ) 448: 449: def ECHO_graphicEntry(self): 450: """DO nothing""" 451: if 'overview' in self.aq_parent.__dict__.keys(): 452: pt=PageTemplateFile('Products/ECHO_content/ECHO_draw.zpt').__of__(self) 453: return pt() 454: else: 455: return "NO OVERVIEW GRAPHICS" 456: 457: def ECHO_enterCoords(self,coordstr): 458: """Enter coords""" 459: self.coords.append(coordstr.split(",")) 460: pt=PageTemplateFile('Products/ECHO_content/ECHO_draw.zpt').__of__(self) 461: return pt() 462: 463: 464: security.declarePublic('ECHO_Collection_config') 465: def ECHO_Collection_config(self): 466: """Main configuration""" 467: 468: if not hasattr(self,'weight'): 469: self.weight="" 470: 471: if not hasattr(self,'sortfield'): 472: self.sortfield="weight" 473: #print "HI" 474: if not hasattr(self,'coords'): 475: self.coords=[] 476: 477: pt=PageTemplateFile('Products/ECHO_content/ChangeECHO_Collection.zpt').__of__(self) 478: return pt() 479: 480: 481: security.declarePublic('changeECHO_Collection') 482: 483: def changeECHO_Collection(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coords,sortfield="weight",RESPONSE=None): 484: 485: """Änderung der Properties""" 486: 487: coordsnew=[ string.split(x,",") for x in coords] 488: setECHO_CollectionInformation(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coordsnew) 489: 490: self.sortfield=sortfield 491: 492: if RESPONSE is not None: 493: RESPONSE.redirect('manage_main') 494: 495: security.declarePublic('index_html') 496: 497: showOverview=DTMLFile('ECHO_content_overview',globals()) 498: 499: 500: def index_html(self): 501: """standard page""" 502: #print self.objectIDs() 503: 504: if 'index.html' in self.__dict__.keys(): 505: return getattr(self,'index.html')() 506: elif 'overview' in self.__dict__.keys(): 507: return self.showOverview() 508: 509: 510: pt=PageTemplateFile('Products/ECHO_content/ECHO_content_standard.zpt').__of__(self) 511: pt.content_type="text/html" 512: return pt() 513: 514: 515: def getGraphicCoords(self): 516: """Give list of coordinates""" 517: subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource'] 518: ids=[] 519: for entry in self.__dict__.keys(): 520: object=getattr(self,entry) 521: #print "OB:",object 522: 523: try: 524: print "MT:",object.meta_type 525: if object.meta_type in subColTypes: 526: for coord in object.coords: 527: if len(coord)==4: 528: ids.append([string.join(coord,", "),object.getId()]) 529: 530: 531: except: 532: """nothing""" 533: print "IDS",ids 534: return ids 535: 536: def getSubCols(self,sortfield="weight"): 537: 538: subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource'] 539: ids=[] 540: for entry in self.__dict__.keys(): 541: object=getattr(self,entry) 542: #print "OB:",object 543: 544: try: 545: #print "MT:",object.meta_type 546: if object.meta_type in subColTypes: 547: ids.append(object) 548: 549: except: 550: """nothing""" 551: try: 552: sortfield=self.sortfield 553: except: 554: """nothing""" 555: 556: tmplist=[] 557: for x in ids: 558: if hasattr(x,sortfield): 559: try: 560: x=int(x) 561: except: 562: """nothing""" 563: tmp=getattr(x,sortfield) 564: else: 565: tmp=10000000 566: tmplist.append((tmp,x)) 567: tmplist.sort() 568: return [x for (key,x) in tmplist] 569: 570: 571: 572: 573: 574: 575: def manage_AddECHO_collectionForm(self): 576: """Nothing yet""" 577: pt=PageTemplateFile('Products/ECHO_content/AddECHO_collectionForm.zpt').__of__(self) 578: return pt() 579: 580: 581: def manage_AddECHO_collection(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,sortfield,coords,RESPONSE=None): 582: 583: """nothing yet""" 584: scientificClassificationObj=scientificClassification(context,science,practice) 585: 586: scientificInformationObj=scientificInformation(source_type,period) 587: 588: 589: newObj=ECHO_collection(id,title,label,description,content_type,responsible,credits,weight,sortfield,coords) 590: 591: self._setObject(id,newObj) 592: getattr(self,id)._setObject('scientific_Information',scientificInformationObj) 593: getattr(self,id).scientific_Information._setObject('scientific_Classification',scientificClassificationObj) 594: if RESPONSE is not None: 595: RESPONSE.redirect('manage_main') 596: 597: class ECHO_root(Folder,Persistent,Implicit): 598: """ECHO Root Folder""" 599: meta_type="ECHO_root" 600: 601: def __init__(self,id,title): 602: """init""" 603: self.id = id 604: self.title=title 605: 606: def getPartners(self): 607: """Get list of Partners. Presently only from a subfolder partners""" 608: partnerTypes=['ECHO_partner'] 609: ids=[] 610: for entry in self.partners.__dict__.keys(): 611: object=getattr(self.partners,entry) 612: 613: try: 614: 615: if object.meta_type in partnerTypes: 616: ids.append(object) 617: 618: except: 619: """nothing""" 620: return ids 621: 622: def getCollectionTree(self): 623: """get the collection tree (list of triples (parent,child, depth)""" 624: 625: def getCollection(object,depth=0): 626: depth+=1 627: collections=[] 628: for entry in object.__dict__.keys(): 629: element=getattr(object,entry) 630: try: 631: if element.meta_type=="ECHO_collection": 632: collections.append((object,element,depth)) 633: collections+=getCollection(element,depth) 634: except: 635: """nothing""" 636: return collections 637: 638: 639: return getCollection(self) 640: 641: def getCollectionTreeIds(self): 642: """Show the IDs of the Tree""" 643: ret=[] 644: for collection in self.getCollectionTree(): 645: ret.append((collection[0].getId(),collection[1].getId(),collection[2])) 646: return ret 647: 648: 649: 650: def manage_AddECHO_root(self,id,title,RESPONSE=None): 651: """Add an ECHO_root""" 652: self._setObject(id,ECHO_root(id,title)) 653: 654: if RESPONSE is not None: 655: RESPONSE.redirect('manage_main') 656: 657: def manage_AddECHO_rootForm(self): 658: """Nothing yet""" 659: pt=PageTemplateFile('Products/ECHO_content/AddECHO_root.zpt').__of__(self) 660: return pt() 661: 662: class ECHO_partner(Image,Persistent): 663: """ECHO Partner""" 664: 665: meta_type="ECHO_partner" 666: 667: def __init__(self, id, title,url, file, content_type='', precondition=''): 668: self.__name__=id 669: self.title=title 670: self.url=url 671: self.precondition=precondition 672: 673: data, size = self._read_data(file) 674: content_type=self._get_content_type(file, data, id, content_type) 675: self.update_data(data, content_type, size) 676: 677: manage_options = Image.manage_options+( 678: {'label':'Partner Information','action':'ECHO_partner_config'}, 679: ) 680: 681: def changeECHO_partner(self,url,RESPONSE=None): 682: """Change main information""" 683: self.url=url 684: if RESPONSE is not None: 685: RESPONSE.redirect('manage_main') 686: 687: 688: 689: def ECHO_partner_config(self): 690: """Main configuration""" 691: if not hasattr(self,'url'): 692: self.url="" 693: pt=PageTemplateFile('Products/ECHO_content/ChangeECHO_partner.zpt').__of__(self) 694: return pt() 695: 696: 697: manage_AddECHO_partnerForm=DTMLFile('ECHO_partnerAdd',globals(), 698: Kind='ECHO_partner',kind='ECHO_partner') 699: 700: 701: 702: def manage_AddECHO_partner(self, id, file,url, title='', precondition='', content_type='', 703: REQUEST=None): 704: """ 705: Add a new ECHO_partner object. 706: 707: Creates a new ECHO_partner object 'id' with the contents of 'file'. 708: Based on Image.manage_addImage 709: """ 710: 711: id=str(id) 712: title=str(title) 713: content_type=str(content_type) 714: precondition=str(precondition) 715: 716: id, title = OFS.Image.cookId(id, title, file) 717: 718: self=self.this() 719: 720: # First, we create the image without data: 721: self._setObject(id, ECHO_partner(id,title,url,'',content_type, precondition)) 722: 723: # Now we "upload" the data. By doing this in two steps, we 724: # can use a database trick to make the upload more efficient. 725: if file: 726: self._getOb(id).manage_upload(file) 727: if content_type: 728: self._getOb(id).content_type=content_type 729: 730: if REQUEST is not None: 731: try: url=self.DestinationURL() 732: except: url=REQUEST['URL1'] 733: REQUEST.RESPONSE.redirect('%s/manage_main' % url) 734: return id 735: 736: