File:  [Repository] / ECHO_content / ECHO_collection.py
Revision 1.32: download - view: text, annotated - select for diffs - revision graph
Mon Apr 5 15:38:19 2004 UTC (20 years, 2 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
new add index_template in layouttemplates and secondary link added

    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 os
   15: import OFS.Image
   16: from types import *
   17: from OFS.Image import Image
   18: from Globals import DTMLFile
   19: from OFS.Folder import Folder
   20: from OFS.SimpleItem import SimpleItem
   21: from AccessControl import ClassSecurityInfo
   22: from Globals import InitializeClass
   23: from Globals import DTMLFile
   24: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
   25: from Products.PageTemplates.PageTemplate import PageTemplate
   26: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
   27: from Globals import Persistent, package_home
   28: from Acquisition import Implicit
   29: 
   30: #from psycopg import libpq
   31: #from pyPgSQL import libpq
   32: import xml.dom.minidom
   33: 
   34: import urllib
   35: import xml.dom.minidom
   36: from ECHO_graphicalOverview import javaHandler,javaScriptMain
   37: 
   38: #List of different types for the graphical linking viewer
   39: viewClassificationListMaster=['view point','area']
   40: 
   41: def content_html(self,type):
   42:         """template fuer content"""
   43:         #templates = self.ZopeFind(self.aq_parent,obj_ids=[type+"_template"])
   44:         #
   45:         #if templates:
   46:         #    return templates[0][1]()
   47: 
   48:         try:
   49:             obj=getattr(self,type+"_template")
   50:             return obj()
   51:         except:
   52:             pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_%s_template_standard.zpt'%type).__of__(self)
   53:             pt.content_type="text/html"
   54:             return pt()
   55:     
   56: def toList(field):
   57:     """Einzelfeld in Liste umwandeln"""
   58:     if type(field)==StringType:
   59:         return [field]
   60:     else:
   61:         return field
   62:     
   63: def getText(nodelist):
   64: 
   65:     rc = ""
   66:     for node in nodelist:
   67:     	if node.nodeType == node.TEXT_NODE:
   68:            rc = rc + node.data
   69:     return rc
   70: 
   71: 
   72: def readMetadata(url):
   73:     """Methoden zum Auslesen der Metadateninformation zu einer Resource
   74:     Vorerst noch Typ bib"""
   75:     
   76:     metadict={}
   77:     try:
   78:         geturl=""
   79:         for line in urllib.urlopen(url).readlines():
   80:             geturl=geturl+line
   81:         
   82:         
   83:     except:
   84:         return (None,"Cannot open: "+url)
   85: 
   86:     try:
   87:         dom=xml.dom.minidom.parseString(geturl)
   88:     except:
   89:         return (None,"Cannot parse: "+url+"<br>"+geturl)
   90: 
   91:     metanode=dom.getElementsByTagName('bib')
   92:     metadict['bib_type']='Book'
   93:     if len(metanode)==0:
   94:         metanode=dom.getElementsByTagName('archimedes')
   95:         metadict['bib_type']='Archimedes'
   96:         #print "HELLO"
   97:         
   98:     if not len(metanode)==0:    
   99:         metacontent=metanode[0].childNodes
  100:     
  101:         try:
  102:             metadict['bib_type']=getText(dom.getElementsByTagName('bib')[0].attributes['type'].childNodes)
  103:         except:
  104:             """nothing"""
  105:         
  106:         for node in metacontent:
  107:             try:
  108:                 metadict[node.tagName.lower()]=getText(node.childNodes)
  109:             except:
  110:                 """nothing"""
  111: 
  112:     #print metadict
  113:     return metadict,""
  114:     
  115: 
  116: def setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordstrs,viewClassification=""):
  117: 
  118:         """Allegemeine Informationen zu einer ECHO Collection"""
  119: 
  120:         self.viewClassification=viewClassification
  121: 
  122:         self.label = label
  123:         self.title=title
  124:         self.description=description
  125:         self.contentType=contentType
  126:         self.responsible=responsible
  127:         self.credits=toList(credits)
  128:         self.weight=weight
  129: 
  130:         coords=[]
  131:         #coordinates of for rectangles
  132: 
  133:         #print "cs", coordstrs
  134:         if coordstrs:
  135:             for coordstr in coordstrs:
  136:                 #print "cs", coordstr
  137:                 try:
  138:                     temco=coordstr.split(",")
  139:                 except:
  140:                     temco=[]
  141:                 #temco.append(angle)
  142:                 coords.append(temco)
  143: 
  144: 
  145:         self.coords=coords[0:]
  146:             
  147: 
  148: class scientificClassification(SimpleItem,Persistent,Implicit):
  149:     """outdated will be deleeted in the next versions: subclass"""
  150:     security=ClassSecurityInfo()
  151:     
  152:     def __init__(self,context,science,practice):
  153:         self.context=context
  154:         self.science=science
  155:         self.practice=practice
  156:         self.id="scientific_Classification"
  157:         
  158:     security.declarePublic('get_context')
  159:     def get_context(self):
  160:         return self.context
  161:     
  162:     security.declarePublic('get_science')
  163:     def get_science(self):
  164:         return self.science
  165:         
  166:     security.declarePublic('get_practice')
  167:     def get_practice(self):
  168:         return self.practice
  169:     
  170:                 
  171: class scientificInformation(Folder,Persistent,Implicit):
  172:     """outdated will be deleted in the next versions: subclass scientificInformation"""
  173:     security=ClassSecurityInfo()
  174:     
  175:     
  176:     
  177:     def __init__(self,source_type,period):
  178: 
  179:         self.id="scientific_Information"
  180:         self.source_type=source_type
  181:         self.period=period
  182:         
  183: 
  184: 
  185:     security.declarePublic('get_source_type')
  186:     def get_source_type(self):
  187:         return self.source_type
  188:     
  189:     security.declarePublic('get_period')
  190:     def get_period(self):
  191:         return self.period
  192: 
  193: class ECHO_layoutTemplate(ZopePageTemplate):
  194:     """Create a layout Template for different purposes"""
  195: 
  196:     meta_type="ECHO_layoutTemplate"
  197: 
  198:     #manage_options=ZopePageTemplate.manage_options+(
  199:     #    {'label':'Set back to Standard','action':'changeECHO_layoutTemplateToStandardForm'},
  200:     #    )
  201: 
  202: 
  203:     def __init__(self, id, text=None, content_type=None,EchoType=None):
  204:         self.id = str(id)
  205: 
  206: 
  207: 
  208:         self.ZBindings_edit(self._default_bindings)
  209:         if text is None:
  210:             self._default_content_fn = os.path.join(package_home(globals()),
  211:                                                'zpt/ECHO_%s_template_standard.zpt'%EchoType)
  212:             text = open(self._default_content_fn).read()
  213:         self.pt_edit(text, content_type)
  214: 
  215:    ##  def changeECHO_layoutTemplateToStandardForm(self):
  216: ##         """change form"""
  217: ##         pt=PageTemplateFile('Products/ECHO_content/zpt/changeECHO_pageTemplateWeightForm.zpt').__of__(self)
  218: ##         return pt()
  219: 
  220:     
  221:         """change form"""
  222: 
  223: 
  224: def manage_addECHO_layoutTemplateForm(self):
  225:     """Form for adding"""
  226:     pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_layoutTemplate.zpt').__of__(self)
  227:     return pt()
  228: 
  229: from urllib import quote
  230: 
  231: 
  232: def manage_addECHO_layoutTemplate(self, EchoType,title=None,REQUEST=None):
  233:     "Add a Page Template with optional file content."
  234:     if type(EchoType)==StringType:
  235:         EchoTypes=[EchoType]
  236:     else:
  237:         EchoTypes=EchoType
  238:         
  239:     for singleType in EchoTypes:
  240: 
  241:         id = str(singleType)+"_template"
  242:         if REQUEST is None:
  243:             self._setObject(id, ECHO_layoutTemplate(id, text,EchoType=singleType))
  244:             ob = getattr(self, id)
  245:             
  246:             if title:
  247:                 ob.pt_setTitle(title)
  248:             return ob
  249:         else:
  250:             file = REQUEST.form.get('file')
  251:             headers = getattr(file, 'headers', None)
  252:             if headers is None or not file.filename:
  253:                 zpt = ECHO_layoutTemplate(id,EchoType=singleType)
  254:             else:
  255:                 zpt = ECHO_layoutTemplate(id, file, headers.get('content_type'))
  256: 
  257:             self._setObject(id, zpt)
  258:             ob = getattr(self, id)
  259:             if title:
  260:                 ob.pt_setTitle(title)
  261: 
  262:             try:
  263:                 u = self.DestinationURL()
  264:             except AttributeError:
  265:                 u = REQUEST['URL1']
  266: 
  267:             
  268:     REQUEST.RESPONSE.redirect(u+'/manage_main')
  269:     return ''
  270: 
  271: class ECHO_resource(Folder):
  272:     """ECHO Ressource"""
  273:     meta_type='ECHO_resource'
  274: 
  275:     viewClassificationList=viewClassificationListMaster
  276: 
  277:     def content_html(self):
  278:         """template fuer content"""
  279:         return content_html(self,'resource')
  280:     
  281:     def getViewClassification(self):
  282:         if hasattr(self,'viewClassification'):
  283:             return self.viewClassification
  284:         else:
  285:             return ""
  286:         
  287:     def getCredits(self):
  288:         """Ausgabe der credits"""
  289:         if self.credits:
  290:             return self.credits
  291:         else:
  292:             return []
  293:     
  294:     def __init__(self,id,link,metalink,title,label,description,contentType,responsible,credits,weight,coords):
  295: 
  296:         self.id = id
  297:         """Festlegen der ID"""
  298:         
  299:         self.label = label
  300:         self.link= link
  301:         self.metalink=metalink
  302:         self.title=title
  303:         self.weight=weight
  304:         self.credits=toList(credits)
  305:         self.description=description
  306:         self.contentType=contentType
  307:         self.responsible=responsible
  308:         
  309:         if coords:
  310:             coordsnew=[ string.split(x,",") for x in coords]
  311:         else:
  312:             coordsnew=[]
  313:         
  314:         self.coords=coordsnew
  315: 
  316: 
  317:     def getCoords(self):
  318:         try:
  319:             return [string.join(x,",") for x in self.coords]  
  320:         except:
  321:             return []
  322: 
  323: 
  324:     def ECHO_resource_config(self):
  325:         """Main configuration"""
  326: 
  327:         if not hasattr(self,'weight'):
  328:             self.weight=""
  329:         if not hasattr(self,'coords'):
  330:             self.coords=[]
  331: 
  332:         print "vorher",self.coords
  333:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_resource.zpt').__of__(self)
  334:         return pt()
  335:     
  336: 
  337:     def changeECHO_resource(self,metalink,link,title,label,description,contentType,responsible,weight,viewClassification="",coords=None,credits=None,RESPONSE=None):
  338:         """Änderung der Properties"""
  339:         
  340:         
  341:         coordsnew=[ string.split(x,",") for x in coords]
  342:         
  343:         
  344:         setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew)
  345: 
  346:         self.coords=coordsnew[0:]
  347:         self.link=link
  348:         self.metalink=metalink
  349:         
  350:         if RESPONSE is not None:
  351:             RESPONSE.redirect('manage_main')
  352:             
  353:             
  354:     manage_options = Folder.manage_options+(
  355:         {'label':'Main Config','action':'ECHO_resource_config'},
  356:         {'label':'Metadata','action':'ECHO_getResourceMD'},
  357:         {'label':'Graphics','action':'ECHO_graphicEntry'},
  358:         )
  359: 
  360:     def getOverview(self):
  361:         """overview graphics"""
  362:         
  363:         return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
  364: 
  365:     def ECHO_graphicEntry(self):
  366:         """DO nothing"""
  367:         overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
  368:         if overview: 
  369:             pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
  370:             return pt()
  371:         else:
  372:             return "NO OVERVIEW GRAPHICS"
  373: 
  374:     def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
  375:         """Enter coords"""
  376:         coords=self.coords
  377:         temco=coordstr.split(",")
  378:         temco.append(angle)
  379:         coords.append(temco)
  380:         
  381:         self.coords=coords[0:]
  382: 
  383:         if RESPONSE is not None:
  384:             RESPONSE.redirect('ECHO_graphicEntry')
  385: 
  386:     def ECHO_getResourceMD(self,template="yes"):
  387:         """Einlesen der Metadaten und Anlegen dieser Metadaten als Informationen zur Resource"""
  388:         (metadict, error)=readMetadata(self.metalink)
  389: 
  390: 
  391: 
  392:         if not error=="": #Fehler beim Auslesen des Metafiles
  393:             return "ERROR:",error
  394:         for key in metadict.keys():#Hinzufügen der Felder
  395: 
  396:             setattr(self,key,metadict[key].encode('ascii','replace'))
  397:         
  398: 
  399:         self.metadata=metadict.keys()
  400: 
  401:         self.label=self.generate_label()
  402:         
  403:         if template=="yes":
  404:             pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_resourceMD.zpt').__of__(self)
  405:             return pt()
  406:     
  407:     def ECHO_getMD(self,item):
  408:         """Ausgabe der MD"""
  409:         return getattr(self,item)
  410:         
  411:     def index_html(self):
  412:         """standard page"""
  413:         
  414:         return self.REQUEST.RESPONSE.redirect(self.link)
  415: 
  416:     def generate_label(self):
  417:         """Erzeugt_standard_Label aus Template"""
  418:         pt=getattr(self,"label_template_"+self.bib_type)
  419: 
  420:         return pt()
  421: 
  422: def manage_addECHO_resourceForm(self):
  423:         """Form for adding a ressource"""
  424:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_resourceForm.zpt').__of__(self)
  425:         return pt()
  426: 
  427: 
  428: 
  429: def manage_addECHO_resource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None):
  430:     """addaresource"""
  431: 
  432:     newObj=ECHO_resource(id,link,metalink,title,label,description,contentType,responsible,credits,weight,coords)
  433: 
  434:     self._setObject(id,newObj)
  435: 
  436:     if RESPONSE is not None:
  437:         RESPONSE.redirect('manage_main')
  438:  
  439: 
  440: class ECHO_externalLink(Folder):
  441:     """Link zu einer externen Ressource"""
  442:     security=ClassSecurityInfo()
  443:     meta_type='ECHO_externalLink'
  444: 
  445:     def content_html(self):
  446:         """template fuer content"""
  447:         return content_html(self,'externalLink')
  448:     
  449:     def __init__(self,id,link,title,label,description,contentType,responsible,credits,weight,coords):
  450: 
  451:         self.id = id
  452:         """Festlegen der ID"""
  453: 
  454:         self.credits=toList(credits)
  455:         self.label = label
  456:         self.link= link
  457:         self.title=title
  458:         self.weight=weight
  459:         self.description=description
  460:         self.contentType=contentType
  461:         self.responsible=responsible
  462:         coordsnew=[ string.split(x,",") for x in coords]
  463:         self.coords=coordsnew
  464: 
  465:     def ECHO_externalLink_config(self):
  466:         """Main configuration"""
  467: 
  468:         if not hasattr(self,'weight'):
  469:             self.weight=""
  470:         if not hasattr(self,'coords'):
  471:             
  472:             self.coords=['']
  473:             #print "G",self.coords
  474: 
  475:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_externalLink.zpt').__of__(self)
  476:         return pt()
  477:     
  478: 
  479:     def changeECHO_externalLink(self,link,title,label,description,contentType,responsible,weight,coords=None,credits=None,RESPONSE=None):
  480: 
  481:         """Änderung der Properties"""
  482:         coordsnew=[ string.split(x,",") for x in coords]
  483: 
  484:         setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coords)
  485: 
  486:         self.coords=coordsnew[0:]
  487:         self.link=link
  488:         if RESPONSE is not None:
  489:             RESPONSE.redirect('manage_main')
  490:             
  491:             
  492:     manage_options = Folder.manage_options+(
  493:         {'label':'Main Config','action':'ECHO_externalLink_config'},
  494:         )
  495: 
  496:     def getCredits(self):
  497:         """Ausgabe der credits"""
  498:         if self.credits:
  499:             return self.credits
  500:         else:
  501:             return []
  502:         
  503:     def index_html(self):
  504:         """standard page"""
  505:         
  506:         return self.REQUEST.RESPONSE.redirect(self.link)
  507: 
  508: def manage_addECHO_externalLinkForm(self):
  509:         """Form for external Links"""
  510:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_externalLinkForm.zpt').__of__(self)
  511:         return pt()
  512: 
  513: 
  514: def manage_addECHO_externalLink(self,id,title,label,description,contentType,responsible,link,weight,coords=None,credits=None,RESPONSE=None):
  515:     """Add an external Link"""
  516: 
  517:     newObj=ECHO_externalLink(id,link,title,label,description,contentType,responsible,credits,weight,coords)
  518: 
  519:     self._setObject(id,newObj)
  520: 
  521:     if RESPONSE is not None:
  522:         RESPONSE.redirect('manage_main')
  523:  
  524: 
  525: 
  526: class ECHO_collection(Folder, Persistent, Implicit):
  527:     """ECHO Collection"""
  528:     security=ClassSecurityInfo()
  529:     meta_type='ECHO_collection'
  530: 
  531:     def getImageTag(self):
  532:         """GetTag"""
  533:         try:
  534:             return self.imageTag
  535:         except:
  536:             return ""
  537: 
  538:     def addResource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None):
  539:         """SSS"""
  540:         try:
  541:             manage_addECHO_resource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None)
  542:             return "done"
  543:         except:
  544:             return None
  545: 
  546:     def getSecondaryLink(self):
  547:         """secondary link"""
  548:         try:
  549:             return self.secondaryLink
  550:         except:
  551:             return ""
  552: 
  553:     def getSecondaryLinkTitle(self):
  554:         """secondary link"""
  555:         try:
  556:             return self.secondaryLinkTitle
  557:         except:
  558:             return ""
  559:         
  560:     def getCollectionTreeXML(self):
  561:         """Tree as XML"""
  562: 
  563:         def getCollection(object,depth=0):
  564:             depth+=1
  565:             collections=""
  566:             for entry in object.__dict__.keys():
  567:                 element=getattr(object,entry)
  568:                 try:
  569:                     if element.meta_type=="ECHO_collection":
  570:                         collections+="<element name=\""+element.title+"\" url=\""+element.absolute_url()+"\">"
  571:                         collections+=getCollection(element,depth)+"</element>\n"
  572:                 except:
  573:                     """nothing"""
  574:             return collections
  575:         
  576: 
  577:         return "<collection>"+getCollection(self)+"</collection>"
  578:     
  579:     def createJavaScript(self):
  580:         """CreateJava"""
  581:         ret=javaScriptMain
  582: 
  583:         dynamical=""
  584:         for ob in self.getGraphicCoords():
  585:             dynamical+="""Coords.push(new Coord('%s', Img, %s));\n"""%(ob[1],ob[0])
  586:         ret+=javaHandler%dynamical
  587:         return ret
  588:     
  589:     security.declarePublic('getCreditObject')
  590:     def getCreditObject(self,name):
  591:         """credit id to credititem"""
  592:         try:
  593:             return getattr(self.partners,name)
  594:         except:
  595:             return ""
  596: 
  597:     security.declarePublic('ECHO_generateNavBar')
  598:     def ECHO_generateNavBar(self):
  599:         """Erzeuge Navigationsbar"""
  600:         link=""
  601:         object="self"
  602:         ret=[]
  603:         path=self.getPhysicalPath()
  604:         for element in path:
  605:             
  606:            
  607:             if not element=="":
  608:                 object+="."+element
  609:                 
  610:                 label=eval(object).label
  611:                 link+="/"+element
  612:                 if not label=="":
  613:                     ret.append((label,link))
  614:         return ret
  615:     
  616:     security.declarePublic('ECHO_rerenderLinksMD')
  617:     def ECHO_rerenderLinksMD(self):
  618:         """Rerender all Links"""
  619:         
  620:         for entry in self.__dict__.keys():
  621:             object=getattr(self,entry)
  622:             
  623:             
  624:             try:
  625:                 
  626:                 if object.meta_type == 'ECHO_resource':
  627:                     
  628:                     object.ECHO_getResourceMD(template="no")
  629:                     
  630:             except:
  631:                 """nothing"""
  632:                 
  633:         return "Rerenderd all links to resources in: "+self.title
  634: 
  635:     security.declarePublic('ECHO_newViewerLink')
  636:     
  637: 
  638:     def getCoords(self):
  639:         try:
  640:             
  641:             x=  [string.join(x,",") for x in self.coords]  
  642:             return x
  643: 
  644:         except:
  645: 
  646:             return []
  647:         
  648:     def __init__(self,id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle,secondaryLink,imageTag=""):
  649:         #print "CO",coords
  650: 
  651:         self.id = id
  652:         """Festlegen der ID"""
  653:         self.credits=toList(credits)
  654:         self.label = label
  655:         self.title=title
  656:         self.description=description
  657:         self.contentType=contentType
  658:         self.responsible=responsible
  659:         self.imageTag=imageTag
  660:         self.weight=weight
  661:         self.sortfield=sortfield
  662:         coordsnew=[ string.split(x,",") for x in coords]
  663:         self.coords=coordsnew
  664:         self.secondaryLinkTitle=secondaryLinkTitle
  665:         self.secondaryLink=secondaryLink
  666:         
  667: 
  668:     manage_options = Folder.manage_options+(
  669:         {'label':'Main Config','action':'ECHO_collection_config'},
  670:         {'label':'Rerender Links','action':'ECHO_rerenderLinksMD'},
  671:         {'label':'Graphics','action':'ECHO_graphicEntry'},
  672: 
  673:         )
  674: 
  675:     def getOverview(self):
  676:         """overview graphics"""
  677:         
  678:         return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
  679:     
  680:     
  681:     def ECHO_graphicEntry(self):
  682:         """DO nothing"""
  683:         overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
  684:         
  685:     
  686:         if overview:
  687:             pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
  688:             return pt()
  689:         else:
  690:             return "NO OVERVIEW GRAPHICS"
  691: 
  692:     def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
  693:         """Enter coords"""
  694:         coords=self.coords
  695:         temco=coordstr.split(",")
  696:         temco.append(angle)
  697:         coords.append(temco)
  698:         self.coords=coords[0:]
  699: 
  700:         if RESPONSE is not None:
  701:             RESPONSE.redirect('ECHO_graphicEntry')
  702: 
  703:     
  704:     security.declarePublic('ECHO_collection_config')
  705:     def ECHO_collection_config(self):
  706:         """Main configuration"""
  707: 
  708:         if not hasattr(self,'weight'):
  709:             self.weight=""
  710: 
  711:         if not hasattr(self,'sortfield'):
  712:             self.sortfield="weight"
  713:   
  714:         if not hasattr(self,'coords'):
  715:             self.coords=[]
  716: 
  717:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_collection.zpt').__of__(self)
  718:         return pt()
  719: 
  720: 
  721:     security.declarePublic('changeECHO_collection')
  722: 
  723: 
  724:     def changeECHO_collection(self,title,label,description,contentType,responsible,weight,secondaryLink,secondaryLinkTitle,credits=None,sortfield="weight",coords=None,RESPONSE=None,imageTag=""):
  725:         """Änderung der Properties"""
  726: 
  727:         self.secondaryLink=secondaryLink
  728:         self.secondaryLinkTitle=secondaryLinkTitle
  729:         self.imageTag=imageTag
  730:         if coords:
  731:             coordsnew=[ string.split(x,",") for x in coords]
  732:             self.coords=coordsnew[0:]
  733:         else:
  734:             coordsnew=None
  735:             self.coords=None
  736:             
  737:         setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew)
  738: 
  739:     
  740:         
  741:         self.sortfield=sortfield
  742: 
  743:         if RESPONSE is not None:
  744:             RESPONSE.redirect('manage_main')
  745:             
  746:     security.declarePublic('index_html')
  747: 
  748: 
  749:     def showOverview(self):
  750:         """overview"""
  751:         if 'ECHO_overview.html' in self.__dict__.keys():
  752:             return getattr(self,'ECHO_overview.html')()
  753:         pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_overview.zpt').__of__(self)
  754:         return pt()
  755: 
  756:     
  757:     def index_html(self):
  758:         """standard page"""
  759:         
  760:         if 'index.html' in self.__dict__.keys():
  761:             return getattr(self,'index.html')()
  762:         
  763:         elif 'overview' in self.__dict__.keys():
  764:             return self.showOverview()
  765:         elif hasattr(self,'collection_index_template'):
  766:             return self.collection_index_template()    
  767:         
  768:         pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_standard.zpt').__of__(self)
  769:         pt.content_type="text/html"
  770:         return pt()
  771: 
  772:     def content_html(self):
  773:         """template fuer content"""
  774:         return content_html(self,'collection')
  775:     
  776:     def getCredits(self):
  777:         """Ausgabe der credits"""
  778:         if self.credits:
  779:             return self.credits
  780:         else:
  781:             return []
  782: 
  783: 
  784:         
  785:     def getGraphicCoords(self):
  786:         """Give list of coordinates"""
  787:         subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
  788:         ids=[]
  789:         for entry in self.__dict__.keys():
  790:             object=getattr(self,entry)
  791:             try:
  792:                 if object.meta_type in subColTypes:
  793:                     for coordtemp in object.coords:
  794:                         if len(coordtemp)>3:
  795:                             coord=coordtemp[0:4]
  796:                             if hasattr(object,'label') and not object.label=="":
  797:                                 ids.append([string.join(coord,", "),object.getId(),object.label,object])
  798:                             elif hasattr(object,'title'):
  799:                                 if not object.title=="":
  800:                                     ids.append([string.join(coord,", "),object.getId(),object.title,object])
  801:                                 else:
  802:                                     ids.append([string.join(coord,", "),object.getId(),object.getId(),object])
  803:                             else:
  804:                                 ids.append([string.join(coord,", "),object.getId(),object.getId(),object])
  805:                     
  806:             except:
  807:                 """nothing"""
  808: 
  809:         return ids
  810:     
  811:     def getSubCols(self,sortfield="weight"):
  812: 
  813:         subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
  814:         ids=[]
  815:         for entry in self.__dict__.keys():
  816:             object=getattr(self,entry)
  817:             try:
  818:                 if object.meta_type in subColTypes:
  819:                     ids.append(object)
  820:                     
  821:             except:
  822:                 """nothing"""
  823:         try:
  824:             sortfield=self.sortfield
  825:         except:
  826:             """nothing"""
  827:             
  828:         tmplist=[]
  829:         for x in ids:
  830:             if hasattr(x,sortfield):
  831:                 try:
  832:                     x=int(x)
  833:                 except:
  834:                     """nothing"""
  835:                 tmp=getattr(x,sortfield)
  836:             else:
  837:                 tmp=10000000
  838:             tmplist.append((tmp,x))
  839:         tmplist.sort()
  840:         return [x for (key,x) in tmplist]
  841:      
  842:         
  843:         
  844:                 
  845:     
  846:     
  847: def manage_addECHO_collectionForm(self):
  848:         """Add collection form"""
  849:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_collectionForm.zpt').__of__(self)
  850:         return pt()
  851: 
  852: 
  853: def manage_addECHO_collection(self,id,title,label,description,contentType,responsible,weight,sortfield,coords="",secondaryLinkTitle="",secondaryLink="",credits=None,RESPONSE=None,imageTag=""):
  854:     """add a echo collection"""
  855:     
  856: 
  857:     newObj=ECHO_collection(id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle=secondaryLinkTitle,secondaryLink=secondaryLink,imageTag=imageTag)
  858: 
  859:     self._setObject(id,newObj)
  860: 
  861:     if RESPONSE is not None:
  862:         RESPONSE.redirect('manage_main')
  863: 
  864: class ECHO_root(Folder,Persistent,Implicit):
  865:     """ECHO Root Folder"""
  866:     meta_type="ECHO_root"
  867: 
  868: 
  869:     def contentTypeSelector_HTML(self,selected=None):
  870:         """give type selector"""
  871:         if not selected:
  872:             retStr="<option selected>\n"
  873:         else:
  874:             retStr="<option>\n"
  875:             
  876:         try:
  877:             for contentType in self.ZopeFind(self.contentTypes,obj_metatypes="ECHO_contentType"):
  878:                 if selected and (contentType[0]==selected):
  879:                     retStr+="""<option selected value="%s">%s\n"""%(contentType[0],contentType[0])
  880:                 else:                
  881:                     retStr+="""<option value="%s">%s\n"""%(contentType[0],contentType[0])
  882:         except:
  883:             """nothing"""
  884:         return retStr
  885:             
  886:     def patchContentType(self,obj=None):
  887:         """austauschen content_type with contentType (patch bei umstieg von alter Version)"""
  888:     
  889: 
  890:         if not obj:
  891:             obj = self
  892:             
  893:         entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection','ECHO_externalLink','ECHO_pageTemplate'])
  894: 
  895:         for entry in entries:
  896:                 setattr(entry[1],'contentType',entry[1].content_type)
  897:                 #entry[1].contentType == entry[1].content_type
  898: 
  899:                 if entry[1].meta_type == 'ECHO_collection':
  900:                     entry[1].patchContentType(entry[1])    
  901: 
  902:                 
  903:         return "Rerenderd all links to resources in: "+self.title
  904:     
  905:     def ECHO_newViewerLink(self,obj=None):
  906:         """change links (:86 faellt weg)"""
  907: 
  908:         if not obj:
  909:             obj = self
  910:             
  911:         entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection'])
  912: 
  913:         for entry in entries:
  914:                 
  915:                 if entry[1].meta_type == 'ECHO_resource':
  916:                     
  917:                     entry[1].link=re.sub('\:86','',entry[1].link)
  918: 
  919:                 else:
  920:                     
  921:                     entry[1].ECHO_newViewerLink(entry[1])
  922:                 
  923:         return "Rerenderd all links to resources in: "+self.title
  924: 
  925:     def __init__(self,id,title):
  926:         """init"""
  927:         self.id = id
  928:         self.title=title
  929: 
  930:     def deleteSpace(self,str):
  931:         """delete space at the end of a line"""
  932:         if str[len(str)-1]==" ":
  933:             return str[0:len(str)-1]
  934:         else:
  935:             return str
  936:         
  937:     
  938: 
  939:     # zusaetliche methoden fuer das vlp muessen in ein eigenes produkt
  940: 
  941:     def formatAscii(self,str,url=None):
  942:         """ersetze ascii umbrueche durch <br>"""
  943:         #url=None
  944:         if url:
  945:             
  946:             retStr=""
  947:             words=str.split("\n")
  948:             
  949:             for word in words:
  950:                 strUrl=url%word
  951:                 print "str",strUrl
  952:                 retStr+="""<a href="%s">%s</a><br/>"""%(strUrl,word)
  953:             str=retStr
  954:         if str:
  955:             return re.sub(r"[\n]","<br/>",str)
  956:         else:
  957:             return ""
  958:         
  959:     def link2html(self,str):
  960:         """link2html fuer VLP muss hier noch raus"""
  961:         if str:
  962:             print str
  963:             str=re.sub("\&","&amp;",str)
  964:             dom=xml.dom.minidom.parseString("<?xml version='1.0' ?><txt>"+str+"</txt>")
  965:             links=dom.getElementsByTagName("link")
  966:             
  967:             print "link",links
  968:             for link in links:
  969:                 link.tagName="a"
  970:                 ref=link.getAttribute("ref")
  971:                 if self.checkRef(ref):
  972:                     link.setAttribute("href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref)
  973: 
  974:             return dom.toxml('utf-8')
  975:         return ""
  976: 
  977: 
  978:     def checkRef(self,ref):
  979:         dbs={'vl_literature':'AND CD LIKE \'%lise%\'','vl_technology':'','vl_people':''}
  980:         res=None
  981:         for db in dbs.keys():
  982:             #print ref,"select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])
  983: 
  984:             res=res or self.search(var=str("select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])))
  985:         return res
  986:                                     
  987:     #Ende Methode fuer vlp
  988: 
  989:     def PgQuoteString(self,string):
  990:         """Quote string"""
  991:         #print "PG",string
  992:         return libpq.PgQuoteString(string)
  993:         
  994:     def getPartners(self):
  995:         """Get list of Partners. Presently only from a subfolder partners"""
  996:                     
  997:         return [ item[1] for item in self.partners.ZopeFind(self.partners,obj_metatypes=['ECHO_partner'])]
  998:                 
  999:                 
 1000:                    
 1001: 
 1002:     
 1003:     def getPartnersXML(self):
 1004:         """partner liste als xml""" 
 1005:         partners=self.getPartners()
 1006:         ret="<partners>"
 1007:         for partner in partners:
 1008:             ret+="""<partner id="%s" title="%s"/>\n"""%(partner.getId(),partner.title)
 1009: 
 1010:         return ret+"\n</partners>"
 1011:     
 1012:     def getCollectionTree(self):
 1013:         """get the collection tree (list of triples (parent,child, depth)"""
 1014: 
 1015:         def getCollection(object,depth=0):
 1016:             depth+=1
 1017:             collections=[]
 1018:             for entry in object.__dict__.keys():
 1019:                 element=getattr(object,entry)
 1020:                 try:
 1021:                     if element.meta_type=="ECHO_collection":
 1022:                         collections.append((object,element,depth))
 1023:                         collections+=getCollection(element,depth)
 1024:                 except:
 1025:                     """nothing"""
 1026:             return collections
 1027:         
 1028: 
 1029:         return getCollection(self)
 1030:     
 1031:     def getCollectionTreeIds(self):
 1032:         """Show the IDs of the Tree"""
 1033:         ret=[]
 1034:         for collection in self.getCollectionTree():
 1035:             ret.append((collection[0].getId(),collection[1].getId(),collection[2]))
 1036:         return ret
 1037: 
 1038:         
 1039:         
 1040: def manage_addECHO_root(self,id,title,RESPONSE=None):
 1041:     """Add an ECHO_root"""
 1042:     self._setObject(id,ECHO_root(id,title))
 1043:     
 1044:     if RESPONSE is not None:
 1045:         RESPONSE.redirect('manage_main')
 1046: 
 1047: def manage_addECHO_rootForm(self):
 1048:         """Nothing yet"""
 1049:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_root.zpt').__of__(self)
 1050:         return pt()
 1051:  
 1052: class ECHO_partner(Image,Persistent):
 1053:     """ECHO Partner"""
 1054: 
 1055:     meta_type="ECHO_partner"
 1056: 
 1057:     def __init__(self, id, title,url, file, content_type='', precondition=''):
 1058:         self.__name__=id
 1059:         self.title=title
 1060:         self.url=url
 1061:         self.precondition=precondition
 1062: 
 1063:         data, size = self._read_data(file)
 1064:         content_type=self._get_content_type(file, data, id, content_type)
 1065:         self.update_data(data, content_type, size)
 1066: 
 1067:     manage_options = Image.manage_options+(
 1068:         {'label':'Partner Information','action':'ECHO_partner_config'},
 1069:         )
 1070: 
 1071:     def changeECHO_partner(self,url,RESPONSE=None):
 1072:         """Change main information"""
 1073:         self.url=url
 1074:         if RESPONSE is not None:
 1075:             RESPONSE.redirect('manage_main')
 1076:             
 1077:             
 1078: 
 1079:     def ECHO_partner_config(self):
 1080:         """Main configuration"""
 1081:         if not hasattr(self,'url'):
 1082:             self.url=""
 1083:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_partner.zpt').__of__(self)
 1084:         return pt()
 1085: 
 1086:         
 1087: manage_addECHO_partnerForm=DTMLFile('dtml/ECHO_partnerAdd',globals(),
 1088:                              Kind='ECHO_partner',kind='ECHO_partner')
 1089: 
 1090: 
 1091: 
 1092: def manage_addECHO_partner(self, id, file,url, title='', precondition='', content_type='',
 1093:                     REQUEST=None):
 1094:     """
 1095:     Add a new ECHO_partner object.
 1096: 
 1097:     Creates a new ECHO_partner object 'id' with the contents of 'file'.
 1098:     Based on Image.manage_addImage
 1099:     """
 1100: 
 1101:     id=str(id)
 1102:     title=str(title)
 1103:     content_type=str(content_type)
 1104:     precondition=str(precondition)
 1105: 
 1106:     id, title = OFS.Image.cookId(id, title, file)
 1107: 
 1108:     self=self.this()
 1109: 
 1110:     # First, we create the image without data:
 1111:     self._setObject(id, ECHO_partner(id,title,url,'',content_type, precondition))
 1112: 
 1113:     # Now we "upload" the data.  By doing this in two steps, we
 1114:     # can use a database trick to make the upload more efficient.
 1115:     if file:
 1116:         self._getOb(id).manage_upload(file)
 1117:     if content_type:
 1118:         self._getOb(id).content_type=content_type
 1119: 
 1120:     if REQUEST is not None:
 1121:         try:    url=self.DestinationURL()
 1122:         except: url=REQUEST['URL1']
 1123:         REQUEST.RESPONSE.redirect('%s/manage_main' % url)
 1124:     return id
 1125: 
 1126: 

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