summaryrefslogtreecommitdiff
path: root/repoze/bfg/view.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-10-14 11:14:44 +0000
committerChris McDonough <chrism@agendaless.com>2009-10-14 11:14:44 +0000
commit083422c0c66c1aa53f9d96c6fd185e238bc51708 (patch)
treedfed56fdd9d595e1d081370791eeb3a30b307904 /repoze/bfg/view.py
parent069db05dec4d8352d37cf05cf3c6ffd04b69fc91 (diff)
downloadpyramid-083422c0c66c1aa53f9d96c6fd185e238bc51708.tar.gz
pyramid-083422c0c66c1aa53f9d96c6fd185e238bc51708.tar.bz2
pyramid-083422c0c66c1aa53f9d96c6fd185e238bc51708.zip
- Add ``xhr``, ``accept``, and ``header`` view configuration
predicates to ZCML view declaration, ZCML route declaration, and ``bfg_view`` decorator. See the ``Views`` narrative documentation chapter for more information about these predicates.
Diffstat (limited to 'repoze/bfg/view.py')
-rw-r--r--repoze/bfg/view.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/repoze/bfg/view.py b/repoze/bfg/view.py
index dba0f99b9..d6c47ec0f 100644
--- a/repoze/bfg/view.py
+++ b/repoze/bfg/view.py
@@ -240,7 +240,8 @@ class bfg_view(object):
The following arguments are supported: ``for_``, ``permission``,
``name``, ``request_type``, ``route_name``, ``request_method``,
- ``request_param``, and ``containment``.
+ ``request_param``, ``containment``, ``xhr``, ``accept``, and
+ ``header``.
If ``for_`` is not supplied, the interface
``zope.interface.Interface`` (matching any context) is used.
@@ -295,6 +296,27 @@ class bfg_view(object):
denoting that the view 'matches' the current request only if any graph
lineage node possesses this class or interface.
+ If ``xhr`` is specified, it must be a boolean value. If the value
+ is ``True``, the view will only be invoked if the request's
+ ``X-Requested-With`` header has the value ``XMLHttpRequest``.
+
+ If ``accept`` is specified, it must be a mimetype value. If
+ ``accept`` is specified, the view will only be invoked if the
+ ``Accept`` HTTP header matches the value requested. See the
+ description of ``accept`` in :ref:`the_view_zcml_directive` for
+ information about the allowable composition and matching behavior
+ of this value.
+
+ If ``header`` is specified, it must be a header name or a
+ ``headername:headervalue`` pair. If ``header`` is specified, and
+ possesses a value the view will only be invoked if an HTTP header
+ matches the value requested. If ``header`` is specified without a
+ value (a bare header name only), the view will only be invoked if
+ the HTTP header exists with any value in the request. See the
+ description of ``header`` in :ref:`the_view_zcml_directive` for
+ information about the allowable composition and matching behavior
+ of this value.
+
Any individual or all parameters can be omitted. The simplest
bfg_view declaration then becomes::
@@ -354,7 +376,8 @@ class bfg_view(object):
"""
def __init__(self, name='', request_type=None, for_=None, permission=None,
route_name=None, request_method=None, request_param=None,
- containment=None, attr=None, renderer=None, wrapper=None):
+ containment=None, attr=None, renderer=None, wrapper=None,
+ xhr=False, accept=None, header=None):
self.name = name
self.request_type = request_type
self.for_ = for_
@@ -366,6 +389,9 @@ class bfg_view(object):
self.attr = attr
self.renderer = renderer
self.wrapper_viewname = wrapper
+ self.xhr = xhr
+ self.accept = accept
+ self.header = header
def __call__(self, wrapped):
wrapped.__bfg_view_settings__ = self.__dict__.copy()