Annotation of ECHO_content/ECHO_collection.py, revision 1.13

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

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