File:  [Repository] / ECHO_content / ECHO_collection.py
Revision 1.70: download - view: text, annotated - select for diffs - revision graph
Fri May 7 17:09:07 2004 UTC (20 years, 1 month ago) by casties
Branches: MAIN
CVS tags: HEAD
check number of coordinates...

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

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