diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-06-19 09:24:49 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-06-19 09:24:49 +0000 |
| commit | b606d97195187bdb33e334a7a40df501b30e2f48 (patch) | |
| tree | 487a09938f408e02757846d62796b582b0902ce3 /repoze/bfg/zcml.py | |
| parent | 65697f35f2670fc93e695a7ddf083320f8a11f1a (diff) | |
| download | pyramid-b606d97195187bdb33e334a7a40df501b30e2f48.tar.gz pyramid-b606d97195187bdb33e334a7a40df501b30e2f48.tar.bz2 pyramid-b606d97195187bdb33e334a7a40df501b30e2f48.zip | |
- 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::
<notfound
view="helloworld.views.notfound_view"/>
- 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::
<forbidden
view="helloworld.views.forbidden_view"/>
Diffstat (limited to 'repoze/bfg/zcml.py')
| -rw-r--r-- | repoze/bfg/zcml.py | 30 |
1 files changed, 30 insertions, 0 deletions
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) |
