diff options
| author | Chris McDonough <chrism@plope.com> | 2011-12-14 03:41:03 -0500 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-12-14 03:41:03 -0500 |
| commit | 4375cf2bad3535ce896e95fcf1e388e33f2e8ecf (patch) | |
| tree | a89f3a497e446a65f5f7607b692f2732dadb1f4c /docs/whatsnew-1.3.rst | |
| parent | 914abe3b0b5d4068d33050f4695c3a3f4a7ecf78 (diff) | |
| download | pyramid-4375cf2bad3535ce896e95fcf1e388e33f2e8ecf.tar.gz pyramid-4375cf2bad3535ce896e95fcf1e388e33f2e8ecf.tar.bz2 pyramid-4375cf2bad3535ce896e95fcf1e388e33f2e8ecf.zip | |
Flesh out new view_defaults feature and add docs, change notes, and add to whatsnew.
Diffstat (limited to 'docs/whatsnew-1.3.rst')
| -rw-r--r-- | docs/whatsnew-1.3.rst | 64 |
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 ----------------------- |
