summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-10-18 05:50:54 +0000
committerChris McDonough <chrism@agendaless.com>2009-10-18 05:50:54 +0000
commit1dc3907e59995852d5ee0251c1c92a360f03ed35 (patch)
tree38da7879503f2b55b995cee89a2aebe6c7d6f076 /docs
parent2cce431f02a37c119eacfc3dfa94af9fe3305de1 (diff)
downloadpyramid-1dc3907e59995852d5ee0251c1c92a360f03ed35.tar.gz
pyramid-1dc3907e59995852d5ee0251c1c92a360f03ed35.tar.bz2
pyramid-1dc3907e59995852d5ee0251c1c92a360f03ed35.zip
- The ``@bfg_view`` decorator can now be used against a class method::
from webob import Response from repoze.bfg.view import bfg_view class MyView(object): def __init__(self, context, request): self.context = context self.request = request @bfg_view(name='hello') def amethod(self): return Response('hello from %s!' % self.context) When the bfg_view decorator is used against a class method, a view is registered for the *class* (it's a "class view" where the "attr" happens to be the method they're attached to), so the view class must have a suitable constructor.
Diffstat (limited to 'docs')
-rw-r--r--docs/narr/views.rst44
1 files changed, 44 insertions, 0 deletions
diff --git a/docs/narr/views.rst b/docs/narr/views.rst
index b52abf57f..effc17f06 100644
--- a/docs/narr/views.rst
+++ b/docs/narr/views.rst
@@ -729,6 +729,50 @@ This registers the same view under two different names.
stacked without the effect of the "upper" decorator cancelling the
effect of the the decorator beneath it.
+The bfg_view decorator can also be used against class methods:
+
+.. code-block:: python
+ :linenos:
+
+ from webob import Response
+ from repoze.bfg.view import bfg_view
+
+ class MyView(object):
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+
+ @bfg_view(name='hello')
+ def amethod(self):
+ return Response('hello from %s!' % self.context)
+
+When the bfg_view decorator is used against a class method, a view is
+registered for the *class*, so the class constructor must accept
+either ``request`` or ``context, request``. The method which is
+decorated must return a response (or rely on a :term:`renderer` to
+generate one). Using the decorator against a particular method of a
+class is equivalent to using the ``attr`` parameter in a decorator
+attached to the class itself. For example, the above registration
+implied by the decorator being used against the ``amethod`` method
+could be spelled equivalently as the below:
+
+.. code-block:: python
+
+ from webob import Response
+ from repoze.bfg.view import bfg_view
+
+ @bfg_view(attr='amethod', name='hello')
+ class MyView(object):
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+
+ def amethod(self):
+ return Response('hello from %s!' % self.context)
+
+.. warning:: The ability to use the ``bfg_view`` decorator as a method
+ decorator is new in :mod:`repoze.bfg` version 1.1.
+
.. _view_lookup_ordering:
View Lookup Ordering