summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-09-16 20:45:20 +0000
committerChris McDonough <chrism@agendaless.com>2009-09-16 20:45:20 +0000
commit550e16bb5936f5e22954992e50ac57f7f5cff4e0 (patch)
tree1a0c87130ef61985c3cb4588bc58640ff9a562b8
parent3c5d6701421281508211c762febb86acf2a21b2b (diff)
downloadpyramid-550e16bb5936f5e22954992e50ac57f7f5cff4e0.tar.gz
pyramid-550e16bb5936f5e22954992e50ac57f7f5cff4e0.tar.bz2
pyramid-550e16bb5936f5e22954992e50ac57f7f5cff4e0.zip
- Give the ``route`` ZCML directive the ``view_attr`` and
``view_renderer`` parameters (bring up to speed with 1.1a3 features). These can also be spelled as ``attr`` and ``renderer``.
-rw-r--r--CHANGES.txt7
-rw-r--r--docs/narr/urldispatch.rst48
-rw-r--r--repoze/bfg/zcml.py13
3 files changed, 66 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 8b13df881..8e48e544f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,10 @@
+Next release
+============
+
+- Give the ``route`` ZCML directive the ``view_attr`` and
+ ``view_renderer`` parameters (bring up to speed with 1.1a3
+ features). These can also be spelled as ``attr`` and ``renderer``.
+
1.1a3 (2009-09-16)
==================
diff --git a/docs/narr/urldispatch.rst b/docs/narr/urldispatch.rst
index dfae6e1b0..f18e1d23c 100644
--- a/docs/narr/urldispatch.rst
+++ b/docs/narr/urldispatch.rst
@@ -136,6 +136,8 @@ view_request_method
This attribute can also be spelled as ``request_method``.
+ .. note:: This feature is new as of :mod:`repoze.bfg` 1.1.
+
view_request_param
This value can be any string. A view declaration with this
@@ -153,6 +155,8 @@ view_request_param
This attribute can also be spelled as ``request_param``.
+ .. note:: This feature is new as of :mod:`repoze.bfg` 1.1.
+
view_containment
This value should be a Python dotted-path string representing the
@@ -167,6 +171,50 @@ view_containment
This attribute can also be spelled as ``containment``.
+ .. note:: This feature is new as of :mod:`repoze.bfg` 1.1.
+
+view_attr
+
+ The view machinery defaults to using the ``__call__`` method of the
+ view callable (or the function itself, if the view callable is a
+ funcion) to obtain a response dictionary. The ``attr`` value allows
+ you to vary the method attribute used to obtain the response. For
+ example, if your view was a class, and the class has a method named
+ ``index`` and you wanted to use this method instead of the class'
+ ``__call__`` method to return the response, you'd say
+ ``attr="index"`` in the view configuration for the view. This is
+ most useful when the view definition is a class.
+
+ If the ``view`` attribute is not provided, this attribute has no
+ effect.
+
+ This attribute can also be spelled as ``attr``.
+
+ .. note:: This feature is new as of :mod:`repoze.bfg` 1.1.
+
+view_renderer
+
+ This is either a single string term (e.g. ``json``) or a string
+ implying a path or :term:`resource specification`
+ (e.g. ``templates/views.pt``). If the renderer value is a single
+ term (does not contain a dot ``.``), the specified term will be used
+ to look up a renderer implementation, and that renderer
+ inplementation will be used to construct a response from the view
+ return value. If the renderer term contains a dot (``.``), the
+ specified term will be treated as a path, and the filename extension
+ of the last element in the path will be used to look up the renderer
+ implementation, which will be passed the full path. The renderer
+ implementation will be used to construct a response from the view
+ return value. See :ref:`views_which_use_a_renderer` for more
+ information.
+
+ If the ``view`` attribute is not provided, this attribute has no
+ effect.
+
+ This attribute can also be spelled as ``renderer``.
+
+ .. note:: This feature is new as of :mod:`repoze.bfg` 1.1.
+
The Matchdict
-------------
diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py
index a9a6a95a0..fd8e086a4 100644
--- a/repoze/bfg/zcml.py
+++ b/repoze/bfg/zcml.py
@@ -505,6 +505,8 @@ class IRouteDirective(Interface):
view_containment = GlobalObject(
title = u'Dotted name of a containment class or interface',
required=False)
+ view_attr = TextLine(title=u'view_attr', required=False)
+ view_renderer = TextLine(title=u'view_renderer', required=False)
# alias for "view_for"
for_ = GlobalObject(title=u'for', required=False)
# alias for "view_permission"
@@ -519,13 +521,18 @@ class IRouteDirective(Interface):
containment = GlobalObject(
title = u'Dotted name of a containment class or interface',
required=False)
+ # alias for "view_attr"
+ attr = TextLine(title=u'attr', required=False)
+ # alias for "view_renderer"
+ renderer = TextLine(title=u'renderer', required=False)
def route(_context, name, path, view=None, view_for=None,
permission=None, factory=None, request_type=None, for_=None,
view_permission=None, view_request_type=None,
request_method=None, view_request_method=None,
request_param=None, view_request_param=None, containment=None,
- view_containment=None):
+ view_containment=None, attr=None, view_attr=None, renderer=None,
+ view_renderer=None):
""" Handle ``route`` ZCML directives
"""
# the strange ordering of the request kw args above is for b/w
@@ -536,6 +543,8 @@ def route(_context, name, path, view=None, view_for=None,
request_method = view_request_method or request_method
request_param = view_request_param or request_param
containment = view_containment or containment
+ attr = view_attr or attr
+ renderer = view_renderer or renderer
sm = getSiteManager()
@@ -555,7 +564,7 @@ def route(_context, name, path, view=None, view_for=None,
_view(_context, permission=permission, for_=for_, view=view, name='',
request_type=request_type, route_name=name,
request_method=request_method, request_param=request_param,
- containment=containment)
+ containment=containment, attr=attr, renderer=renderer)
_context.action(
discriminator = ('route', name),