Annotation of ECHO_content/ECHO_collection.py, revision 1.15

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

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