File:  [Repository] / ECHO_content / ECHO_collection.py
Revision 1.15: download - view: text, annotated - select for diffs - revision graph
Mon Mar 1 17:42:49 2004 UTC (20 years, 4 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD

bug fixed

    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 index_html(self):
  388:         """standard page"""
  389:         
  390:         return self.REQUEST.RESPONSE.redirect(self.link)
  391: 
  392: def manage_addECHO_externalLinkForm(self):
  393:         """Form for external Links"""
  394:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_externalLinkForm.zpt').__of__(self)
  395:         return pt()
  396: 
  397: 
  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"""
  400: 
  401:     newObj=ECHO_externalLink(id,link,title,label,description,content_type,responsible,credits,weight,coords)
  402: 
  403:     self._setObject(id,newObj)
  404: 
  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"""
  419:         try:
  420:             return getattr(self.partners,name)
  421:         except:
  422:             return ""
  423:         
  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"""
  446:         
  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:
  465:             
  466:             x=  [string.join(x,",") for x in self.coords]  
  467:             return x
  468: 
  469:         except:
  470: 
  471:             return []
  472:         
  473:     def __init__(self,id,title,label,description,content_type,responsible,credits,weight,sortfield,coords):
  474:         #print "CO",coords
  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+(
  492:         {'label':'Main Config','action':'ECHO_collection_config'},
  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():
  501:             pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
  502:             return pt()
  503:         else:
  504:             return "NO OVERVIEW GRAPHICS"
  505: 
  506:     def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
  507:         """Enter coords"""
  508:         coords=self.coords
  509:         temco=coordstr.split(",")
  510:         temco.append(angle)
  511:         coords.append(temco)
  512:         self.coords=coords[0:]
  513: 
  514:         if RESPONSE is not None:
  515:             RESPONSE.redirect('ECHO_graphicEntry')
  516: 
  517:     
  518:     security.declarePublic('ECHO_collection_config')
  519:     def ECHO_collection_config(self):
  520:         """Main configuration"""
  521: 
  522:         if not hasattr(self,'weight'):
  523:             self.weight=""
  524: 
  525:         if not hasattr(self,'sortfield'):
  526:             self.sortfield="weight"
  527:   
  528:         if not hasattr(self,'coords'):
  529:             self.coords=[]
  530: 
  531:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_collection.zpt').__of__(self)
  532:         return pt()
  533: 
  534: 
  535:     security.declarePublic('changeECHO_collection')
  536: 
  537: 
  538:     def changeECHO_collection(self,title,label,description,content_type,responsible,weight,credits=None,sortfield="weight",coords=None,RESPONSE=None):
  539:         """Änderung der Properties"""
  540: 
  541:         coordsnew=[ string.split(x,",") for x in coords]
  542: 
  543:         setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coordsnew)
  544: 
  545:         self.sortfield=sortfield
  546: 
  547:         if RESPONSE is not None:
  548:             RESPONSE.redirect('manage_main')
  549:             
  550:     security.declarePublic('index_html')
  551: 
  552:     showOverview=DTMLFile('ECHO_content_overview',globals())
  553:     
  554:     
  555:     def index_html(self):
  556:         """standard page"""
  557:         
  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:         
  564:         pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_standard.zpt').__of__(self)
  565:         pt.content_type="text/html"
  566:         return pt()
  567: 
  568:     def getCredits(self):
  569:         """Ausgabe der credits"""
  570:         if self.credits:
  571:             return self.credits
  572:         else:
  573:             return []
  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:
  583:                     for coordtemp in object.coords:
  584:                         if len(coordtemp)>3:
  585:                             coord=coordtemp[0:4]
  586:                             if hasattr(object,'title'):
  587:                                 if not object.title=="":
  588:                                     ids.append([string.join(coord,", "),object.getId(),object.title])
  589:                                 else:
  590:                                     ids.append([string.join(coord,", "),object.getId(),object.getId()])
  591:                             else:
  592:                                 ids.append([string.join(coord,", "),object.getId(),object.getId()])
  593:                     
  594:             except:
  595:                 """nothing"""
  596: 
  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:     
  635: def manage_addECHO_collectionForm(self):
  636:         """Add collection form"""
  637:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_collectionForm.zpt').__of__(self)
  638:         return pt()
  639: 
  640: 
  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"""
  643:     
  644: 
  645:     newObj=ECHO_collection(id,title,label,description,content_type,responsible,credits,weight,sortfield,coords)
  646: 
  647:     self._setObject(id,newObj)
  648: 
  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
  660: 
  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: 
  720:     def PgQuoteString(self,string):
  721:         """Quote string"""
  722:         #print "PG",string
  723:         return libpq.PgQuoteString(string)
  724:         
  725:     def getPartners(self):
  726:         """Get list of Partners. Presently only from a subfolder partners"""
  727:         partnerTypes=['ECHO_partner']
  728:         ids=[]
  729:         try:
  730:             for entry in self.partners.__dict__.keys():
  731:                 object=getattr(self.partners,entry)
  732:                 
  733:                 try:
  734:                 
  735:                     if object.meta_type in partnerTypes:
  736:                         ids.append(object)
  737:                     
  738:                 except:
  739:                     """nothing"""
  740:         except:
  741:             ids=[] # no partners
  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:         
  772: def manage_addECHO_root(self,id,title,RESPONSE=None):
  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: 
  779: def manage_addECHO_rootForm(self):
  780:         """Nothing yet"""
  781:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_root.zpt').__of__(self)
  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=""
  815:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_partner.zpt').__of__(self)
  816:         return pt()
  817: 
  818:         
  819: manage_addECHO_partnerForm=DTMLFile('dtml/ECHO_partnerAdd',globals(),
  820:                              Kind='ECHO_partner',kind='ECHO_partner')
  821: 
  822: 
  823: 
  824: def manage_addECHO_partner(self, id, file,url, title='', precondition='', content_type='',
  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>