From ce8f9b5eadf324b4cc3154004bcf9f1f03e7d6c8 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 10 Oct 2009 02:30:50 +0000 Subject: - The ``notfound`` and ``forbidden`` ZCML directives now accept the following addtional attributes: ``attr``, ``renderer``, and ``wrapper``. These have the same meaning as they do in the context of a ZCML ``view`` directive. --- repoze/bfg/zcml.py | 51 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 16 deletions(-) (limited to 'repoze/bfg/zcml.py') diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py index 3faadb24b..adb1f1f31 100644 --- a/repoze/bfg/zcml.py +++ b/repoze/bfg/zcml.py @@ -279,29 +279,49 @@ def view( _view = view # for directives that take a view arg -class INotFoundViewDirective(Interface): +class ISystemViewDirective(Interface): view = GlobalObject( title=u"", - description=u"The notfound view callable", - required=True, + description=u"The view function", + required=False, ) -def notfound(_context, view): - view_utility(_context, view, INotFoundView) + attr = TextLine( + title=u'The callable attribute of the view object(default is __call__)', + description=u'', + required=False) -class IForbiddenViewDirective(Interface): - view = GlobalObject( - title=u"", - description=u"The forbidden view callable", - required=True, - ) + renderer = TextLine( + title=u'The renderer asssociated with the view', + description=u'', + required=False) -def forbidden(_context, view): - view_utility(_context, view, IForbiddenView) + wrapper = TextLine( + title = u'The *name* of the view that acts as a wrapper for this view.', + description = u'', + required=False) + +def notfound(_context, view=None, attr=None, renderer=None, wrapper=None): + view_utility(_context, view, attr, renderer, wrapper, INotFoundView) + +def forbidden(_context, view=None, attr=None, renderer=None, wrapper=None): + view_utility(_context, view, attr, renderer, wrapper, IForbiddenView) + +def view_utility(_context, view, attr, renderer, wrapper, iface): + if not view: + if renderer: + def view(context, request): + return {} + else: + raise ConfigurationError('"view" attribute was not specified and ' + 'no renderer specified') + + if renderer and '.' in renderer: + renderer = resource_spec(renderer, package_name(_context.resolve('.'))) -def view_utility(_context, view, iface): def register(): - derived_view = derive_view(view) + derived_view = derive_view(view, attr=attr, renderer_name=renderer, + wrapper_viewname=wrapper) sm = getSiteManager() sm.registerUtility(derived_view, iface, '', _context.info) @@ -310,7 +330,6 @@ def view_utility(_context, view, iface): callable = register, ) - class IResourceDirective(Interface): """ Directive for specifying that one package may override resources from -- cgit v1.2.3