Annotation of ECHO_content/ECHO_collection.py, revision 1.2

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: 
                    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: 
1.2     ! dwinter   457:     def ECHO_enterCoords(self,coordstr,RESPONSE=None):
1.1       casties   458:         """Enter coords"""
1.2     ! dwinter   459:         coords=self.coords
        !           460:         coords.append(coordstr.split(","))
        !           461:         self.coords=coords[0:]
        !           462:         #pt=PageTemplateFile('Products/ECHO_content/ECHO_draw.zpt').__of__(self)
        !           463:         if RESPONSE is not None:
        !           464:             RESPONSE.redirect('ECHO_graphicEntry')
1.1       casties   465: 
                    466:     
                    467:     security.declarePublic('ECHO_Collection_config')
                    468:     def ECHO_Collection_config(self):
                    469:         """Main configuration"""
                    470: 
                    471:         if not hasattr(self,'weight'):
                    472:             self.weight=""
                    473: 
                    474:         if not hasattr(self,'sortfield'):
                    475:             self.sortfield="weight"
                    476:         #print "HI"
                    477:         if not hasattr(self,'coords'):
                    478:             self.coords=[]
                    479: 
                    480:         pt=PageTemplateFile('Products/ECHO_content/ChangeECHO_Collection.zpt').__of__(self)
                    481:         return pt()
                    482: 
                    483: 
                    484:     security.declarePublic('changeECHO_Collection')
                    485: 
                    486:     def changeECHO_Collection(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coords,sortfield="weight",RESPONSE=None):
                    487: 
                    488:         """Änderung der Properties"""
                    489: 
                    490:         coordsnew=[ string.split(x,",") for x in coords]
                    491:         setECHO_CollectionInformation(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coordsnew)
                    492: 
                    493:         self.sortfield=sortfield
                    494: 
                    495:         if RESPONSE is not None:
                    496:             RESPONSE.redirect('manage_main')
                    497:             
                    498:     security.declarePublic('index_html')
                    499: 
                    500:     showOverview=DTMLFile('ECHO_content_overview',globals())
                    501:     
                    502:     
                    503:     def index_html(self):
                    504:         """standard page"""
                    505:         #print self.objectIDs()
                    506:         
                    507:         if 'index.html' in self.__dict__.keys():
                    508:             return getattr(self,'index.html')()
                    509:         elif 'overview' in self.__dict__.keys():
1.2     ! dwinter   510:             print "HI"
1.1       casties   511:             return self.showOverview()
                    512:             
                    513:         
                    514:         pt=PageTemplateFile('Products/ECHO_content/ECHO_content_standard.zpt').__of__(self)
                    515:         pt.content_type="text/html"
                    516:         return pt()
                    517: 
                    518: 
                    519:     def getGraphicCoords(self):
                    520:         """Give list of coordinates"""
                    521:         subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
                    522:         ids=[]
                    523:         for entry in self.__dict__.keys():
                    524:             object=getattr(self,entry)
                    525:             #print "OB:",object
                    526:             
                    527:             try:
                    528:                 print "MT:",object.meta_type
                    529:                 if object.meta_type in subColTypes:
                    530:                     for coord in object.coords:
                    531:                         if len(coord)==4:
                    532:                             ids.append([string.join(coord,", "),object.getId()])
                    533:                         
                    534:                     
                    535:             except:
                    536:                 """nothing"""
