diff --git a/browser/README.txt b/browser/README.txt index 062c271..9dbceda 100644 --- a/browser/README.txt +++ b/browser/README.txt @@ -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) + diff --git a/browser/configurator.py b/browser/configurator.py index a4e007b..9058fae 100644 --- a/browser/configurator.py +++ b/browser/configurator.py @@ -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 diff --git a/browser/controller.py b/browser/controller.py index 9f0fcfa..ad3d378 100644 --- a/browser/controller.py +++ b/browser/controller.py @@ -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) diff --git a/browser/liquid/base.css b/browser/liquid/base.css index 96a8d62..3fb21f5 100644 --- a/browser/liquid/base.css +++ b/browser/liquid/base.css @@ -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 */ diff --git a/container/contents.pt b/container/contents.pt index 70768f1..adfdb64 100644 --- a/container/contents.pt +++ b/container/contents.pt @@ -101,7 +101,6 @@ tal:attributes="href string:${url}/@@SelectedManagementView.html" tal:content="item/id" - i18n:translate="" >foo