work in progress: using browser.configurator for controlling portlets (?)
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1343 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
6ced111cf9
commit
eea19cc7ea
5 changed files with 55 additions and 13 deletions
|
@ -160,7 +160,7 @@ We can also access slots that are not predefined:
|
|||
The View Configurator
|
||||
---------------------
|
||||
|
||||
A view configurator is a multiadapter for a content object that provides
|
||||
A view configurator is typically a multiadapter for a content object that provides
|
||||
a set of properties to be used for setting up special presentation
|
||||
characteristics of a page. Typical examples for such characteristics are
|
||||
|
||||
|
@ -168,7 +168,7 @@ characteristics of a page. Typical examples for such characteristics are
|
|||
- the logo to show in the corner of the page
|
||||
|
||||
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 a form somewhere to edit those
|
||||
properties and store them in the content object's annotations.
|
||||
|
||||
>>> from zope.app.annotation.interfaces import IAttributeAnnotatable, IAnnotations
|
||||
|
@ -197,3 +197,12 @@ stored in the attribute annotations. So let's set a 'skinName' attribute:
|
|||
>>> controller.skinName.value
|
||||
'SuperSkin'
|
||||
|
||||
Another way of providing view configurations is using a view configurator
|
||||
as a utility, this can be used for setting view properties by certain
|
||||
packages.
|
||||
|
||||
>>> from cybertools.browser.configurator import GlobalViewConfigurator
|
||||
>>> component.provideUtility(GlobalViewConfigurator())
|
||||
|
||||
>>> gvc = component.getUtility(IViewConfigurator)
|
||||
|
||||
|
|
|
@ -40,6 +40,11 @@ class IViewConfigurator(Interface):
|
|||
|
||||
viewProperties = Attribute('A sequence of IViewProperty objects')
|
||||
|
||||
def getActiveViewProperties(self):
|
||||
""" Return a selection of this configurator's view properties
|
||||
that are to be considered active in the current context.
|
||||
"""
|
||||
|
||||
|
||||
class IViewProperty(Interface):
|
||||
|
||||
|
@ -78,6 +83,16 @@ class ViewConfigurator(object):
|
|||
propDefs = ann.get(ANNOTATION_KEY, {})
|
||||
return [self.setupViewProperty(prop, propDef)
|
||||
for prop, propDef in propDefs.items() if propDef]
|
||||
# idea: include properties from GlobalViewConfigurator;
|
||||
# there also may be other view configurators e.g. based on
|
||||
# the class (or some sort of type) of the context object.
|
||||
# Also the view properties may be filtered by permission
|
||||
# or other conditions.
|
||||
# Note: collecting configurators may be solved by getting
|
||||
# multiple configurators (+ utilities) in the controller!
|
||||
|
||||
def getActiveViewProperties(self):
|
||||
return self.viewProperties
|
||||
|
||||
def setupViewProperty(self, prop, propDef):
|
||||
vp = zapi.queryMultiAdapter((self.context, self.request),
|
||||
|
@ -89,6 +104,19 @@ class ViewConfigurator(object):
|
|||
return vp
|
||||
|
||||
|
||||
class GlobalViewConfigurator(object):
|
||||
""" A global utility that allows the registration of view properties.
|
||||
"""
|
||||
|
||||
implements(IViewConfigurator)
|
||||
|
||||
def __init__(self):
|
||||
self.viewProperties = []
|
||||
|
||||
def getActiveViewProperties(self):
|
||||
return self.viewProperties
|
||||
|
||||
|
||||
class ViewProperty(object):
|
||||
|
||||
implements(IViewProperty)
|
||||
|
@ -117,5 +145,6 @@ class MacroViewProperty(object):
|
|||
def setParams(self, params):
|
||||
params = dict(params)
|
||||
self.name = params.pop('name', '')
|
||||
self.identifier = params.pop('identifier', name)
|
||||
self.template = params.pop('template', None)
|
||||
self.params = params
|
||||
|
|
|
@ -22,7 +22,7 @@ Controller for views, templates, macros.
|
|||
$Id$
|
||||
"""
|
||||
|
||||
from zope.app import zapi
|
||||
from zope import component
|
||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
|
||||
|
@ -52,12 +52,19 @@ class Controller(object):
|
|||
return self.request.URL[0] + skinSetter + '/@@/'
|
||||
|
||||
def configure(self):
|
||||
configurator = zapi.queryMultiAdapter((self.context, self.request),
|
||||
#configurator = component.queryMultiAdapter((self.context, self.request),
|
||||
# IViewConfigurator)
|
||||
# idea: collect multiple configurators:
|
||||
configurators = component.getAdapters((self.context, self.request),
|
||||
IViewConfigurator)
|
||||
if configurator is not None:
|
||||
for item in configurator.viewProperties:
|
||||
for conf in configurators:
|
||||
configurator = conf[1]
|
||||
#if configurator is not None:
|
||||
#for item in configurator.viewProperties:
|
||||
for item in configurator.getActiveViewProperties():
|
||||
if IMacroViewProperty.providedBy(item):
|
||||
self.macros.register(item.slot, item.template, item.name,
|
||||
self.macros.register(item.slot, item.idenitifier,
|
||||
item.template, item.name,
|
||||
**item.params)
|
||||
else:
|
||||
setattr(self, item.slot, item)
|
||||
|
|
|
@ -25,9 +25,9 @@ body {
|
|||
|
||||
#global,#footer {width:100%}
|
||||
#menu,#content,#sub-section {float:left}
|
||||
#menu {width:18%}
|
||||
#content {width:67%}
|
||||
#sub-section {width:15%}
|
||||
#menu {width:20%}
|
||||
#content {width:63%}
|
||||
#sub-section {width:17%}
|
||||
#footer {clear:left}
|
||||
|
||||
/* more general stuff */
|
||||
|
|
|
@ -101,7 +101,6 @@
|
|||
tal:attributes="href
|
||||
string:${url}/@@SelectedManagementView.html"
|
||||
tal:content="item/id"
|
||||
i18n:translate=""
|
||||
>foo</a
|
||||
><a href="#"
|
||||
tal:attributes="href
|
||||
|
@ -120,12 +119,10 @@
|
|||
string:${request/URL}?retitle_id=${id_quoted}"
|
||||
tal:condition="item/retitleable"
|
||||
tal:content="item/title|default"
|
||||
i18n:translate=""
|
||||
> </a>
|
||||
<span
|
||||
tal:condition="item/plaintitle"
|
||||
tal:content="item/title|default"
|
||||
i18n:translate=""
|
||||
> </span>
|
||||
</td>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue