File:  [Repository] / ECHO_content / ECHO_collection.py
Revision 1.18: download - view: text, annotated - select for diffs - revision graph
Tue Mar 23 12:58:24 2004 UTC (20 years, 2 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
remove some files (html/dtml)

    1: """New version of the product started February, 8th. Without scientific classification, use content-type for further classification."""
    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 re
   14: import OFS.Image
   15: from types import *
   16: from OFS.Image import Image
   17: from Globals import DTMLFile
   18: from OFS.Folder import Folder
   19: from OFS.SimpleItem import SimpleItem
   20: from AccessControl import ClassSecurityInfo
   21: from Globals import InitializeClass
   22: from Globals import DTMLFile
   23: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
   24: from Products.PageTemplates.PageTemplate import PageTemplate
   25: from Globals import Persistent
   26: from Acquisition import Implicit
   27: #from psycopg import libpq
   28: #from pyPgSQL import libpq
   29: import xml.dom.minidom
   30: 
   31: import urllib
   32: import xml.dom.minidom
   33: 
   34: 
   35: #List of different types for the graphical linking viewer
   36: viewClassificationListMaster=['view point','area']
   37: 
   38: 
   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: 
   99: def setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coordstrs,viewClassification=""):
  100: 
  101:         """Allegemeine Informationen zu einer ECHO Collection"""
  102: 
  103:         self.viewClassification=viewClassification
  104: 
  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: 
  113:         coords=[]
  114:         #coordinates of for rectangles
  115: 
  116:         #print "cs", coordstrs
  117:         if coordstrs:
  118:             for coordstr in coordstrs:
  119:                 #print "cs", coordstr
  120:                 try:
  121:                     temco=coordstr.split(",")
  122:                 except:
  123:                     temco=[]
  124:                 #temco.append(angle)
  125:                 coords.append(temco)
  126: 
  127: 
  128:         self.coords=coords[0:]
  129:             
  130: 
  131: class scientificClassification(SimpleItem,Persistent,Implicit):
  132:     """outdated will be deleeted in the next versions: subclass"""
  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):
  155:     """outdated will be deleted in the next versions: subclass scientificInformation"""
  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: 
  181:     viewClassificationList=viewClassificationListMaster
  182: 
  183:     def getViewClassification(self):
  184:         if hasattr(self,'viewClassification'):
  185:             return self.viewClassification
  186:         else:
  187:             return ""
  188:         
  189:     def getCredits(self):
  190:         """Ausgabe der credits"""
  191:         if self.credits:
  192:             return self.credits
  193:         else:
  194:             return []
  195:     
  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
  210:         
  211:         if coords:
  212:             coordsnew=[ string.split(x,",") for x in coords]
  213:         else:
  214:             coordsnew=[]
  215:         
  216:         self.coords=coordsnew
  217: 
  218: 
  219:     def getCoords(self):
  220:         try:
  221:             return [string.join(x,",") for x in self.coords]  
  222:         except:
  223:             return []
  224: 
  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: 
  234:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_resource.zpt').__of__(self)
  235:         return pt()
  236:     
  237: 
  238:     def changeECHO_resource(self,metalink,link,title,label,description,content_type,responsible,weight,viewClassification="",coords=None,credits=None,RESPONSE=None):
  239: 
  240: 
  241:         """Änderung der Properties"""
  242:         
  243: 
  244:         setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coords,viewClassification)
  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'},
  257:         {'label':'Graphics','action':'ECHO_graphicEntry'},
  258:         )
  259: 
  260:     def ECHO_graphicEntry(self):
  261:         """DO nothing"""
  262:         if 'overview' in self.aq_parent.__dict__.keys():
  263:             pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
  264:             return pt()
  265:         else:
  266:             return "NO OVERVIEW GRAPHICS"
  267: 
  268:     def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
  269:         """Enter coords"""
  270:         coords=self.coords
  271:         temco=coordstr.split(",")
  272:         temco.append(angle)
  273:         coords.append(temco)
  274:         
  275:         self.coords=coords[0:]
  276: 
  277:         if RESPONSE is not None:
  278:             RESPONSE.redirect('ECHO_graphicEntry')
  279: 
  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: 
  284: 
  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()
  294: 
  295:         self.label=self.generate_label()
  296:         
  297:         if template=="yes":
  298:             pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_resourceMD.zpt').__of__(self)
  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)
  313: 
  314:         return pt()
  315: 
  316: def manage_addECHO_resourceForm(self):
  317:         """Form for adding a ressource"""
  318:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_resourceForm.zpt').__of__(self)
  319:         return pt()
  320: 
  321: 
  322: 
  323: def manage_addECHO_resource(self,id,title,label,description,content_type,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None):
  324:     """addaresource"""
  325: 
  326:     newObj=ECHO_resource(id,link,metalink,title,label,description,content_type,responsible,credits,weight,coords)
  327: 
  328:     self._setObject(id,newObj)
  329: 
  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'):
  362:             
  363:             self.coords=['']
  364:             #print "G",self.coords
  365: 
  366:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_externalLink.zpt').__of__(self)
  367:         return pt()
  368:     
  369: 
  370:     def changeECHO_externalLink(self,link,title,label,description,content_type,responsible,weight,coords=None,credits=None,RESPONSE=None):
  371: 
  372:         """Änderung der Properties"""
  373:         
  374: 
  375:         setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coords)
  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 getCredits(self):
  388:         """Ausgabe der credits"""
  389:         if self.credits:
  390:             return self.credits
  391:         else:
  392:             return []
  393:         
  394:     def index_html(self):
  395:         """standard page"""
  396:         
  397:         return self.REQUEST.RESPONSE.redirect(self.link)
  398: 
  399: def manage_addECHO_externalLinkForm(self):
  400:         """Form for external Links"""
  401:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_externalLinkForm.zpt').__of__(self)
  402:         return pt()
  403: 
  404: 
  405: def manage_addECHO_externalLink(self,id,title,label,description,content_type,responsible,link,weight,coords=None,credits=None,RESPONSE=None):
  406:     """Add an external Link"""
  407: 
  408:     newObj=ECHO_externalLink(id,link,title,label,description,content_type,responsible,credits,weight,coords)
  409: 
  410:     self._setObject(id,newObj)
  411: 
  412:     if RESPONSE is not None:
  413:         RESPONSE.redirect('manage_main')
  414:  
  415:         
  416: class ECHO_collection(Folder, Persistent, Implicit):
  417:     """ECHO Collection"""
  418:     security=ClassSecurityInfo()
  419:     meta_type='ECHO_collection'
  420: 
  421: 
  422:     
  423:     security.declarePublic('getCreditObject')
  424:     def getCreditObject(self,name):
  425:         """credit id to credititem"""
  426:         try:
  427:             return getattr(self.partners,name)
  428:         except:
  429:             return ""
  430: 
  431:     security.declarePublic('ECHO_generateNavBar')
  432:     def ECHO_generateNavBar(self):
  433:         """Erzeuge Navigationsbar"""
  434:         link=""
  435:         object="self"
  436:         ret=[]
  437:         path=self.getPhysicalPath()
  438:         for element in path:
  439:             
  440:            
  441:             if not element=="":
  442:                 object+="."+element
  443:                 
  444:                 label=eval(object).label
  445:                 link+="/"+element
  446:                 if not label=="":
  447:                     ret.append((label,link))
  448:         return ret
  449:     
  450:     security.declarePublic('ECHO_rerenderLinksMD')
  451:     def ECHO_rerenderLinksMD(self):
  452:         """Rerender all Links"""
  453:         
  454:         for entry in self.__dict__.keys():
  455:             object=getattr(self,entry)
  456:             
  457:             
  458:             try:
  459:                 
  460:                 if object.meta_type == 'ECHO_resource':
  461:                     
  462:                     object.ECHO_getResourceMD(template="no")
  463:                     
  464:             except:
  465:                 """nothing"""
  466:                 
  467:         return "Rerenderd all links to resources in: "+self.title
  468:     
  469: 
  470:     def getCoords(self):
  471:         try:
  472:             
  473:             x=  [string.join(x,",") for x in self.coords]  
  474:             return x
  475: 
  476:         except:
  477: 
  478:             return []
  479:         
  480:     def __init__(self,id,title,label,description,content_type,responsible,credits,weight,sortfield,coords):
  481:         #print "CO",coords
  482: 
  483:         self.id = id
  484:         """Festlegen der ID"""
  485:         self.credits=toList(credits)
  486:         self.label = label
  487:         self.title=title
  488:         self.description=description
  489:         self.content_type=content_type
  490:         self.responsible=responsible
  491: 
  492:         self.weight=weight
  493:         self.sortfield=sortfield
  494:         coordsnew=[ string.split(x,",") for x in coords]
  495:         self.coords=coordsnew
  496: 
  497: 
  498:     manage_options = Folder.manage_options+(
  499:         {'label':'Main Config','action':'ECHO_collection_config'},
  500:         {'label':'Rerender Links','action':'ECHO_rerenderLinksMD'},
  501:         {'label':'Graphics','action':'ECHO_graphicEntry'},
  502: 
  503:         )
  504: 
  505:     def ECHO_graphicEntry(self):
  506:         """DO nothing"""
  507:         if 'overview' in self.aq_parent.__dict__.keys():
  508:             pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
  509:             return pt()
  510:         else:
  511:             return "NO OVERVIEW GRAPHICS"
  512: 
  513:     def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
  514:         """Enter coords"""
  515:         coords=self.coords
  516:         temco=coordstr.split(",")
  517:         temco.append(angle)
  518:         coords.append(temco)
  519:         self.coords=coords[0:]
  520: 
  521:         if RESPONSE is not None:
  522:             RESPONSE.redirect('ECHO_graphicEntry')
  523: 
  524:     
  525:     security.declarePublic('ECHO_collection_config')
  526:     def ECHO_collection_config(self):
  527:         """Main configuration"""
  528: 
  529:         if not hasattr(self,'weight'):
  530:             self.weight=""
  531: 
  532:         if not hasattr(self,'sortfield'):
  533:             self.sortfield="weight"
  534:   
  535:         if not hasattr(self,'coords'):
  536:             self.coords=[]
  537: 
  538:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_collection.zpt').__of__(self)
  539:         return pt()
  540: 
  541: 
  542:     security.declarePublic('changeECHO_collection')
  543: 
  544: 
  545:     def changeECHO_collection(self,title,label,description,content_type,responsible,weight,credits=None,sortfield="weight",coords=None,RESPONSE=None):
  546:         """Änderung der Properties"""
  547: 
  548:         coordsnew=[ string.split(x,",") for x in coords]
  549: 
  550:         setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coordsnew)
  551: 
  552:         self.sortfield=sortfield
  553: 
  554:         if RESPONSE is not None:
  555:             RESPONSE.redirect('manage_main')
  556:             
  557:     security.declarePublic('index_html')
  558: 
  559:     showOverview=DTMLFile('dtml/ECHO_content_overview',globals())
  560:     
  561:     
  562:     def index_html(self):
  563:         """standard page"""
  564:         
  565:         if 'index.html' in self.__dict__.keys():
  566:             return getattr(self,'index.html')()
  567:         elif 'overview' in self.__dict__.keys():
  568:             return self.showOverview()
  569:             
  570:         
  571:         pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_standard.zpt').__of__(self)
  572:         pt.content_type="text/html"
  573:         return pt()
  574: 
  575:     def getCredits(self):
  576:         """Ausgabe der credits"""
  577:         if self.credits:
  578:             return self.credits
  579:         else:
  580:             return []
  581: 
  582:     def getGraphicCoords(self):
  583:         """Give list of coordinates"""
  584:         subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
  585:         ids=[]
  586:         for entry in self.__dict__.keys():
  587:             object=getattr(self,entry)
  588:             try:
  589:                 if object.meta_type in subColTypes:
  590:                     for coordtemp in object.coords:
  591:                         if len(coordtemp)>3:
  592:                             coord=coordtemp[0:4]
  593:                             if hasattr(object,'title'):
  594:                                 if not object.title=="":
  595:                                     ids.append([string.join(coord,", "),object.getId(),object.title])
  596:                                 else:
  597:                                     ids.append([string.join(coord,", "),object.getId(),object.getId()])
  598:                             else:
  599:                                 ids.append([string.join(coord,", "),object.getId(),object.getId()])
  600:                     
  601:             except:
  602:                 """nothing"""
  603: 
  604:         return ids
  605:     
  606:     def getSubCols(self,sortfield="weight"):
  607: 
  608:         subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
  609:         ids=[]
  610:         for entry in self.__dict__.keys():
  611:             object=getattr(self,entry)
  612:             try:
  613:                 if object.meta_type in subColTypes:
  614:                     ids.append(object)
  615:                     
  616:             except:
  617:                 """nothing"""
  618:         try:
  619:             sortfield=self.sortfield
  620:         except:
  621:             """nothing"""
  622:             
  623:         tmplist=[]
  624:         for x in ids:
  625:             if hasattr(x,sortfield):
  626:                 try:
  627:                     x=int(x)
  628:                 except:
  629:                     """nothing"""
  630:                 tmp=getattr(x,sortfield)
  631:             else:
  632:                 tmp=10000000
  633:             tmplist.append((tmp,x))
  634:         tmplist.sort()
  635:         return [x for (key,x) in tmplist]
  636:      
  637:         
  638:         
  639:                 
  640:     
  641:     
  642: def manage_addECHO_collectionForm(self):
  643:         """Add collection form"""
  644:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_collectionForm.zpt').__of__(self)
  645:         return pt()
  646: 
  647: 
  648: def manage_addECHO_collection(self,id,title,label,description,content_type,responsible,weight,sortfield,coords="",credits=None,RESPONSE=None):
  649:     """add a echo collection"""
  650:     
  651: 
  652:     newObj=ECHO_collection(id,title,label,description,content_type,responsible,credits,weight,sortfield,coords)
  653: 
  654:     self._setObject(id,newObj)
  655: 
  656:     if RESPONSE is not None:
  657:         RESPONSE.redirect('manage_main')
  658: 
  659: class ECHO_root(Folder,Persistent,Implicit):
  660:     """ECHO Root Folder"""
  661:     meta_type="ECHO_root"
  662: 
  663:     def __init__(self,id,title):
  664:         """init"""
  665:         self.id = id
  666:         self.title=title
  667: 
  668:     def deleteSpace(self,str):
  669:         """delete space at the end of a line"""
  670:         if str[len(str)-1]==" ":
  671:             return str[0:len(str)-1]
  672:         else:
  673:             return str
  674:         
  675:     
  676: 
  677:     # zusaetliche methoden fuer das vlp muessen in ein eigenes produkt
  678: 
  679:     def formatAscii(self,str,url=None):
  680:         """ersetze ascii umbrueche durch <br>"""
  681:         #url=None
  682:         if url:
  683:             
  684:             retStr=""
  685:             words=str.split("\n")
  686:             
  687:             for word in words:
  688:                 strUrl=url%word
  689:                 print "str",strUrl
  690:                 retStr+="""<a href="%s">%s</a><br/>"""%(strUrl,word)
  691:             str=retStr
  692:         if str:
  693:             return re.sub(r"[\n]","<br/>",str)
  694:         else:
  695:             return ""
  696:         
  697:     def link2html(self,str):
  698:         """link2html fuer VLP muss hier noch raus"""
  699:         if str:
  700:             print str
  701:             str=re.sub("\&","&amp;",str)
  702:             dom=xml.dom.minidom.parseString("<?xml version='1.0' ?><txt>"+str+"</txt>")
  703:             links=dom.getElementsByTagName("link")
  704:             
  705:             print "link",links
  706:             for link in links:
  707:                 link.tagName="a"
  708:                 ref=link.getAttribute("ref")
  709:                 if self.checkRef(ref):
  710:                     link.setAttribute("href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref)
  711: 
  712:             return dom.toxml('utf-8')
  713:         return ""
  714: 
  715: 
  716:     def checkRef(self,ref):
  717:         dbs={'vl_literature':'AND CD LIKE \'%lise%\'','vl_technology':'','vl_people':''}
  718:         res=None
  719:         for db in dbs.keys():
  720:             #print ref,"select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])
  721: 
  722:             res=res or self.search(var=str("select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])))
  723:         return res
  724:                                     
  725:     #Ende Methode fuer vlp
  726: 
  727:     def PgQuoteString(self,string):
  728:         """Quote string"""
  729:         #print "PG",string
  730:         return libpq.PgQuoteString(string)
  731:         
  732:     def getPartners(self):
  733:         """Get list of Partners. Presently only from a subfolder partners"""
  734:         partnerTypes=['ECHO_partner']
  735:         ids=[]
  736:         try:
  737:             for entry in self.partners.__dict__.keys():
  738:                 object=getattr(self.partners,entry)
  739:                 
  740:                 try:
  741:                 
  742:                     if object.meta_type in partnerTypes:
  743:                         ids.append(object)
  744:                     
  745:                 except:
  746:                     """nothing"""
  747:         except:
  748:             ids=[] # no partners
  749:         return ids
  750: 
  751:     def getCollectionTree(self):
  752:         """get the collection tree (list of triples (parent,child, depth)"""
  753: 
  754:         def getCollection(object,depth=0):
  755:             depth+=1
  756:             collections=[]
  757:             for entry in object.__dict__.keys():
  758:                 element=getattr(object,entry)
  759:                 try:
  760:                     if element.meta_type=="ECHO_collection":
  761:                         collections.append((object,element,depth))
  762:                         collections+=getCollection(element,depth)
  763:                 except:
  764:                     """nothing"""
  765:             return collections
  766:         
  767: 
  768:         return getCollection(self)
  769:     
  770:     def getCollectionTreeIds(self):
  771:         """Show the IDs of the Tree"""
  772:         ret=[]
  773:         for collection in self.getCollectionTree():
  774:             ret.append((collection[0].getId(),collection[1].getId(),collection[2]))
  775:         return ret
  776: 
  777:         
  778:         
  779: def manage_addECHO_root(self,id,title,RESPONSE=None):
  780:     """Add an ECHO_root"""
  781:     self._setObject(id,ECHO_root(id,title))
  782:     
  783:     if RESPONSE is not None:
  784:         RESPONSE.redirect('manage_main')
  785: 
  786: def manage_addECHO_rootForm(self):
  787:         """Nothing yet"""
  788:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_root.zpt').__of__(self)
  789:         return pt()
  790:  
  791: class ECHO_partner(Image,Persistent):
  792:     """ECHO Partner"""
  793: 
  794:     meta_type="ECHO_partner"
  795: 
  796:     def __init__(self, id, title,url, file, content_type='', precondition=''):
  797:         self.__name__=id
  798:         self.title=title
  799:         self.url=url
  800:         self.precondition=precondition
  801: 
  802:         data, size = self._read_data(file)
  803:         content_type=self._get_content_type(file, data, id, content_type)
  804:         self.update_data(data, content_type, size)
  805: 
  806:     manage_options = Image.manage_options+(
  807:         {'label':'Partner Information','action':'ECHO_partner_config'},
  808:         )
  809: 
  810:     def changeECHO_partner(self,url,RESPONSE=None):
  811:         """Change main information"""
  812:         self.url=url
  813:         if RESPONSE is not None:
  814:             RESPONSE.redirect('manage_main')
  815:             
  816:             
  817: 
  818:     def ECHO_partner_config(self):
  819:         """Main configuration"""
  820:         if not hasattr(self,'url'):
  821:             self.url=""
  822:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_partner.zpt').__of__(self)
  823:         return pt()
  824: 
  825:         
  826: manage_addECHO_partnerForm=DTMLFile('dtml/ECHO_partnerAdd',globals(),
  827:                              Kind='ECHO_partner',kind='ECHO_partner')
  828: 
  829: 
  830: 
  831: def manage_addECHO_partner(self, id, file,url, title='', precondition='', content_type='',
  832:                     REQUEST=None):
  833:     """
  834:     Add a new ECHO_partner object.
  835: 
  836:     Creates a new ECHO_partner object 'id' with the contents of 'file'.
  837:     Based on Image.manage_addImage
  838:     """
  839: 
  840:     id=str(id)
  841:     title=str(title)
  842:     content_type=str(content_type)
  843:     precondition=str(precondition)
  844: 
  845:     id, title = OFS.Image.cookId(id, title, file)
  846: 
  847:     self=self.this()
  848: 
  849:     # First, we create the image without data:
  850:     self._setObject(id, ECHO_partner(id,title,url,'',content_type, precondition))
  851: 
  852:     # Now we "upload" the data.  By doing this in two steps, we
  853:     # can use a database trick to make the upload more efficient.
  854:     if file:
  855:         self._getOb(id).manage_upload(file)
  856:     if content_type:
  857:         self._getOb(id).content_type=content_type
  858: 
  859:     if REQUEST is not None:
  860:         try:    url=self.DestinationURL()
  861:         except: url=REQUEST['URL1']
  862:         REQUEST.RESPONSE.redirect('%s/manage_main' % url)
  863:     return id
  864: 
  865: 

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