File:  [Repository] / ECHO_content / ECHO_collection.py
Revision 1.8: download - view: text, annotated - select for diffs - revision graph
Wed Jan 14 16:09:36 2004 UTC (20 years, 5 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD

bug fixes

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

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