1.2     ! dwinter   537:         #print "IDS",ids
1.1       casties   538:         return ids
                    539:     
                    540:     def getSubCols(self,sortfield="weight"):
                    541: 
                    542:         subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
                    543:         ids=[]
                    544:         for entry in self.__dict__.keys():
                    545:             object=getattr(self,entry)
                    546:             #print "OB:",object
                    547:             
                    548:             try:
                    549:                 #print "MT:",object.meta_type
                    550:                 if object.meta_type in subColTypes:
                    551:                     ids.append(object)
                    552:                     
                    553:             except:
                    554:                 """nothing"""
                    555:         try:
                    556:             sortfield=self.sortfield
                    557:         except:
                    558:             """nothing"""
                    559:             
                    560:         tmplist=[]
                    561:         for x in ids:
                    562:             if hasattr(x,sortfield):
                    563:                 try:
                    564:                     x=int(x)
                    565:                 except:
                    566:                     """nothing"""
                    567:                 tmp=getattr(x,sortfield)
                    568:             else:
                    569:                 tmp=10000000
                    570:             tmplist.append((tmp,x))
                    571:         tmplist.sort()
                    572:         return [x for (key,x) in tmplist]
                    573:      
                    574:         
                    575:         
                    576:                 
                    577:     
                    578:     
                    579: def manage_AddECHO_collectionForm(self):
                    580:         """Nothing yet"""
                    581:         pt=PageTemplateFile('Products/ECHO_content/AddECHO_collectionForm.zpt').__of__(self)
                    582:         return pt()
                    583: 
                    584: 
                    585: def manage_AddECHO_collection(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,sortfield,coords,RESPONSE=None):
                    586: 
                    587:     """nothing yet"""
                    588:     scientificClassificationObj=scientificClassification(context,science,practice)
                    589:     
                    590:     scientificInformationObj=scientificInformation(source_type,period)
                    591:     
                    592: 
                    593:     newObj=ECHO_collection(id,title,label,description,content_type,responsible,credits,weight,sortfield,coords)
                    594: 
                    595:     self._setObject(id,newObj)
                    596:     getattr(self,id)._setObject('scientific_Information',scientificInformationObj)
                    597:     getattr(self,id).scientific_Information._setObject('scientific_Classification',scientificClassificationObj)
                    598:     if RESPONSE is not None:
                    599:         RESPONSE.redirect('manage_main')
                    600: 
                    601: class ECHO_root(Folder,Persistent,Implicit):
                    602:     """ECHO Root Folder"""
                    603:     meta_type="ECHO_root"
                    604: 
                    605:     def __init__(self,id,title):
                    606:         """init"""
                    607:         self.id = id
                    608:         self.title=title
                    609:         
                    610:     def getPartners(self):
                    611:         """Get list of Partners. Presently only from a subfolder partners"""
                    612:         partnerTypes=['ECHO_partner']
                    613:         ids=[]
                    614:         for entry in self.partners.__dict__.keys():
                    615:             object=getattr(self.partners,entry)
                    616:             
                    617:             try:
                    618:                 
                    619:                 if object.meta_type in partnerTypes:
                    620:                     ids.append(object)
                    621:                     
                    622:             except:
                    623:                 """nothing"""
                    624:         return ids
                    625: 
                    626:     def getCollectionTree(self):
                    627:         """get the collection tree (list of triples (parent,child, depth)"""
                    628: 
                    629:         def getCollection(object,depth=0):
                    630:             depth+=1
                    631:             collections=[]
                    632:             for entry in object.__dict__.keys():
                    633:                 element=getattr(object,entry)
                    634:                 try:
                    635:                     if element.meta_type=="ECHO_collection":
                    636:                         collections.append((object,element,depth))
                    637:                         collections+=getCollection(element,depth)
                    638:                 except:
                    639:                     """nothing"""
                    640:             return collections
                    641:         
                    642: 
                    643:         return getCollection(self)
                    644:     
                    645:     def getCollectionTreeIds(self):
                    646:         """Show the IDs of the Tree"""
                    647:         ret=[]
                    648:         for collection in self.getCollectionTree():
                    649:             ret.append((collection[0].getId(),collection[1].getId(),collection[2]))
                    650:         return ret
                    651: 
                    652:         
                    653:         
                    654: def manage_AddECHO_root(self,id,title,RESPONSE=None):
                    655:     """Add an ECHO_root"""
                    656:     self._setObject(id,ECHO_root(id,title))
                    657:     
                    658:     if RESPONSE is not None:
                    659:         RESPONSE.redirect('manage_main')
                    660: 
                    661: def manage_AddECHO_rootForm(self):
                    662:         """Nothing yet"""
                    663:         pt=PageTemplateFile('Products/ECHO_content/AddECHO_root.zpt').__of__(self)
                    664:         return pt()
                    665:  
                    666: class ECHO_partner(Image,Persistent):
                    667:     """ECHO Partner"""
                    668: 
                    669:     meta_type="ECHO_partner"
                    670: 
                    671:     def __init__(self, id, title,url, file, content_type='', precondition=''):
                    672:         self.__name__=id
                    673:         self.title=title
                    674:         self.url=url
                    675:         self.precondition=precondition
                    676: 
                    677:         data, size = self._read_data(file)
                    678:         content_type=self._get_content_type(file, data, id, content_type)
                    679:         self.update_data(data, content_type, size)
                    680: 
                    681:     manage_options = Image.manage_options+(
                    682:         {'label':'Partner Information','action':'ECHO_partner_config'},
                    683:         )
                    684: 
                    685:     def changeECHO_partner(self,url,RESPONSE=None):
                    686:         """Change main information"""
                    687:         self.url=url
                    688:         if RESPONSE is not None:
                    689:             RESPONSE.redirect('manage_main')
                    690:             
                    691:             
                    692: 
                    693:     def ECHO_partner_config(self):
                    694:         """Main configuration"""
                    695:         if not hasattr(self,'url'):
                    696:             self.url=""
                    697:         pt=PageTemplateFile('Products/ECHO_content/ChangeECHO_partner.zpt').__of__(self)
                    698:         return pt()
                    699: 
                    700:         
                    701: manage_AddECHO_partnerForm=DTMLFile('ECHO_partnerAdd',globals(),
                    702:                              Kind='ECHO_partner',kind='ECHO_partner')
                    703: 
                    704: 
                    705: 
                    706: def manage_AddECHO_partner(self, id, file,url, title='', precondition='', content_type='',
                    707:                     REQUEST=None):
                    708:     """
                    709:     Add a new ECHO_partner object.
                    710: 
                    711:     Creates a new ECHO_partner object 'id' with the contents of 'file'.
                    712:     Based on Image.manage_addImage
                    713:     """
                    714: 
                    715:     id=str(id)
                    716:     title=str(title)
                    717:     content_type=str(content_type)
                    718:     precondition=str(precondition)
                    719: 
                    720:     id, title = OFS.Image.cookId(id, title, file)
                    721: 
                    722:     self=self.this()
                    723: 
                    724:     # First, we create the image without data:
                    725:     self._setObject(id, ECHO_partner(id,title,url,'',content_type, precondition))
                    726: 
                    727:     # Now we "upload" the data.  By doing this in two steps, we
                    728:     # can use a database trick to make the upload more efficient.
                    729:     if file:
                    730:         self._getOb(id).manage_upload(file)
                    731:     if content_type:
                    732:         self._getOb(id).content_type=content_type
                    733: 
                    734:     if REQUEST is not None:
                    735:         try:    url=self.DestinationURL()
                    736:         except: url=REQUEST['URL1']
                    737:         REQUEST.RESPONSE.redirect('%s/manage_main' % url)
                    738:     return id
                    739: 
                    740: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>