summaryrefslogtreecommitdiff
path: root/docs/whatsnew-1.3.rst
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-12-14 03:41:37 -0500
committerChris McDonough <chrism@plope.com>2011-12-14 03:41:37 -0500
commita1995a197b735b2d1bbf674a5a6a82c359b5131f (patch)
treee9b7f2f8ee0c892bbf6d35cd5d377a0193cd67ef /docs/whatsnew-1.3.rst
parentec507ade5541e1e3949fd6020062e78d113e0ed8 (diff)
parent4375cf2bad3535ce896e95fcf1e388e33f2e8ecf (diff)
downloadpyramid-a1995a197b735b2d1bbf674a5a6a82c359b5131f.tar.gz
pyramid-a1995a197b735b2d1bbf674a5a6a82c359b5131f.tar.bz2
pyramid-a1995a197b735b2d1bbf674a5a6a82c359b5131f.zip
Merge branch 'feature.viewdefaults'
Diffstat (limited to 'docs/whatsnew-1.3.rst')
-rw-r--r--docs/whatsnew-1.3.rst64
1 files changed, 64 insertions, 0 deletions
diff --git a/docs/whatsnew-1.3.rst b/docs/whatsnew-1.3.rst
index f51c7977a..608db74cd 100644
--- a/docs/whatsnew-1.3.rst
+++ b/docs/whatsnew-1.3.rst
@@ -126,6 +126,70 @@ New APIs were added to support introspection
:attr:`pyramid.config.Configurator.introspectable`,
:attr:`pyramid.registry.Registry.introspector`.
+``@view_defaults`` Decorator
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If you use a class as a view, you can use the new
+:class:`pyramid.view.view_defaults` class decorator on the class to provide
+defaults to the view configuration information used by every ``@view_config``
+decorator that decorates a method of that class.
+
+For instance, if you've got a class that has methods that represent "REST
+actions", all which are mapped to the same route, but different request
+methods, instead of this:
+
+.. code-block:: python
+ :linenos:
+
+ from pyramid.view import view_config
+ from pyramid.response import Response
+
+ class RESTView(object):
+ def __init__(self, request):
+ self.request = request
+
+ @view_config(route_name='rest', request_method='GET')
+ def get(self):
+ return Response('get')
+
+ @view_config(route_name='rest', request_method='POST')
+ def post(self):
+ return Response('post')
+
+ @view_config(route_name='rest', request_method='DELETE')
+ def delete(self):
+ return Response('delete')
+
+You can do this:
+
+.. code-block:: python
+ :linenos:
+
+ from pyramid.view import view_defaults
+ from pyramid.view import view_config
+ from pyramid.response import Response
+
+ @view_defaults(route_name='rest')
+ class RESTView(object):
+ def __init__(self, request):
+ self.request = request
+
+ @view_config(request_method='GET')
+ def get(self):
+ return Response('get')
+
+ @view_config(request_method='POST')
+ def post(self):
+ return Response('post')
+
+ @view_config(request_method='DELETE')
+ def delete(self):
+ return Response('delete')
+
+This also works for imperative view configurations that involve a class.
+
+See :ref:`view_defaults` for more information.
+
Minor Feature Additions
-----------------------