--- ECHO_content/ECHO_collection.py 2004/03/01 17:42:49 1.15 +++ ECHO_content/ECHO_collection.py 2004/04/07 17:27:49 1.34 @@ -11,6 +11,7 @@ class ECHO_externalLink contains informa """ import string import re +import os import OFS.Image from types import * from OFS.Image import Image @@ -22,20 +23,36 @@ from Globals import InitializeClass from Globals import DTMLFile from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplate import PageTemplate -from Globals import Persistent +from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate +from Globals import Persistent, package_home from Acquisition import Implicit + #from psycopg import libpq #from pyPgSQL import libpq import xml.dom.minidom import urllib import xml.dom.minidom - +from ECHO_graphicalOverview import javaHandler,javaScriptMain #List of different types for the graphical linking viewer viewClassificationListMaster=['view point','area'] +def content_html(self,type): + """template fuer content""" + #templates = self.ZopeFind(self.aq_parent,obj_ids=[type+"_template"]) + # + #if templates: + # return templates[0][1]() + try: + obj=getattr(self,type+"_template") + return obj() + except: + pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_%s_template_standard.zpt'%type).__of__(self) + pt.content_type="text/html" + return pt() + def toList(field): """Einzelfeld in Liste umwandeln""" if type(field)==StringType: @@ -96,7 +113,7 @@ def readMetadata(url): return metadict,"" -def setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coordstrs,viewClassification=""): +def setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordstrs,viewClassification=""): """Allegemeine Informationen zu einer ECHO Collection""" @@ -105,7 +122,7 @@ def setECHO_collectionInformation(self,t self.label = label self.title=title self.description=description - self.content_type=content_type + self.contentType=contentType self.responsible=responsible self.credits=toList(credits) self.weight=weight @@ -173,6 +190,83 @@ class scientificInformation(Folder,Persi def get_period(self): return self.period +class ECHO_layoutTemplate(ZopePageTemplate): + """Create a layout Template for different purposes""" + + meta_type="ECHO_layoutTemplate" + + #manage_options=ZopePageTemplate.manage_options+( + # {'label':'Set back to Standard','action':'changeECHO_layoutTemplateToStandardForm'}, + # ) + + + def __init__(self, id, text=None, content_type=None,EchoType=None): + self.id = str(id) + + + + self.ZBindings_edit(self._default_bindings) + if text is None: + self._default_content_fn = os.path.join(package_home(globals()), + 'zpt/ECHO_%s_template_standard.zpt'%EchoType) + text = open(self._default_content_fn).read() + self.pt_edit(text, content_type) + + ## def changeECHO_layoutTemplateToStandardForm(self): +## """change form""" +## pt=PageTemplateFile('Products/ECHO_content/zpt/changeECHO_pageTemplateWeightForm.zpt').__of__(self) +## return pt() + + + """change form""" + + +def manage_addECHO_layoutTemplateForm(self): + """Form for adding""" + pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_layoutTemplate.zpt').__of__(self) + return pt() + +from urllib import quote + + +def manage_addECHO_layoutTemplate(self, EchoType,title=None,REQUEST=None): + "Add a Page Template with optional file content." + if type(EchoType)==StringType: + EchoTypes=[EchoType] + else: + EchoTypes=EchoType + + for singleType in EchoTypes: + + id = str(singleType)+"_template" + if REQUEST is None: + self._setObject(id, ECHO_layoutTemplate(id, text,EchoType=singleType)) + ob = getattr(self, id) + + if title: + ob.pt_setTitle(title) + return ob + else: + file = REQUEST.form.get('file') + headers = getattr(file, 'headers', None) + if headers is None or not file.filename: + zpt = ECHO_layoutTemplate(id,EchoType=singleType) + else: + zpt = ECHO_layoutTemplate(id, file, headers.get('content_type')) + + self._setObject(id, zpt) + ob = getattr(self, id) + if title: + ob.pt_setTitle(title) + + try: + u = self.DestinationURL() + except AttributeError: + u = REQUEST['URL1'] + + + REQUEST.RESPONSE.redirect(u+'/manage_main') + return '' class ECHO_resource(Folder): """ECHO Ressource""" @@ -180,6 +274,10 @@ class ECHO_resource(Folder): viewClassificationList=viewClassificationListMaster + def content_html(self): + """template fuer content""" + return content_html(self,'resource') + def getViewClassification(self): if hasattr(self,'viewClassification'): return self.viewClassification @@ -193,7 +291,7 @@ class ECHO_resource(Folder): else: return [] - def __init__(self,id,link,metalink,title,label,description,content_type,responsible,credits,weight,coords): + def __init__(self,id,link,metalink,title,label,description,contentType,responsible,credits,weight,coords): self.id = id """Festlegen der ID""" @@ -205,7 +303,7 @@ class ECHO_resource(Folder): self.weight=weight self.credits=toList(credits) self.description=description - self.content_type=content_type + self.contentType=contentType self.responsible=responsible if coords: @@ -231,19 +329,22 @@ class ECHO_resource(Folder): if not hasattr(self,'coords'): self.coords=[] + print "vorher",self.coords pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_resource.zpt').__of__(self) return pt() - def changeECHO_resource(self,metalink,link,title,label,description,content_type,responsible,weight,viewClassification="",coords=None,credits=None,RESPONSE=None): - - + def changeECHO_resource(self,metalink,link,title,label,description,contentType,responsible,weight,viewClassification="",coords=None,credits=None,RESPONSE=None): """Änderung der Properties""" - - setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coords,viewClassification) - + try: + coordsnew=[ string.split(x,",") for x in coords] + except: + coordsnew=[] + setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew) + + self.coords=coordsnew[0:] self.link=link self.metalink=metalink @@ -257,9 +358,15 @@ class ECHO_resource(Folder): {'label':'Graphics','action':'ECHO_graphicEntry'}, ) + def getOverview(self): + """overview graphics""" + + return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1] + def ECHO_graphicEntry(self): """DO nothing""" - if 'overview' in self.aq_parent.__dict__.keys(): + overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview']) + if overview: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self) return pt() else: @@ -320,10 +427,10 @@ def manage_addECHO_resourceForm(self): -def manage_addECHO_resource(self,id,title,label,description,content_type,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None): +def manage_addECHO_resource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None): """addaresource""" - newObj=ECHO_resource(id,link,metalink,title,label,description,content_type,responsible,credits,weight,coords) + newObj=ECHO_resource(id,link,metalink,title,label,description,contentType,responsible,credits,weight,coords) self._setObject(id,newObj) @@ -336,8 +443,11 @@ class ECHO_externalLink(Folder): security=ClassSecurityInfo() meta_type='ECHO_externalLink' - - def __init__(self,id,link,title,label,description,content_type,responsible,credits,weight,coords): + def content_html(self): + """template fuer content""" + return content_html(self,'externalLink') + + def __init__(self,id,link,title,label,description,contentType,responsible,credits,weight,coords): self.id = id """Festlegen der ID""" @@ -348,7 +458,7 @@ class ECHO_externalLink(Folder): self.title=title self.weight=weight self.description=description - self.content_type=content_type + self.contentType=contentType self.responsible=responsible coordsnew=[ string.split(x,",") for x in coords] self.coords=coordsnew @@ -367,14 +477,14 @@ class ECHO_externalLink(Folder): return pt() - def changeECHO_externalLink(self,link,title,label,description,content_type,responsible,weight,coords=None,credits=None,RESPONSE=None): + def changeECHO_externalLink(self,link,title,label,description,contentType,responsible,weight,coords=None,credits=None,RESPONSE=None): """Änderung der Properties""" - + coordsnew=[ string.split(x,",") for x in coords] - setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coords) + setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coords) - + self.coords=coordsnew[0:] self.link=link if RESPONSE is not None: RESPONSE.redirect('manage_main') @@ -383,7 +493,14 @@ class ECHO_externalLink(Folder): manage_options = Folder.manage_options+( {'label':'Main Config','action':'ECHO_externalLink_config'}, ) - + + def getCredits(self): + """Ausgabe der credits""" + if self.credits: + return self.credits + else: + return [] + def index_html(self): """standard page""" @@ -395,23 +512,80 @@ def manage_addECHO_externalLinkForm(self return pt() -def manage_addECHO_externalLink(self,id,title,label,description,content_type,responsible,link,weight,coords=None,credits=None,RESPONSE=None): +def manage_addECHO_externalLink(self,id,title,label,description,contentType,responsible,link,weight,coords=None,credits=None,RESPONSE=None): """Add an external Link""" - newObj=ECHO_externalLink(id,link,title,label,description,content_type,responsible,credits,weight,coords) + newObj=ECHO_externalLink(id,link,title,label,description,contentType,responsible,credits,weight,coords) self._setObject(id,newObj) if RESPONSE is not None: RESPONSE.redirect('manage_main') - + + class ECHO_collection(Folder, Persistent, Implicit): """ECHO Collection""" security=ClassSecurityInfo() meta_type='ECHO_collection' + def getImageTag(self): + """GetTag""" + try: + return self.imageTag + except: + return "" + + def addResource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None): + """SSS""" + try: + manage_addECHO_resource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None) + return "done" + except: + return None + + def getSecondaryLink(self): + """secondary link""" + try: + return self.secondaryLink + except: + return "" + + def getSecondaryLinkTitle(self): + """secondary link""" + try: + return self.secondaryLinkTitle + except: + return "" + + def getCollectionTreeXML(self): + """Tree as XML""" + + def getCollection(object,depth=0): + depth+=1 + collections="" + for entry in object.__dict__.keys(): + element=getattr(object,entry) + try: + if element.meta_type=="ECHO_collection": + collections+="" + collections+=getCollection(element,depth)+"\n" + except: + """nothing""" + return collections + + + return ""+getCollection(self)+"" + + def createJavaScript(self): + """CreateJava""" + ret=javaScriptMain + dynamical="" + for ob in self.getGraphicCoords(): + dynamical+="""Coords.push(new Coord('%s', Img, %s));\n"""%(ob[1],ob[0]) + ret+=javaHandler%dynamical + return ret security.declarePublic('getCreditObject') def getCreditObject(self,name): @@ -420,7 +594,7 @@ class ECHO_collection(Folder, Persistent return getattr(self.partners,name) except: return "" - + security.declarePublic('ECHO_generateNavBar') def ECHO_generateNavBar(self): """Erzeuge Navigationsbar""" @@ -458,6 +632,8 @@ class ECHO_collection(Folder, Persistent """nothing""" return "Rerenderd all links to resources in: "+self.title + + security.declarePublic('ECHO_newViewerLink') def getCoords(self): @@ -470,7 +646,7 @@ class ECHO_collection(Folder, Persistent return [] - def __init__(self,id,title,label,description,content_type,responsible,credits,weight,sortfield,coords): + def __init__(self,id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle,secondaryLink,imageTag="",bgcolour=""): #print "CO",coords self.id = id @@ -479,14 +655,17 @@ class ECHO_collection(Folder, Persistent self.label = label self.title=title self.description=description - self.content_type=content_type + self.contentType=contentType self.responsible=responsible - + self.imageTag=imageTag self.weight=weight self.sortfield=sortfield coordsnew=[ string.split(x,",") for x in coords] self.coords=coordsnew - + self.secondaryLinkTitle=secondaryLinkTitle + self.secondaryLink=secondaryLink + self.bgcolour=bgcolor + manage_options = Folder.manage_options+( {'label':'Main Config','action':'ECHO_collection_config'}, @@ -495,9 +674,18 @@ class ECHO_collection(Folder, Persistent ) + def getOverview(self): + """overview graphics""" + + return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1] + + def ECHO_graphicEntry(self): """DO nothing""" - if 'overview' in self.aq_parent.__dict__.keys(): + overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview']) + + + if overview: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self) return pt() else: @@ -535,13 +723,32 @@ class ECHO_collection(Folder, Persistent security.declarePublic('changeECHO_collection') - def changeECHO_collection(self,title,label,description,content_type,responsible,weight,credits=None,sortfield="weight",coords=None,RESPONSE=None): + def getBgcolour(self): + """colour""" + if hasattr(self,'bgcolour') and not (self.bgcolour==""): + return self.bgcolour + else: + return "#dddddd" + + def changeECHO_collection(self,title,label,description,contentType,responsible,weight,secondaryLink,secondaryLinkTitle,credits=None,sortfield="weight",coords=None,RESPONSE=None,imageTag="",bgcolour=""): """Änderung der Properties""" - coordsnew=[ string.split(x,",") for x in coords] - - setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coordsnew) + self.secondaryLink=secondaryLink + self.secondaryLinkTitle=secondaryLinkTitle + self.imageTag=imageTag + self.bgcolour=bgcolour + + if coords: + coordsnew=[ string.split(x,",") for x in coords] + self.coords=coordsnew[0:] + else: + coordsnew=None + self.coords=None + + setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew) + + self.sortfield=sortfield if RESPONSE is not None: @@ -549,22 +756,34 @@ class ECHO_collection(Folder, Persistent security.declarePublic('index_html') - showOverview=DTMLFile('ECHO_content_overview',globals()) - + + def showOverview(self): + """overview""" + if 'ECHO_overview.html' in self.__dict__.keys(): + return getattr(self,'ECHO_overview.html')() + pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_overview.zpt').__of__(self) + return pt() + def index_html(self): """standard page""" if 'index.html' in self.__dict__.keys(): return getattr(self,'index.html')() + elif 'overview' in self.__dict__.keys(): return self.showOverview() - + elif hasattr(self,'collection_index_template'): + return self.collection_index_template() pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_standard.zpt').__of__(self) pt.content_type="text/html" return pt() + def content_html(self): + """template fuer content""" + return content_html(self,'collection') + def getCredits(self): """Ausgabe der credits""" if self.credits: @@ -572,6 +791,8 @@ class ECHO_collection(Folder, Persistent else: return [] + + def getGraphicCoords(self): """Give list of coordinates""" subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource'] @@ -583,13 +804,15 @@ class ECHO_collection(Folder, Persistent for coordtemp in object.coords: if len(coordtemp)>3: coord=coordtemp[0:4] - if hasattr(object,'title'): + if hasattr(object,'label') and not object.label=="": + ids.append([string.join(coord,", "),object.getId(),object.label,object]) + elif hasattr(object,'title'): if not object.title=="": - ids.append([string.join(coord,", "),object.getId(),object.title]) + ids.append([string.join(coord,", "),object.getId(),object.title,object]) else: - ids.append([string.join(coord,", "),object.getId(),object.getId()]) + ids.append([string.join(coord,", "),object.getId(),object.getId(),object]) else: - ids.append([string.join(coord,", "),object.getId(),object.getId()]) + ids.append([string.join(coord,", "),object.getId(),object.getId(),object]) except: """nothing""" @@ -638,11 +861,11 @@ def manage_addECHO_collectionForm(self): return pt() -def manage_addECHO_collection(self,id,title,label,description,content_type,responsible,weight,sortfield,coords="",credits=None,RESPONSE=None): +def manage_addECHO_collection(self,id,title,label,description,contentType,responsible,weight,sortfield,coords="",secondaryLinkTitle="",secondaryLink="",credits=None,RESPONSE=None,imageTag="",bgcolour=""): """add a echo collection""" - newObj=ECHO_collection(id,title,label,description,content_type,responsible,credits,weight,sortfield,coords) + newObj=ECHO_collection(id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle=secondaryLinkTitle,secondaryLink=secondaryLink,imageTag=imageTag,bgcolour="") self._setObject(id,newObj) @@ -653,6 +876,63 @@ class ECHO_root(Folder,Persistent,Implic """ECHO Root Folder""" meta_type="ECHO_root" + + def contentTypeSelector_HTML(self,selected=None): + """give type selector""" + if not selected: + retStr="