Annotation of ECHO_content/ECHO_collection.py, revision 1.10

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

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