File:  [Repository] / ECHO_content / ECHO_collection.py
Revision 1.72: download - view: text, annotated - select for diffs - revision graph
Fri May 7 18:04:29 2004 UTC (20 years, 1 month ago) by casties
Branches: MAIN
CVS tags: HEAD
restore compatibility with old version of createjavascript

    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: 
  688:         dynamical="\n"
  689:         for ob in self.getGraphicCoords():
  690: 	    if ob[4][4] == "":	
  691: 	        dynamical+="""Coords.push(new Coord('%s', Img, %s));\n"""%(ob[1],ob[0])
  692: 	    else:
  693: 		dynamical+="""Coords.push(new Coord('%s', Img, %s));//%s\n"""%(ob[1],ob[0],ob[4][4])
  694: 		dynamical+="ShowArrow(new getObj('i.%s'),Img,%s);\n"%(ob[1],ob[0])
  695: 	ret+=javaHandler%dynamical
  696:         return ret
  697: 
  698:     def createJSAreas(self):
  699:         """CreateJava"""
  700:         dynamical="\n"
  701:         for ob in self.getGraphicCoords():
  702: 	    if ob[5] == "area":	
  703: 	        dynamical+="""addArea('%s', 'overview', %s, 'area');\n"""%(ob[1],ob[0])
  704: 	    else:
  705: 	        dynamical+="""addArea('%s', 'overview', %s, 'arrow');\n"""%(ob[1],ob[0])
  706:         return dynamical
  707:     
  708:     security.declarePublic('getCreditObject')
  709:     def getCreditObject(self,name):
  710:         """credit id to credititem"""
  711:         try:
  712:             return getattr(self.partners,name)
  713:         except:
  714:             return ""
  715: 
  716:     security.declarePublic('ECHO_generateNavBar')
  717:     def ECHO_generateNavBar(self):
  718:         """Erzeuge Navigationsbar"""
  719:         link=""
  720:         object="self"
  721:         ret=[]
  722:         path=self.getPhysicalPath()
  723:         for element in path:
  724:             
  725:            
  726:             if not element=="":
  727:                 object+="."+element
  728:                 
  729:                 label=eval(object).label
  730:                 link+="/"+element
  731:                 if not label=="":
  732:                     ret.append((label,link))
  733:         return ret
  734:     
  735:     security.declarePublic('ECHO_rerenderLinksMD')
  736:     def ECHO_rerenderLinksMD(self,obj=None):
  737:         """Rerender all Links"""
  738:         if not obj:
  739:             obj = self
  740:             
  741:         entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection'])
  742: 
  743:         for entry in entries:
  744: 		if entry[1].meta_type == 'ECHO_resource':
  745: 			entry[1].ECHO_getResourceMD(template="no")
  746: 			print "rerender",entry[1].getId()
  747: 		else:
  748: 		   self.ECHO_rerenderLinksMD(entry[1])
  749: 
  750:                 
  751:                 
  752:         return "Rerenderd all links to resources in: "+self.title
  753: 
  754:     security.declarePublic('ECHO_newViewerLink')
  755:     
  756: 
  757:     def getCoords(self):
  758:         try:
  759:             
  760:             x=  [string.join(x,",") for x in self.coords]  
  761:             return x
  762: 
  763:         except:
  764: 
  765:             return []
  766:         
  767:     def __init__(self,id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle,secondaryLink,imageTag="",bgcolour=""):
  768:         #print "CO",coords
  769: 
  770:         self.id = id
  771:         """Festlegen der ID"""
  772:         self.credits=toList(credits)
  773:         self.label = label
  774:         self.title=title
  775:         self.description=description
  776:         self.contentType=contentType
  777:         self.responsible=responsible
  778:         self.imageTag=imageTag
  779:         self.weight=weight
  780:         self.sortfield=sortfield
  781:         coordsnew=[ string.split(x,",") for x in coords]
  782:         self.coords=coordsnew
  783:         self.secondaryLinkTitle=secondaryLinkTitle
  784:         self.secondaryLink=secondaryLink
  785: 	self.bgcolour=bgcolour
  786:         
  787: 
  788:     manage_options = Folder.manage_options+(
  789:         {'label':'Main Config','action':'ECHO_collection_config'},
  790:         {'label':'Rerender Links','action':'ECHO_rerenderLinksMD'},
  791:         {'label':'Graphics','action':'ECHO_graphicEntry'},
  792: 	{'label':'create resources from XML','action':'createRessourcesFromXMLForm'},
  793: 
  794:         )
  795: 
  796:     def getOverview(self):
  797:         """overview graphics"""
  798:         
  799:         return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
  800:     
  801:     
  802:     def ECHO_graphicEntry(self):
  803:         """DO nothing"""
  804:         overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
  805:         
  806:     
  807:         if overview:
  808:             pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
  809:             return pt()
  810:         else:
  811:             return "NO OVERVIEW GRAPHICS"
  812: 
  813:     def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
  814:         """Enter coords"""
  815:         coords=self.coords
  816:         temco=coordstr.split(",")
  817:         temco.append(angle)
  818:         coords.append(temco)
  819:         self.coords=coords[0:]
  820: 
  821:         if RESPONSE is not None:
  822:             RESPONSE.redirect('ECHO_graphicEntry')
  823: 
  824:     
  825:     security.declarePublic('ECHO_collection_config')
  826:     def ECHO_collection_config(self):
  827:         """Main configuration"""
  828: 
  829:         if not hasattr(self,'weight'):
  830:             self.weight=""
  831: 
  832:         if not hasattr(self,'sortfield'):
  833:             self.sortfield="weight"
  834:   
  835:         if not hasattr(self,'coords'):
  836:             self.coords=[]
  837: 
  838:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_collection.zpt').__of__(self)
  839:         return pt()
  840: 
  841: 
  842:     security.declarePublic('changeECHO_collection')
  843: 
  844: 
  845:     def getBgcolour(self):
  846: 	    """colour"""
  847: 	    if hasattr(self,'bgcolour') and not (self.bgcolour==""):
  848: 		    return self.bgcolour
  849: 	    else:
  850: 		    return "#dddddd"
  851: 	    
  852:     def changeECHO_collection(self,title,label,description,contentType,responsible,weight,secondaryLink,secondaryLinkTitle,credits=None,sortfield="weight",coords=None,RESPONSE=None,imageTag="",bgcolour="",viewClassification=None):
  853:         """Aenderung der Properties"""
  854: 
  855:         self.secondaryLink=secondaryLink
  856:         self.secondaryLinkTitle=secondaryLinkTitle
  857:         self.imageTag=imageTag
  858: 	self.bgcolour=bgcolour
  859:         self.viewClassification=viewClassification
  860: 	
  861:         if coords:
  862:             coordsnew=[ string.split(x,",") for x in coords]
  863:             self.coords=coordsnew[0:]
  864:         else:
  865:             coordsnew=None
  866:             self.coords=None
  867:             
  868:         setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew)
  869: 	try:
  870: 		self.coords=coordsnew[0:] # HACK fehler in setECHO_collection
  871:         except:
  872: 		"""none"""
  873: 		
  874:         self.sortfield=sortfield
  875: 
  876:         if RESPONSE is not None:
  877:             RESPONSE.redirect('manage_main')
  878:             
  879:     security.declarePublic('index_html')
  880: 
  881: 
  882:     def showOverview(self):
  883:         """overview"""
  884:         if 'ECHO_overview.html' in self.__dict__.keys():
  885:             return getattr(self,'ECHO_overview.html')()
  886:         pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_overview.zpt').__of__(self)
  887:         return pt()
  888: 
  889:     
  890:     def index_html(self):
  891:         """standard page"""
  892:         
  893:         if 'index.html' in self.__dict__.keys():
  894:             return getattr(self,'index.html')()
  895:         
  896:         elif 'overview' in self.__dict__.keys():
  897:             return self.showOverview()
  898:         elif hasattr(self,'collection_index_template'):
  899:             return self.collection_index_template()    
  900:         elif hasattr(self,'main_index_template'):
  901:             return self.main_index_template()    
  902:         
  903:         pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_main_index_template_standard.zpt').__of__(self)
  904:         pt.content_type="text/html"
  905:         return pt()
  906: 
  907:     def content_html(self):
  908:         """template fuer content"""
  909:         return content_html(self,'collection')
  910:     
  911:     def getCredits(self):
  912:         """Ausgabe der credits"""
  913:         if self.credits:
  914:             return self.credits
  915:         else:
  916:             return []
  917: 
  918:     def area_img(self):
  919:         """area image"""
  920:         sendFile(self, 'images/red.gif', 'image/gif')
  921:         return 
  922: 
  923:     def hl_lib_js(self):
  924:         """javascript"""
  925:         sendFile(self, 'js/hl_lib.js', 'text/plain')
  926:         return 
  927: 
  928:     def js_lib_js(self):
  929:         """javascript"""
  930:         sendFile(self, 'js/js_lib.js', 'text/plain')
  931:         return 
  932: 
  933:         
  934:     def getGraphicCoords(self):
  935:         """Give list of coordinates"""
  936:         subColTypes=['ECHO_collection','ECHO_resource']
  937:         ids=[]
  938:         for entrySearch in self.ZopeFind(self,obj_metatypes=subColTypes):
  939:             object=entrySearch[1]
  940:             if hasattr(object,'coords'):
  941:                 for coordtemp in object.coords:
  942:                     if len(coordtemp)>3:
  943:                         coord=coordtemp[0:4]
  944:                         label=""
  945: 			vc=""
  946:                         if hasattr(object,'label') and not object.label=="":
  947:                             label=object.label
  948:                         elif hasattr(object,'title') and not object.title=="":
  949:                             label=object.title
  950:                         else:
  951:                             label=object.getId()
  952: 			if object.viewClassification != "":
  953: 			    vc=object.viewClassification
  954: 			else:
  955: 			    if len(coordtemp) > 4 and coordtemp[4] != "":
  956: 				vc="view point"
  957: 			    else:
  958: 				vc="area"
  959:                         ids.append([string.join(coord,", "),object.getId(),label,object,coordtemp,vc])
  960:         return ids
  961:     
  962: 
  963: 
  964: 
  965:     getSubCols = ECHO_helpers.getSubCols
  966:      
  967:                 
  968:     
  969:     
  970: def manage_addECHO_collectionForm(self):
  971:         """Add collection form"""
  972:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_collectionForm.zpt').__of__(self)
  973:         return pt()
  974: 
  975: 
  976: def manage_addECHO_collection(self,id,title,label,description,contentType,responsible,weight,sortfield,coords="",secondaryLinkTitle="",secondaryLink="",credits=None,RESPONSE=None,imageTag="",bgcolour=""):
  977:     """add a echo collection"""
  978:     
  979: 
  980:     newObj=ECHO_collection(id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle=secondaryLinkTitle,secondaryLink=secondaryLink,imageTag=imageTag,bgcolour="")
  981: 
  982:     self._setObject(id,newObj)
  983: 
  984:     if RESPONSE is not None:
  985:         RESPONSE.redirect('manage_main')
  986: 
  987: class ECHO_group(ECHO_collection):
  988: 	"""ECHO Gruppe"""
  989: 	meta_type="ECHO_group"
  990: 
  991: 	manage_options = Folder.manage_options+(
  992: 		{'label':'Main Config','action':'ECHO_group_config'},
  993: 		{'label':'Rerender Links','action':'ECHO_rerenderLinksMD'},
  994: 		{'label':'Graphics','action':'ECHO_graphicEntry'},
  995: 		)
  996: 
  997: 	def index_html(self):
  998: 		"""standard page"""
  999: 		displayedObjects=self.ZopeFind(self,obj_metatypes=displayTypes)
 1000: 		#if (len(displayedObjects)==1) and (displayedObjects[0][1].meta_type=="ECHO_collection"): # nur ein Object dann redirect auf dieses Object
 1001: 		#	return self.REQUEST.RESPONSE.redirect(displayedObjects[0][1].absolute_url())
 1002: 		
 1003: 		if 'index.html' in self.__dict__.keys():
 1004: 			return getattr(self,'index.html')()
 1005: 		
 1006: 		elif 'overview' in self.__dict__.keys():
 1007: 			return self.showOverview()
 1008: 		elif hasattr(self,'group_index_template'):
 1009: 			return self.group_index_template()
 1010: 		elif hasattr(self,'collection_index_template'):
 1011: 			return self.collection_index_template()    
 1012: 		elif hasattr(self,'main_index_template'):
 1013: 		    return self.main_index_template()    
 1014: 
 1015: 		pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_main_index_template_standard.zpt').__of__(self)
 1016: 		pt.content_type="text/html"
 1017: 		return pt()
 1018: 
 1019: 	def ECHO_group_config(self):
 1020: 		"""Main configuration"""
 1021: 		
 1022: 		if not hasattr(self,'weight'):
 1023: 			self.weight=""
 1024: 			
 1025: 		if not hasattr(self,'sortfield'):
 1026: 			self.sortfield="weight"
 1027: 				
 1028: 		if not hasattr(self,'coords'):
 1029: 			self.coords=[]
 1030: 
 1031: 		pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_group.zpt').__of__(self)
 1032: 		return pt()
 1033: 
 1034: 	def changeECHO_group(self,title,label,description,contentType,responsible,weight,secondaryLink,secondaryLinkTitle,credits=None,sortfield="weight",coords=None,RESPONSE=None,imageTag="",bgcolour="",logo=""):
 1035: 		"""Änderung der Properties"""
 1036: 
 1037: 		self.secondaryLink=secondaryLink
 1038: 		self.secondaryLinkTitle=secondaryLinkTitle
 1039: 		self.imageTag=imageTag
 1040: 		self.bgcolour=bgcolour
 1041:                 self.logo=logo
 1042:                 
 1043: 		if coords:
 1044: 		    coordsnew=[ string.split(x,",") for x in coords]
 1045: 		    self.coords=coordsnew[0:]
 1046: 		else:
 1047: 		    coordsnew=None
 1048: 		    self.coords=None
 1049: 
 1050: 		setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew)
 1051: 
 1052: 
 1053: 
 1054: 		self.sortfield=sortfield
 1055: 
 1056: 		if RESPONSE is not None:
 1057: 		    RESPONSE.redirect('manage_main')
 1058: 
 1059: 	def getLogo(self):    
 1060: 		"""logo ausgeben"""
 1061:                 try:
 1062:                     return self.logo
 1063:                 except:
 1064:                     return "ECHO_groups"
 1065: 
 1066: 	def content_html(self):
 1067: 		"""template fuer content"""
 1068: 		return content_html(self,'group')
 1069:     
 1070: 
 1071: 
 1072: def manage_addECHO_groupForm(self):
 1073:         """Add group form"""
 1074:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_groupForm.zpt').__of__(self)
 1075:         return pt()
 1076: 
 1077: 
 1078: def manage_addECHO_group(self,id,title,label,description,contentType,responsible,weight,sortfield,coords="",secondaryLinkTitle="",secondaryLink="",credits=None,RESPONSE=None,imageTag="",bgcolour="",logo=""):
 1079:     """add a echo group"""
 1080:     
 1081: 
 1082:     newObj=ECHO_group(id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle=secondaryLinkTitle,secondaryLink=secondaryLink,imageTag=imageTag,bgcolour="")
 1083: 
 1084:     setattr(newObj,'logo',logo)
 1085:     self._setObject(id,newObj)
 1086:     
 1087:     if RESPONSE is not None:
 1088:         RESPONSE.redirect('manage_main')
 1089: 
 1090: 
 1091: 	
 1092: class ECHO_root(Folder,Persistent,Implicit):
 1093:     """ECHO Root Folder"""
 1094:     meta_type="ECHO_root"
 1095: 
 1096:     
 1097:     def getImageTag(self):
 1098: 	    """needed by main_template"""
 1099: 	    return ""
 1100:     secondaryLink="" #needed by main_template
 1101:     secondaryLinkTitle="" #needed by main_template
 1102:     
 1103:     def getBgcolour(self):
 1104: 	"""hack"""
 1105: 	return "#dddddd"
 1106: 
 1107:     def contentTypeSelector_HTML(self,selected=None):
 1108:         """give type selector"""
 1109:         if not selected:
 1110:             retStr="<option selected>\n"
 1111:         else:
 1112:             retStr="<option>\n"
 1113:             
 1114:         try: # erste version contentTypes exists
 1115:             for contentType in self.ZopeFind(self.contentTypes,obj_metatypes=["ECHO_contentType"]):
 1116:                 if selected and (contentType[0]==selected):
 1117:                     retStr+="""<option selected value="%s">%s\n"""%(contentType[0],contentType[0])
 1118:                 else:                
 1119:                     retStr+="""<option value="%s">%s\n"""%(contentType[0],contentType[0])
 1120:         except:
 1121: 		try:
 1122: 			for contentType in self.ZopeFind(self.standardMD,obj_metatypes=["OSAS_MetadataMapping"]):
 1123: 				if selected and (contentType[0]==selected):
 1124: 					retStr+="""<option selected value="%s">%s\n"""%(contentType[0],contentType[0])
 1125: 				else:                
 1126: 					retStr+="""<option value="%s">%s\n"""%(contentType[0],contentType[0])
 1127: 		except:
 1128: 			"""nothing"""
 1129: 			    
 1130:         return retStr
 1131:             
 1132:     def patchContentType(self,obj=None):
 1133:         """austauschen content_type with contentType (patch bei umstieg von alter Version)"""
 1134:     
 1135: 
 1136:         if not obj:
 1137:             obj = self
 1138:             
 1139:         entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection','ECHO_externalLink','ECHO_pageTemplate'])
 1140: 
 1141:         for entry in entries:
 1142:                 setattr(entry[1],'contentType',entry[1].content_type)
 1143:                 #entry[1].contentType == entry[1].content_type
 1144: 
 1145:                 if entry[1].meta_type == 'ECHO_collection':
 1146:                     entry[1].patchContentType(entry[1])    
 1147: 
 1148:                 
 1149:         return "changed all contenttypes in: "+self.title
 1150: 
 1151: 
 1152:     def patchViewClassification(self,obj=None):
 1153:         """setze viewClassification heuristisch"""
 1154: 
 1155: 	def checkIfArrow(obj):
 1156: 		if hasattr(obj,'coords'):
 1157: 			for coordtemp in obj.coords:
 1158: 				print obj.title,len(coordtemp)
 1159: 				if (len(coordtemp)>4) and not (coordtemp[4]==''):
 1160: 					return 4
 1161: 			return None
 1162: 		return None
 1163: 	
 1164:         if not obj:
 1165:             obj = self
 1166:             
 1167:         entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection','ECHO_group'])
 1168: 
 1169:         for entry in entries:
 1170: 		
 1171: 		if checkIfArrow(entry[1]):
 1172: 			print "VP"
 1173: 			setattr(entry[1],'viewClassification','view point')
 1174: 		else:
 1175: 			print "area"
 1176: 			setattr(entry[1],'viewClassification','area')
 1177: 
 1178:                 #entry[1].contentType == entry[1].content_type
 1179: 
 1180:                 if entry[1].meta_type in ['ECHO_collection','ECHO_group']:
 1181:                     entry[1].patchViewClassification(entry[1])    
 1182: 
 1183:                 
 1184:         return "changed all contenttypes in: "+self.title
 1185: 
 1186:     def ECHO_newViewerLink(self,obj=None):
 1187:         """change links (:86 faellt weg)"""
 1188: 
 1189:         if not obj:
 1190:             obj = self
 1191:             
 1192:         entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection'])
 1193: 
 1194:         for entry in entries:
 1195:                 
 1196:                 if entry[1].meta_type == 'ECHO_resource':
 1197:                     
 1198:                     entry[1].link=re.sub('\:86','',entry[1].link)
 1199: 
 1200:                 else:
 1201:                     
 1202:                     entry[1].ECHO_newViewerLink(entry[1])
 1203:                 
 1204:         return "Rerenderd all links to resources in: "+self.title
 1205: 
 1206:     def __init__(self,id,title):
 1207:         """init"""
 1208:         self.id = id
 1209:         self.title=title
 1210: 
 1211:     def deleteSpace(self,str):
 1212:         """delete space at the end of a line"""
 1213:         if str[len(str)-1]==" ":
 1214:             return str[0:len(str)-1]
 1215:         else:
 1216:             return str
 1217:         
 1218:     
 1219: 
 1220:     # zusaetliche methoden fuer das vlp muessen in ein eigenes produkt
 1221: 
 1222:     def formatAscii(self,str,url=None):
 1223:         """ersetze ascii umbrueche durch <br>"""
 1224:         #url=None
 1225:         if url:
 1226:             
 1227:             retStr=""
 1228:             words=str.split("\n")
 1229:             
 1230:             for word in words:
 1231:                 strUrl=url%word
 1232:                 print "str",strUrl
 1233:                 retStr+="""<a href="%s">%s</a><br/>"""%(strUrl,word)
 1234:             str=retStr
 1235:         if str:
 1236:             return re.sub(r"[\n]","<br/>",str)
 1237:         else:
 1238:             return ""
 1239:         
 1240:     def link2html(self,str):
 1241:         """link2html fuer VLP muss hier noch raus"""
 1242:         if str:
 1243:             print str
 1244:             str=re.sub("\&","&amp;",str)
 1245:             dom=xml.dom.minidom.parseString("<?xml version='1.0' ?><txt>"+str+"</txt>")
 1246:             links=dom.getElementsByTagName("link")
 1247:             
 1248:             print "link",links
 1249:             for link in links:
 1250:                 link.tagName="a"
 1251:                 ref=link.getAttribute("ref")
 1252:                 if self.checkRef(ref):
 1253:                     link.setAttribute("href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref)
 1254: 
 1255:             return dom.toxml('utf-8')
 1256:         return ""
 1257: 
 1258: 
 1259:     def checkRef(self,ref):
 1260:         dbs={'vl_literature':'AND CD LIKE \'%lise%\'','vl_technology':'','vl_people':''}
 1261:         res=None
 1262:         for db in dbs.keys():
 1263:             #print ref,"select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])
 1264: 
 1265:             res=res or self.search(var=str("select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])))
 1266:         return res
 1267:                                     
 1268:     #Ende Methode fuer vlp
 1269: 
 1270:     def PgQuoteString(self,string):
 1271:         """Quote string"""
 1272:         #print "PG",string
 1273:         return libpq.PgQuoteString(string)
 1274:         
 1275:     def getPartners(self):
 1276:         """Get list of Partners. Presently only from a subfolder partners"""
 1277:                     
 1278:         return [ item[1] for item in self.partners.ZopeFind(self.partners,obj_metatypes=['ECHO_partner'])]
 1279:                 
 1280:                 
 1281:                    
 1282: 
 1283:     
 1284:     def getPartnersXML(self):
 1285:         """partner liste als xml""" 
 1286:         partners=self.getPartners()
 1287:         ret="""<?xml version="1.0" encoding="utf-8" ?>
 1288: 	<partners>"""
 1289:         
 1290: 	for partner in partners:
 1291:             ret+="""<partner id="%s" title="%s"/>\n"""%(partner.getId(),unicode(partner.title,'utf-8','replace'))
 1292: 
 1293:         return ret+"\n</partners>"
 1294:     
 1295:     def getCollectionTree(self):
 1296:         """get the collection tree (list of triples (parent,child, depth)"""
 1297: 
 1298:         def getCollection(object,depth=0):
 1299:             depth+=1
 1300:             collections=[]
 1301:             for entry in object.__dict__.keys():
 1302:                 element=getattr(object,entry)
 1303:                 try:
 1304:                     if element.meta_type=="ECHO_collection":
 1305:                         collections.append((object,element,depth))
 1306:                         collections+=getCollection(element,depth)
 1307:                 except:
 1308:                     """nothing"""
 1309:             return collections
 1310:         
 1311: 
 1312:         return getCollection(self)
 1313:     
 1314:     def getCollectionTreeIds(self):
 1315:         """Show the IDs of the Tree"""
 1316:         ret=[]
 1317:         for collection in self.getCollectionTree():
 1318:             ret.append((collection[0].getId(),collection[1].getId(),collection[2]))
 1319:         return ret
 1320: 
 1321:         
 1322:         
 1323: def manage_addECHO_root(self,id,title,RESPONSE=None):
 1324:     """Add an ECHO_root"""
 1325:     self._setObject(id,ECHO_root(id,title))
 1326:     
 1327:     if RESPONSE is not None:
 1328:         RESPONSE.redirect('manage_main')
 1329: 
 1330: def manage_addECHO_rootForm(self):
 1331:         """Nothing yet"""
 1332:         pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_root.zpt').__of__(self)
 1333:         return pt()
 1334:  
 1335: class ECHO_partner(Image,Persistent):
 1336:     """ECHO Partner"""
 1337: 
 1338:     meta_type="ECHO_partner"
 1339: 
 1340:     def __init__(self, id, title,url, file, content_type='', precondition=''):
 1341:         self.__name__=id
 1342:         self.title=title
 1343:         self.url=url
 1344:         self.precondition=precondition
 1345: 
 1346:         data, size = self._read_data(file)
 1347:         content_type=self._get_content_type(file, data, id, content_type)
 1348:         self.update_data(data, content_type, size)
 1349: 
 1350:     manage_options = Image.manage_options+(
 1351:         {'label':'Partner Information','action':'ECHO_partner_config'},
 1352:         )
 1353: 
 1354:     def changeECHO_partner(self,url,RESPONSE=None):
 1355:         """Change main information"""
 1356:         self.url=url
 1357:         if RESPONSE is not None:
 1358:             RESPONSE.redirect('manage_main')
 1359:             
 1360:             
 1361: 
 1362:     def ECHO_partner_config(self):
 1363:         """Main configuration"""
 1364:         if not hasattr(self,'url'):
 1365:             self.url=""
 1366:         pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_partner.zpt').__of__(self)
 1367:         return pt()
 1368: 
 1369:         
 1370: manage_addECHO_partnerForm=DTMLFile('dtml/ECHO_partnerAdd',globals(),
 1371:                              Kind='ECHO_partner',kind='ECHO_partner')
 1372: 
 1373: 
 1374: 
 1375: def manage_addECHO_partner(self, id, file,url, title='', precondition='', content_type='',
 1376:                     REQUEST=None):
 1377:     """
 1378:     Add a new ECHO_partner object.
 1379: 
 1380:     Creates a new ECHO_partner object 'id' with the contents of 'file'.
 1381:     Based on Image.manage_addImage
 1382:     """
 1383: 
 1384:     id=str(id)
 1385:     title=str(title)
 1386:     content_type=str(content_type)
 1387:     precondition=str(precondition)
 1388: 
 1389:     id, title = OFS.Image.cookId(id, title, file)
 1390: 
 1391:     self=self.this()
 1392: 
 1393:     # First, we create the image without data:
 1394:     self._setObject(id, ECHO_partner(id,title,url,'',content_type, precondition))
 1395: 
 1396:     # Now we "upload" the data.  By doing this in two steps, we
 1397:     # can use a database trick to make the upload more efficient.
 1398:     if file:
 1399:         self._getOb(id).manage_upload(file)
 1400:     if content_type:
 1401:         self._getOb(id).content_type=content_type
 1402: 
 1403:     if REQUEST is not None:
 1404:         try:    url=self.DestinationURL()
 1405:         except: url=REQUEST['URL1']
 1406:         REQUEST.RESPONSE.redirect('%s/manage_main' % url)
 1407:     return id
 1408: 
 1409: 

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