From fa7db296623b2b9707aa903a9b01163cb548d096 Mon Sep 17 00:00:00 2001 From: helmutm Date: Wed, 10 May 2006 10:17:42 +0000 Subject: [PATCH] configurator stuff now working git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1201 fd906abe-77d9-0310-91a1-e0d9ade77398 --- browser/README.txt | 7 ++++--- browser/configurator.py | 31 +++++++++++++++++-------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/browser/README.txt b/browser/README.txt index 1ad344e..af72845 100644 --- a/browser/README.txt +++ b/browser/README.txt @@ -110,6 +110,10 @@ The default configurator uses attribute annotations for retrieving view properties; that means that there could be form somewhere to edit those properties and store them in the content object's annotations. + >>> from zope.app.annotation.interfaces import IAttributeAnnotatable, IAnnotations + >>> from zope.app.annotation.attribute import AttributeAnnotations + >>> component.provideAdapter(AttributeAnnotations, (SomeObject,), IAnnotations) + The configurator is called automatically from the controller if there is an appropriate adapter: @@ -122,10 +126,7 @@ an appropriate adapter: But this does not have any effect as long as there aren't any properties stored in the attribute annotations. So let's set a 'skinName' attribute: - >>> from zope.app.annotation.interfaces import IAttributeAnnotatable, IAnnotations - >>> from zope.app.annotation.attribute import AttributeAnnotations >>> interface.classImplements(SomeObject, IAttributeAnnotatable) - >>> component.provideAdapter(AttributeAnnotations, (SomeObject,), IAnnotations) >>> ann = IAnnotations(obj) >>> setting = {'skinName': {'value': 'SuperSkin'}} >>> from cybertools.browser.configurator import ANNOTATION_KEY diff --git a/browser/configurator.py b/browser/configurator.py index 6bbae70..a4e007b 100644 --- a/browser/configurator.py +++ b/browser/configurator.py @@ -23,7 +23,7 @@ $Id$ """ from zope.app import zapi -from zope.app.annotation.interfaces import IAttributeAnnotatable +from zope.app.annotation.interfaces import IAttributeAnnotatable, IAnnotations from zope.app.annotation.attribute import AttributeAnnotations from zope.cachedescriptors.property import Lazy from zope.interface import Interface, Attribute, implements @@ -61,7 +61,7 @@ class IMacroViewProperty(IViewProperty): ANNOTATION_KEY = 'cybertools.browser.configurator.ViewConfigurator' -class ViewConfigurator(AttributeAnnotations): +class ViewConfigurator(object): """ Simple/basic default adapter using attribute annotations as storage for view properties. """ @@ -69,23 +69,24 @@ class ViewConfigurator(AttributeAnnotations): implements(IViewConfigurator) def __init__(self, context, request): - AttributeAnnotations.__init__(self, context) self.context = context self.request = request @property def viewProperties(self): - propDefs = self.get(ANNOTATION_KEY, []) - result = [] - for prop in propDefs: - vp = zapi.queryMultiAdapter((self.context, self.request), - IViewProperty, name=prop) - if vp is None: - vp = ViewProperty(self.context, self.request) - vp.slot = prop - vp.setParams(propDefs[prop]) - result.append(vp) - return result + ann = IAnnotations(self.context) + propDefs = ann.get(ANNOTATION_KEY, {}) + return [self.setupViewProperty(prop, propDef) + for prop, propDef in propDefs.items() if propDef] + + def setupViewProperty(self, prop, propDef): + vp = zapi.queryMultiAdapter((self.context, self.request), + IViewProperty, name=prop) + if vp is None: + vp = ViewProperty(self.context, self.request) + vp.slot = prop + vp.setParams(propDef) + return vp class ViewProperty(object): @@ -101,6 +102,7 @@ class ViewProperty(object): self.params = {} def setParams(self, params): + params = dict(params) self.name = params.pop('name', '') self.value = params.pop('value', None) self.params = params @@ -113,6 +115,7 @@ class MacroViewProperty(object): template = None def setParams(self, params): + params = dict(params) self.name = params.pop('name', '') self.template = params.pop('template', None) self.params = params