From b606d97195187bdb33e334a7a40df501b30e2f48 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 19 Jun 2009 09:24:49 +0000 Subject: - A new ZCML directive was added named ``notfound``. This ZCML directive can be used to name a view that should be invoked when the request can't otherwise be resolved to a view callable. For example:: - A new ZCML directive was added named ``forbidden``. This ZCML directive can be used to name a view that should be invoked when a view callable for a request is found, but cannot be invoked due to an authorization failure. For example:: --- repoze/bfg/zcml.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'repoze/bfg/zcml.py') diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py index e53a359da..1b66839d6 100644 --- a/repoze/bfg/zcml.py +++ b/repoze/bfg/zcml.py @@ -20,6 +20,8 @@ from zope.schema import TextLine from repoze.bfg.interfaces import IRoutesMapper from repoze.bfg.interfaces import IViewPermission +from repoze.bfg.interfaces import INotFoundView +from repoze.bfg.interfaces import IForbiddenView from repoze.bfg.interfaces import IView from repoze.bfg.request import DEFAULT_REQUEST_FACTORIES @@ -84,6 +86,20 @@ def view( derived_view, (for_, request_type), IView, name, _context.info), ) +def view_utility(_context, view, iface): + derived_view = derive_view(view) + _context.action( + discriminator = ('notfound_view',), + callable = handler, + args = ('registerUtility', derived_view, iface, '', _context.info), + ) + +def notfound(_context, view): + view_utility(_context, view, INotFoundView) + +def forbidden(_context, view): + view_utility(_context, view, IForbiddenView) + def derive_view(view): derived_view = view if inspect.isclass(view): @@ -316,6 +332,20 @@ class IViewDirective(Interface): title = u'The route that must match for this view to be used', required = False) +class INotFoundViewDirective(Interface): + view = GlobalObject( + title=u"", + description=u"The notfound view callable", + required=True, + ) + +class IForbiddenViewDirective(Interface): + view = GlobalObject( + title=u"", + description=u"The forbidden view callable", + required=True, + ) + class IRouteRequirementDirective(Interface): """ The interface for the ``requirement`` route subdirective """ attr = TextLine(title=u'attr', required=True) -- cgit v1.2.3