--- ECHO_content/ECHO_collection.py 2004/04/04 17:48:22 1.28 +++ ECHO_content/ECHO_collection.py 2004/04/06 15:21:33 1.33 @@ -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,8 +23,10 @@ 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 @@ -35,7 +38,21 @@ from ECHO_graphicalOverview import javaH #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: @@ -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 @@ -239,9 +337,10 @@ class ECHO_resource(Folder): def changeECHO_resource(self,metalink,link,title,label,description,contentType,responsible,weight,viewClassification="",coords=None,credits=None,RESPONSE=None): """Änderung der Properties""" - - coordsnew=[ string.split(x,",") for x in coords] - + try: + coordsnew=[ string.split(x,",") for x in coords] + except: + coordsnew=[] setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew) @@ -344,7 +443,10 @@ class ECHO_externalLink(Folder): security=ClassSecurityInfo() meta_type='ECHO_externalLink' - + 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 @@ -441,7 +543,21 @@ class ECHO_collection(Folder, Persistent 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""" @@ -530,7 +646,7 @@ class ECHO_collection(Folder, Persistent return [] - def __init__(self,id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,imageTag=""): + def __init__(self,id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle,secondaryLink,imageTag=""): #print "CO",coords self.id = id @@ -546,7 +662,9 @@ class ECHO_collection(Folder, Persistent self.sortfield=sortfield coordsnew=[ string.split(x,",") for x in coords] self.coords=coordsnew - + self.secondaryLinkTitle=secondaryLinkTitle + self.secondaryLink=secondaryLink + manage_options = Folder.manage_options+( {'label':'Main Config','action':'ECHO_collection_config'}, @@ -604,15 +722,23 @@ class ECHO_collection(Folder, Persistent security.declarePublic('changeECHO_collection') - def changeECHO_collection(self,title,label,description,contentType,responsible,weight,credits=None,sortfield="weight",coords=None,RESPONSE=None,imageTag=""): + def changeECHO_collection(self,title,label,description,contentType,responsible,weight,secondaryLink,secondaryLinkTitle,credits=None,sortfield="weight",coords=None,RESPONSE=None,imageTag=""): """Änderung der Properties""" + self.secondaryLink=secondaryLink + self.secondaryLinkTitle=secondaryLinkTitle self.imageTag=imageTag - coordsnew=[ string.split(x,",") for x in coords] - + 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.coords=coordsnew[0:] self.sortfield=sortfield if RESPONSE is not None: @@ -634,14 +760,20 @@ class ECHO_collection(Folder, Persistent 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.contentType="text/html" + 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: @@ -719,11 +851,11 @@ def manage_addECHO_collectionForm(self): return pt() -def manage_addECHO_collection(self,id,title,label,description,contentType,responsible,weight,sortfield,coords="",credits=None,RESPONSE=None,imageTag=""): +def manage_addECHO_collection(self,id,title,label,description,contentType,responsible,weight,sortfield,coords="",secondaryLinkTitle="",secondaryLink="",credits=None,RESPONSE=None,imageTag=""): """add a echo collection""" - newObj=ECHO_collection(id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,imageTag) + newObj=ECHO_collection(id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle=secondaryLinkTitle,secondaryLink=secondaryLink,imageTag=imageTag) self._setObject(id,newObj) @@ -759,11 +891,11 @@ class ECHO_root(Folder,Persistent,Implic if not obj: obj = self - entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection,ECHO_externalLink,ECHO_pageTemplate']) + entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection','ECHO_externalLink','ECHO_pageTemplate']) for entry in entries: - - entry[1].contentType == entry[1].content_type + setattr(entry[1],'contentType',entry[1].content_type) + #entry[1].contentType == entry[1].content_type if entry[1].meta_type == 'ECHO_collection': entry[1].patchContentType(entry[1]) @@ -923,15 +1055,15 @@ class ECHO_partner(Image,Persistent): meta_type="ECHO_partner" - def __init__(self, id, title,url, file, contentType='', precondition=''): + def __init__(self, id, title,url, file, content_type='', precondition=''): self.__name__=id self.title=title self.url=url self.precondition=precondition data, size = self._read_data(file) - contentType=self._get_contentType(file, data, id, contentType) - self.update_data(data, contentType, size) + content_type=self._get_content_type(file, data, id, content_type) + self.update_data(data, content_type, size) manage_options = Image.manage_options+( {'label':'Partner Information','action':'ECHO_partner_config'}, @@ -958,7 +1090,7 @@ manage_addECHO_partnerForm=DTMLFile('dtm -def manage_addECHO_partner(self, id, file,url, title='', precondition='', contentType='', +def manage_addECHO_partner(self, id, file,url, title='', precondition='', content_type='', REQUEST=None): """ Add a new ECHO_partner object. @@ -969,7 +1101,7 @@ def manage_addECHO_partner(self, id, fil id=str(id) title=str(title) - contentType=str(contentType) + content_type=str(content_type) precondition=str(precondition) id, title = OFS.Image.cookId(id, title, file) @@ -977,14 +1109,14 @@ def manage_addECHO_partner(self, id, fil self=self.this() # First, we create the image without data: - self._setObject(id, ECHO_partner(id,title,url,'',contentType, precondition)) + self._setObject(id, ECHO_partner(id,title,url,'',content_type, precondition)) # Now we "upload" the data. By doing this in two steps, we # can use a database trick to make the upload more efficient. if file: self._getOb(id).manage_upload(file) - if contentType: - self._getOb(id).contentType=contentType + if content_type: + self._getOb(id).content_type=content_type if REQUEST is not None: try: url=self.DestinationURL()