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 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

View file

@ -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