configurator stuff now working

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1201 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2006-05-10 10:17:42 +00:00
parent cbc15a5a2d
commit fa7db29662
2 changed files with 21 additions and 17 deletions

View file

@ -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; that means that there could be form somewhere to edit those
properties and store them in the content object's annotations. 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 The configurator is called automatically from the controller if there is
an appropriate adapter: 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 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: 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) >>> interface.classImplements(SomeObject, IAttributeAnnotatable)
>>> component.provideAdapter(AttributeAnnotations, (SomeObject,), IAnnotations)
>>> ann = IAnnotations(obj) >>> ann = IAnnotations(obj)
>>> setting = {'skinName': {'value': 'SuperSkin'}} >>> setting = {'skinName': {'value': 'SuperSkin'}}
>>> from cybertools.browser.configurator import ANNOTATION_KEY >>> from cybertools.browser.configurator import ANNOTATION_KEY

View file

@ -23,7 +23,7 @@ $Id$
""" """
from zope.app import zapi 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.app.annotation.attribute import AttributeAnnotations
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
from zope.interface import Interface, Attribute, implements from zope.interface import Interface, Attribute, implements
@ -61,7 +61,7 @@ class IMacroViewProperty(IViewProperty):
ANNOTATION_KEY = 'cybertools.browser.configurator.ViewConfigurator' ANNOTATION_KEY = 'cybertools.browser.configurator.ViewConfigurator'
class ViewConfigurator(AttributeAnnotations): class ViewConfigurator(object):
""" Simple/basic default adapter using attribute annotations as storage """ Simple/basic default adapter using attribute annotations as storage
for view properties. for view properties.
""" """
@ -69,23 +69,24 @@ class ViewConfigurator(AttributeAnnotations):
implements(IViewConfigurator) implements(IViewConfigurator)
def __init__(self, context, request): def __init__(self, context, request):
AttributeAnnotations.__init__(self, context)
self.context = context self.context = context
self.request = request self.request = request
@property @property
def viewProperties(self): def viewProperties(self):
propDefs = self.get(ANNOTATION_KEY, []) ann = IAnnotations(self.context)
result = [] propDefs = ann.get(ANNOTATION_KEY, {})
for prop in propDefs: return [self.setupViewProperty(prop, propDef)
vp = zapi.queryMultiAdapter((self.context, self.request), for prop, propDef in propDefs.items() if propDef]
IViewProperty, name=prop)
if vp is None: def setupViewProperty(self, prop, propDef):
vp = ViewProperty(self.context, self.request) vp = zapi.queryMultiAdapter((self.context, self.request),
vp.slot = prop IViewProperty, name=prop)
vp.setParams(propDefs[prop]) if vp is None:
result.append(vp) vp = ViewProperty(self.context, self.request)
return result vp.slot = prop
vp.setParams(propDef)
return vp
class ViewProperty(object): class ViewProperty(object):
@ -101,6 +102,7 @@ class ViewProperty(object):
self.params = {} self.params = {}
def setParams(self, params): def setParams(self, params):
params = dict(params)
self.name = params.pop('name', '') self.name = params.pop('name', '')
self.value = params.pop('value', None) self.value = params.pop('value', None)
self.params = params self.params = params
@ -113,6 +115,7 @@ class MacroViewProperty(object):
template = None template = None
def setParams(self, params): def setParams(self, params):
params = dict(params)
self.name = params.pop('name', '') self.name = params.pop('name', '')
self.template = params.pop('template', None) self.template = params.pop('template', None)
self.params = params self.params = params