File:  [Repository] / ECHO_content / ECHO_collection.py
Revision 1.20: download - view: text, annotated - select for diffs - revision graph
Tue Mar 30 12:44:57 2004 UTC (20 years, 3 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD


lage des overview CVS: ----------------------------------------------------------------------

    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 getOverview(self):
  261:         """overview graphics"""
  262:         
  263:         return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
  264: 
  265:     def ECHO_graphicEntry(self):
  266:         """DO nothing"""
  267:         overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
  268:         if overview: 
  269:             pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
  270:             return pt()
  271:         else:
  272:             return "NO OVERVIEW GRAPHICS"
  273: 
  274:     def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
  275:         """Enter coords"""
  276:         coords=self.coords
  277:         temco=coordstr.split(",")
  278:         temco.append(angle)
  279:         coords.append(temco)
  280:         
  281:         self.coords=coords[0:]
  282: 
  283:         if RESPONSE is not None:
  284:             RESPONSE.redirect('ECHO_graphicEntry')
  285: 
  286:     def ECHO_getResourceMD(self,template="yes"):
  287:         """Einlesen der Metadaten und Anlegen dieser Metadaten als Informationen zur Resource"""
  288:         (metadict, error)=readMetadata(self.metalink)
  289: 
  290: 
  291: 
  292:         if not error=="": #Fehler beim Auslesen des Metafiles
  293:             return "ERROR:",error
  294:         for key in metadict.keys():#Hinzufügen der Felder
  295: 
  296:             setattr(self,key,metadict[key].encode('ascii','replace'))
  297:         
  298: 
  299:         self.metadata=metadict.keys()
  300: 
  301:         self.label=self.generate_label()
  302:         
  303:         if template=="yes":
  304:             pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_resourceMD.zpt').__of__(self)
  305:             return pt()
  306:     
  307:     def ECHO_getMD(self,item):
  308:         """Ausgabe der MD"""
  309:         return getattr(self,item)
  310:         
  311:     def index_html(self):
  312:         """standard page"""
  313:         
  314:         return self.REQUEST.RESPONSE.redirect(self.link)
  315: 
  316:     def generate_label(self):
  317:         """Erzeugt_standard_Label aus Template"""
  318:         pt=getattr(self,"label_template_"+self.bib_type)
  319: 
  320:         return pt()
  321: 
  322: def manage_addECHO_resourceForm(self):
  323:         """Form for adding a ressource"""
  324:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_resourceForm.zpt').__of__(self)
  325:         return pt()
  326: 
  327: 
  328: 
  329: def manage_addECHO_resource(self,id,title,label,description,content_type,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None):
  330:     """addaresource"""
  331: 
  332:     newObj=ECHO_resource(id,link,metalink,title,label,description,content_type,responsible,credits,weight,coords)
  333: 
  334:     self._setObject(id,newObj)
  335: 
  336:     if RESPONSE is not None:
  337:         RESPONSE.redirect('manage_main')
  338:  
  339: 
  340: class ECHO_externalLink(Folder):
  341:     """Link zu einer externen Ressource"""
  342:     security=ClassSecurityInfo()
  343:     meta_type='ECHO_externalLink'
  344: 
  345: 
  346:     def __init__(self,id,link,title,label,description,content_type,responsible,credits,weight,coords):
  347: 
  348:         self.id = id
  349:         """Festlegen der ID"""
  350: 
  351:         self.credits=toList(credits)
  352:         self.label = label
  353:         self.link= link
  354:         self.title=title
  355:         self.weight=weight
  356:         self.description=description
  357:         self.content_type=content_type
  358:         self.responsible=responsible
  359:         coordsnew=[ string.split(x,",") for x in coords]
  360:         self.coords=coordsnew
  361: 
  362:     def ECHO_externalLink_config(self):
  363:         """Main configuration"""
  364: 
  365:         if not hasattr(self,'weight'):
  366:             self.weight=""
  367:         if not hasattr(self,'coords'):
  368:             
  369:             self.coords=['']
  370:             #print "G",self.coords
  371: 
  372:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_externalLink.zpt').__of__(self)
  373:         return pt()
  374:     
  375: 
  376:     def changeECHO_externalLink(self,link,title,label,description,content_type,responsible,weight,coords=None,credits=None,RESPONSE=None):
  377: 
  378:         """Änderung der Properties"""
  379:         
  380: 
  381:         setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coords)
  382: 
  383:         
  384:         self.link=link
  385:         if RESPONSE is not None:
  386:             RESPONSE.redirect('manage_main')
  387:             
  388:             
  389:     manage_options = Folder.manage_options+(
  390:         {'label':'Main Config','action':'ECHO_externalLink_config'},
  391:         )
  392: 
  393:     def getCredits(self):
  394:         """Ausgabe der credits"""
  395:         if self.credits:
  396:             return self.credits
  397:         else:
  398:             return []
  399:         
  400:     def index_html(self):
  401:         """standard page"""
  402:         
  403:         return self.REQUEST.RESPONSE.redirect(self.link)
  404: 
  405: def manage_addECHO_externalLinkForm(self):
  406:         """Form for external Links"""
  407:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_externalLinkForm.zpt').__of__(self)
  408:         return pt()
  409: 
  410: 
  411: def manage_addECHO_externalLink(self,id,title,label,description,content_type,responsible,link,weight,coords=None,credits=None,RESPONSE=None):
  412:     """Add an external Link"""
  413: 
  414:     newObj=ECHO_externalLink(id,link,title,label,description,content_type,responsible,credits,weight,coords)
  415: 
  416:     self._setObject(id,newObj)
  417: 
  418:     if RESPONSE is not None:
  419:         RESPONSE.redirect('manage_main')
  420:  
  421:         
  422: class ECHO_collection(Folder, Persistent, Implicit):
  423:     """ECHO Collection"""
  424:     security=ClassSecurityInfo()
  425:     meta_type='ECHO_collection'
  426: 
  427: 
  428:     
  429:     security.declarePublic('getCreditObject')
  430:     def getCreditObject(self,name):
  431:         """credit id to credititem"""
  432:         try:
  433:             return getattr(self.partners,name)
  434:         except:
  435:             return ""
  436: 
  437:     security.declarePublic('ECHO_generateNavBar')
  438:     def ECHO_generateNavBar(self):
  439:         """Erzeuge Navigationsbar"""
  440:         link=""
  441:         object="self"
  442:         ret=[]
  443:         path=self.getPhysicalPath()
  444:         for element in path:
  445:             
  446:            
  447:             if not element=="":
  448:                 object+="."+element
  449:                 
  450:                 label=eval(object).label
  451:                 link+="/"+element
  452:                 if not label=="":
  453:                     ret.append((label,link))
  454:         return ret
  455:     
  456:     security.declarePublic('ECHO_rerenderLinksMD')
  457:     def ECHO_rerenderLinksMD(self):
  458:         """Rerender all Links"""
  459:         
  460:         for entry in self.__dict__.keys():
  461:             object=getattr(self,entry)
  462:             
  463:             
  464:             try:
  465:                 
  466:                 if object.meta_type == 'ECHO_resource':
  467:                     
  468:                     object.ECHO_getResourceMD(template="no")
  469:                     
  470:             except:
  471:                 """nothing"""
  472:                 
  473:         return "Rerenderd all links to resources in: "+self.title
  474: 
  475:     security.declarePublic('ECHO_newViewerLink')
  476:     
  477: 
  478:     def getCoords(self):
  479:         try:
  480:             
  481:             x=  [string.join(x,",") for x in self.coords]  
  482:             return x
  483: 
  484:         except:
  485: 
  486:             return []
  487:         
  488:     def __init__(self,id,title,label,description,content_type,responsible,credits,weight,sortfield,coords):
  489:         #print "CO",coords
  490: 
  491:         self.id = id
  492:         """Festlegen der ID"""
  493:         self.credits=toList(credits)
  494:         self.label = label
  495:         self.title=title
  496:         self.description=description
  497:         self.content_type=content_type
  498:         self.responsible=responsible
  499: 
  500:         self.weight=weight
  501:         self.sortfield=sortfield
  502:         coordsnew=[ string.split(x,",") for x in coords]
  503:         self.coords=coordsnew
  504: 
  505: 
  506:     manage_options = Folder.manage_options+(
  507:         {'label':'Main Config','action':'ECHO_collection_config'},
  508:         {'label':'Rerender Links','action':'ECHO_rerenderLinksMD'},
  509:         {'label':'Graphics','action':'ECHO_graphicEntry'},
  510: 
  511:         )
  512: 
  513:     def getOverview(self):
  514:         """overview graphics"""
  515:         
  516:         return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
  517:     
  518:     
  519:     def ECHO_graphicEntry(self):
  520:         """DO nothing"""
  521:         overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
  522:         
  523:     
  524:         if overview:
  525:             pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
  526:             return pt()
  527:         else:
  528:             return "NO OVERVIEW GRAPHICS"
  529: 
  530:     def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
  531:         """Enter coords"""
  532:         coords=self.coords
  533:         temco=coordstr.split(",")
  534:         temco.append(angle)
  535:         coords.append(temco)
  536:         self.coords=coords[0:]
  537: 
  538:         if RESPONSE is not None:
  539:             RESPONSE.redirect('ECHO_graphicEntry')
  540: 
  541:     
  542:     security.declarePublic('ECHO_collection_config')
  543:     def ECHO_collection_config(self):
  544:         """Main configuration"""
  545: 
  546:         if not hasattr(self,'weight'):
  547:             self.weight=""
  548: 
  549:         if not hasattr(self,'sortfield'):
  550:             self.sortfield="weight"
  551:   
  552:         if not hasattr(self,'coords'):
  553:             self.coords=[]
  554: 
  555:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_collection.zpt').__of__(self)
  556:         return pt()
  557: 
  558: 
  559:     security.declarePublic('changeECHO_collection')
  560: 
  561: 
  562:     def changeECHO_collection(self,title,label,description,content_type,responsible,weight,credits=None,sortfield="weight",coords=None,RESPONSE=None):
  563:         """Änderung der Properties"""
  564: 
  565:         coordsnew=[ string.split(x,",") for x in coords]
  566: 
  567:         setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coordsnew)
  568: 
  569:         self.sortfield=sortfield
  570: 
  571:         if RESPONSE is not None:
  572:             RESPONSE.redirect('manage_main')
  573:             
  574:     security.declarePublic('index_html')
  575: 
  576:     showOverview=DTMLFile('dtml/ECHO_content_overview',globals())
  577:     
  578:     
  579:     def index_html(self):
  580:         """standard page"""
  581:         
  582:         if 'index.html' in self.__dict__.keys():
  583:             return getattr(self,'index.html')()
  584:         elif 'overview' in self.__dict__.keys():
  585:             return self.showOverview()
  586:             
  587:         
  588:         pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_standard.zpt').__of__(self)
  589:         pt.content_type="text/html"
  590:         return pt()
  591: 
  592:     def getCredits(self):
  593:         """Ausgabe der credits"""
  594:         if self.credits:
  595:             return self.credits
  596:         else:
  597:             return []
  598: 
  599:     def getGraphicCoords(self):
  600:         """Give list of coordinates"""
  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:                     for coordtemp in object.coords:
  608:                         if len(coordtemp)>3:
  609:                             coord=coordtemp[0:4]
  610:                             if hasattr(object,'title'):
  611:                                 if not object.title=="":
  612:                                     ids.append([string.join(coord,", "),object.getId(),object.title])
  613:                                 else:
  614:                                     ids.append([string.join(coord,", "),object.getId(),object.getId()])
  615:                             else:
  616:                                 ids.append([string.join(coord,", "),object.getId(),object.getId()])
  617:                     
  618:             except:
  619:                 """nothing"""
  620: 
  621:         return ids
  622:     
  623:     def getSubCols(self,sortfield="weight"):
  624: 
  625:         subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
  626:         ids=[]
  627:         for entry in self.__dict__.keys():
  628:             object=getattr(self,entry)
  629:             try:
  630:                 if object.meta_type in subColTypes:
  631:                     ids.append(object)
  632:                     
  633:             except:
  634:                 """nothing"""
  635:         try:
  636:             sortfield=self.sortfield
  637:         except:
  638:             """nothing"""
  639:             
  640:         tmplist=[]
  641:         for x in ids:
  642:             if hasattr(x,sortfield):
  643:                 try:
  644:                     x=int(x)
  645:                 except:
  646:                     """nothing"""
  647:                 tmp=getattr(x,sortfield)
  648:             else:
  649:                 tmp=10000000
  650:             tmplist.append((tmp,x))
  651:         tmplist.sort()
  652:         return [x for (key,x) in tmplist]
  653:      
  654:         
  655:         
  656:                 
  657:     
  658:     
  659: def manage_addECHO_collectionForm(self):
  660:         """Add collection form"""
  661:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_collectionForm.zpt').__of__(self)
  662:         return pt()
  663: 
  664: 
  665: def manage_addECHO_collection(self,id,title,label,description,content_type,responsible,weight,sortfield,coords="",credits=None,RESPONSE=None):
  666:     """add a echo collection"""
  667:     
  668: 
  669:     newObj=ECHO_collection(id,title,label,description,content_type,responsible,credits,weight,sortfield,coords)
  670: 
  671:     self._setObject(id,newObj)
  672: 
  673:     if RESPONSE is not None:
  674:         RESPONSE.redirect('manage_main')
  675: 
  676: class ECHO_root(Folder,Persistent,Implicit):
  677:     """ECHO Root Folder"""
  678:     meta_type="ECHO_root"
  679: 
  680:     def ECHO_newViewerLink(self,obj=None):
  681:         """change links (:86 faellt weg)"""
  682: 
  683:         if not obj:
  684:             obj = self
  685:             
  686:         entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection'])
  687: 
  688:         for entry in entries:
  689:                 
  690:                 if entry[1].meta_type == 'ECHO_resource':
  691:                     
  692:                     entry[1].link=re.sub('\:86','',entry[1].link)
  693: 
  694:                 else:
  695:                     
  696:                     entry[1].ECHO_newViewerLink(entry[1])
  697:                 
  698:         return "Rerenderd all links to resources in: "+self.title
  699: 
  700:     def __init__(self,id,title):
  701:         """init"""
  702:         self.id = id
  703:         self.title=title
  704: 
  705:     def deleteSpace(self,str):
  706:         """delete space at the end of a line"""
  707:         if str[len(str)-1]==" ":
  708:             return str[0:len(str)-1]
  709:         else:
  710:             return str
  711:         
  712:     
  713: 
  714:     # zusaetliche methoden fuer das vlp muessen in ein eigenes produkt
  715: 
  716:     def formatAscii(self,str,url=None):
  717:         """ersetze ascii umbrueche durch <br>"""
  718:         #url=None
  719:         if url:
  720:             
  721:             retStr=""
  722:             words=str.split("\n")
  723:             
  724:             for word in words:
  725:                 strUrl=url%word
  726:                 print "str",strUrl
  727:                 retStr+="""<a href="%s">%s</a><br/>"""%(strUrl,word)
  728:             str=retStr
  729:         if str:
  730:             return re.sub(r"[\n]","<br/>",str)
  731:         else:
  732:             return ""
  733:         
  734:     def link2html(self,str):
  735:         """link2html fuer VLP muss hier noch raus"""
  736:         if str:
  737:             print str
  738:             str=re.sub("\&","&amp;",str)
  739:             dom=xml.dom.minidom.parseString("<?xml version='1.0' ?><txt>"+str+"</txt>")
  740:             links=dom.getElementsByTagName("link")
  741:             
  742:             print "link",links
  743:             for link in links:
  744:                 link.tagName="a"
  745:                 ref=link.getAttribute("ref")
  746:                 if self.checkRef(ref):
  747:                     link.setAttribute("href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref)
  748: 
  749:             return dom.toxml('utf-8')
  750:         return ""
  751: 
  752: 
  753:     def checkRef(self,ref):
  754:         dbs={'vl_literature':'AND CD LIKE \'%lise%\'','vl_technology':'','vl_people':''}
  755:         res=None
  756:         for db in dbs.keys():
  757:             #print ref,"select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])
  758: 
  759:             res=res or self.search(var=str("select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])))
  760:         return res
  761:                                     
  762:     #Ende Methode fuer vlp
  763: 
  764:     def PgQuoteString(self,string):
  765:         """Quote string"""
  766:         #print "PG",string
  767:         return libpq.PgQuoteString(string)
  768:         
  769:     def getPartners(self):
  770:         """Get list of Partners. Presently only from a subfolder partners"""
  771:         partnerTypes=['ECHO_partner']
  772:         ids=[]
  773:         try:
  774:             for entry in self.partners.__dict__.keys():
  775:                 object=getattr(self.partners,entry)
  776:                 
  777:                 try:
  778:                 
  779:                     if object.meta_type in partnerTypes:
  780:                         ids.append(object)
  781:                     
  782:                 except:
  783:                     """nothing"""
  784:         except:
  785:             ids=[] # no partners
  786:         return ids
  787: 
  788:     def getCollectionTree(self):
  789:         """get the collection tree (list of triples (parent,child, depth)"""
  790: 
  791:         def getCollection(object,depth=0):
  792:             depth+=1
  793:             collections=[]
  794:             for entry in object.__dict__.keys():
  795:                 element=getattr(object,entry)
  796:                 try:
  797:                     if element.meta_type=="ECHO_collection":
  798:                         collections.append((object,element,depth))
  799:                         collections+=getCollection(element,depth)
  800:                 except:
  801:                     """nothing"""
  802:             return collections
  803:         
  804: 
  805:         return getCollection(self)
  806:     
  807:     def getCollectionTreeIds(self):
  808:         """Show the IDs of the Tree"""
  809:         ret=[]
  810:         for collection in self.getCollectionTree():
  811:             ret.append((collection[0].getId(),collection[1].getId(),collection[2]))
  812:         return ret
  813: 
  814:         
  815:         
  816: def manage_addECHO_root(self,id,title,RESPONSE=None):
  817:     """Add an ECHO_root"""
  818:     self._setObject(id,ECHO_root(id,title))
  819:     
  820:     if RESPONSE is not None:
  821:         RESPONSE.redirect('manage_main')
  822: 
  823: def manage_addECHO_rootForm(self):
  824:         """Nothing yet"""
  825:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_root.zpt').__of__(self)
  826:         return pt()
  827:  
  828: class ECHO_partner(Image,Persistent):
  829:     """ECHO Partner"""
  830: 
  831:     meta_type="ECHO_partner"
  832: 
  833:     def __init__(self, id, title,url, file, content_type='', precondition=''):
  834:         self.__name__=id
  835:         self.title=title
  836:         self.url=url
  837:         self.precondition=precondition
  838: 
  839:         data, size = self._read_data(file)
  840:         content_type=self._get_content_type(file, data, id, content_type)
  841:         self.update_data(data, content_type, size)
  842: 
  843:     manage_options = Image.manage_options+(
  844:         {'label':'Partner Information','action':'ECHO_partner_config'},
  845:         )
  846: 
  847:     def changeECHO_partner(self,url,RESPONSE=None):
  848:         """Change main information"""
  849:         self.url=url
  850:         if RESPONSE is not None:
  851:             RESPONSE.redirect('manage_main')
  852:             
  853:             
  854: 
  855:     def ECHO_partner_config(self):
  856:         """Main configuration"""
  857:         if not hasattr(self,'url'):
  858:             self.url=""
  859:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_partner.zpt').__of__(self)
  860:         return pt()
  861: 
  862:         
  863: manage_addECHO_partnerForm=DTMLFile('dtml/ECHO_partnerAdd',globals(),
  864:                              Kind='ECHO_partner',kind='ECHO_partner')
  865: 
  866: 
  867: 
  868: def manage_addECHO_partner(self, id, file,url, title='', precondition='', content_type='',
  869:                     REQUEST=None):
  870:     """
  871:     Add a new ECHO_partner object.
  872: 
  873:     Creates a new ECHO_partner object 'id' with the contents of 'file'.
  874:     Based on Image.manage_addImage
  875:     """
  876: 
  877:     id=str(id)
  878:     title=str(title)
  879:     content_type=str(content_type)
  880:     precondition=str(precondition)
  881: 
  882:     id, title = OFS.Image.cookId(id, title, file)
  883: 
  884:     self=self.this()
  885: 
  886:     # First, we create the image without data:
  887:     self._setObject(id, ECHO_partner(id,title,url,'',content_type, precondition))
  888: 
  889:     # Now we "upload" the data.  By doing this in two steps, we
  890:     # can use a database trick to make the upload more efficient.
  891:     if file:
  892:         self._getOb(id).manage_upload(file)
  893:     if content_type:
  894:         self._getOb(id).content_type=content_type
  895: 
  896:     if REQUEST is not None:
  897:         try:    url=self.DestinationURL()
  898:         except: url=REQUEST['URL1']
  899:         REQUEST.RESPONSE.redirect('%s/manage_main' % url)
  900:     return id
  901: 
  902: 

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