File:  [Repository] / ECHO_content / ECHO_collection.py
Revision 1.21: download - view: text, annotated - select for diffs - revision graph
Tue Mar 30 15:30:58 2004 UTC (20 years, 2 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
hack zur korrektur eingabe der coordinatenCVS: ----------------------------------------------------------------------

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

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