diff options
| author | Chris McDonough <chrism@plope.com> | 2013-07-24 17:22:48 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2013-07-24 17:22:48 -0400 |
| commit | 32333e4d84fe0e71ce097a5dca57025353956dbe (patch) | |
| tree | c9814e4b80b1b1c215156885559e2744eebf5c87 /docs | |
| parent | d79c0338e6b87ffa657f91065ce73c752f60a0b8 (diff) | |
| download | pyramid-32333e4d84fe0e71ce097a5dca57025353956dbe.tar.gz pyramid-32333e4d84fe0e71ce097a5dca57025353956dbe.tar.bz2 pyramid-32333e4d84fe0e71ce097a5dca57025353956dbe.zip | |
add not_ predicate feature
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/api/config.rst | 1 | ||||
| -rw-r--r-- | docs/narr/viewconfig.rst | 27 | ||||
| -rw-r--r-- | docs/whatsnew-1.5.rst | 26 |
3 files changed, 54 insertions, 0 deletions
diff --git a/docs/api/config.rst b/docs/api/config.rst index 39d504348..1f65be9f1 100644 --- a/docs/api/config.rst +++ b/docs/api/config.rst @@ -135,3 +135,4 @@ will only exist for the lifetime of the actual applications for which they are being used. +.. autoclass:: not_ diff --git a/docs/narr/viewconfig.rst b/docs/narr/viewconfig.rst index 241ce62b5..388371a0d 100644 --- a/docs/narr/viewconfig.rst +++ b/docs/narr/viewconfig.rst @@ -557,6 +557,33 @@ form of :term:`declarative configuration`, while :meth:`pyramid.config.Configurator.add_view` is a form of :term:`imperative configuration`. However, they both do the same thing. +Inverting Predicate Values +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can invert the meaning of any predicate value by wrapping it in a call to +:class:`pyramid.config.not_`. + +.. code-block:: python + :linenos: + + from pyramid.config import not_ + + config.add_view( + 'mypackage.views.my_view', + route_name='ok', + request_method=not_('POST') + ) + +The above example will ensure that the view is called if the request method +is *not* ``POST``, at least if no other view is more specific. + +This technique of wrapping a predicate value in ``not_`` can be used anywhere +predicate values are accepted: + +- :meth:`pyramid.config.Configurator.add_view` + +- :meth:`pyramid.view.view_config` + .. index:: single: view_config placement diff --git a/docs/whatsnew-1.5.rst b/docs/whatsnew-1.5.rst index 47b768eb9..ee2250017 100644 --- a/docs/whatsnew-1.5.rst +++ b/docs/whatsnew-1.5.rst @@ -12,6 +12,32 @@ Feature Additions The feature additions in Pyramid 1.5 follow. +- Add the ability to invert the result of any view, route, or subscriber + predicate value using the ``not_`` class. For example: + + .. code-block:: python + + from pyramid.config import not_ + + @view_config(route_name='myroute', request_method=not_('POST')) + def myview(request): ... + + The above example will ensure that the view is called if the request method + is not POST, at least if no other view is more specific. + + The :class:`pyramid.config.not_` class can be used against any value that is + a predicate value passed in any of these contexts: + + - :meth:`pyramid.config.Configurator.add_view` + + - :meth:`pyramid.config.Configurator.add_route` + + - :meth:`pyramid.config.Configurator.add_subscriber` + + - :meth:`pyramid.view.view_config` + + - :meth:`pyramid.events.subscriber` + - View lookup will now search for valid views based on the inheritance hierarchy of the context. It tries to find views based on the most specific context first, and upon predicate failure, will move up the inheritance chain |
