diff options
| author | Chris McDonough <chrism@plope.com> | 2011-01-07 22:53:05 -0500 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-01-07 22:53:05 -0500 |
| commit | 0b0e74764fa0f2a3d6daa8f8ce70112419ea6981 (patch) | |
| tree | 693b0bc712bf23916afdc571879ec24de82a13f7 | |
| parent | 512d53fffab8f0d258f528d0c24c313b65bde652 (diff) | |
| download | pyramid-0b0e74764fa0f2a3d6daa8f8ce70112419ea6981.tar.gz pyramid-0b0e74764fa0f2a3d6daa8f8ce70112419ea6981.tar.bz2 pyramid-0b0e74764fa0f2a3d6daa8f8ce70112419ea6981.zip | |
- Allow ``decorator`` and ``mapper`` arguments to view ZCML directive.
- Document ``decorator`` and ``mapper`` arguments in various places.
| -rw-r--r-- | TODO.txt | 9 | ||||
| -rw-r--r-- | docs/narr/views.rst | 16 | ||||
| -rw-r--r-- | docs/zcml/view.rst | 14 | ||||
| -rw-r--r-- | pyramid/config.py | 30 | ||||
| -rw-r--r-- | pyramid/view.py | 3 | ||||
| -rw-r--r-- | pyramid/zcml.py | 13 |
6 files changed, 63 insertions, 22 deletions
@@ -11,15 +11,10 @@ Must-Have (before 1.0) - Re-make testing.setUp() and testing.tearDown() the canonical APIs for test configuration. -- Document ``decorator=`` and ``view_mapper`` parameters to add_view and - ``@view_config``. - -- Allow ``decorator=`` and ``view_mapper=`` to be passed via ZCML. - - Document ``Configurator.set_view_mapper``. -- Document ``__view_mapper__`` attribute for view callable view mapper - preference. +- Document ``__view_mapper__`` attribute and ``mapper`` argument to view + configuration for view callable view mapper preference. - ZCML directive for view mapper (or just use "utility", but it's not eager). diff --git a/docs/narr/views.rst b/docs/narr/views.rst index 81f3e644f..813c54bee 100644 --- a/docs/narr/views.rst +++ b/docs/narr/views.rst @@ -658,6 +658,22 @@ Non-Predicate Arguments If ``wrapper`` is not supplied, no wrapper view is used. +``decorator`` + A :term:`dotted Python name` to function (or the function itself) which + will be used to decorate the registered :term:`view callable`. The + decorator function will be called with the view callable as a single + argument. The view callable it is passed will accept ``(context, + request)``. The decorator must return a replacement view callable which + also accepts ``(context, request)``. + +``mapper`` + A Python object or :term:`dotted Python name` which refers to a :term:`view + mapper`, or ``None``. By default it is ``None``, which indicates that the + view should use the default view mapper. This plug-point is useful for + Pyramid extension developers, but it's not very useful for 'civilians' who + are just developing stock Pyramid applications. Pay no attention to the man + behind the curtain. + Predicate Arguments +++++++++++++++++++ diff --git a/docs/zcml/view.rst b/docs/zcml/view.rst index b4fabdc2c..ba5c7bf23 100644 --- a/docs/zcml/view.rst +++ b/docs/zcml/view.rst @@ -213,6 +213,20 @@ Predicate Attributes associated view callable will be considered viable for a given request. +``decorator`` + A :term:`dotted Python name` to a function that will be used to decorate + the registered :term:`view callable`. The decorator function will be + called with the view callable as a single argument. The view callable it + is passed will accept ``(context, request)``. The decorator must return a + replacement view callable which also accepts ``(context, request)``. + +``mapper`` + A :term:`dotted Python name` which refers to a :term:`view mapper`, or + ``None``. By default it is ``None``, which indicates that the view should + use the default view mapper. This plug-point is useful for Pyramid + extension developers, but it's not very useful for 'civilians' who are just + developing stock Pyramid applications. + Examples ~~~~~~~~ diff --git a/pyramid/config.py b/pyramid/config.py index 84c902fe9..ff5d51fc4 100644 --- a/pyramid/config.py +++ b/pyramid/config.py @@ -1158,13 +1158,23 @@ class Configurator(object): decorator - A function which will be used to decorate the registered - :term:`view callable`. The decorator function will be called with - the view callable as a single argument. The view callable it is - passed will accept ``(context, request)`. The decorator must - return a replacement view callable which also accepts ``(context, + A :term:`dotted Python name` to function (or the function itself) + which will be used to decorate the registered :term:`view + callable`. The decorator function will be called with the view + callable as a single argument. The view callable it is passed will + accept ``(context, request)``. The decorator must return a + replacement view callable which also accepts ``(context, request)``. + mapper + + A Python object or :term:`dotted Python name` which refers to a + :term:`view mapper`, or ``None``. By default it is ``None``, which + indicates that the view should use the default view mapper. This + plug-point is useful for Pyramid extension developers, but it's not + very useful for 'civilians' who are just developing stock Pyramid + applications. Pay no attention to the man behind the curtain. + Predicate Arguments name @@ -1302,21 +1312,13 @@ class Configurator(object): ``True``, the associated view callable will be considered viable for a given request. - mapper - - A Python object or :term:`dotted Python name` which refers to a - :term:`view mapper`, or ``None``. By default it is ``None``, which - indicates that the view should use the default view mapper. This - plug-point is useful for Pyramid extension developers, but it's not - very useful for 'civilians' who are just developing stock Pyramid - applications. Pay no attention to the man behind the curtain. - """ view = self.maybe_dotted(view) context = self.maybe_dotted(context) for_ = self.maybe_dotted(for_) containment = self.maybe_dotted(containment) mapper = self.maybe_dotted(mapper) + decorator = self.maybe_dotted(decorator) if not view: if renderer: diff --git a/pyramid/view.py b/pyramid/view.py index 6ac5af082..26f64d5fc 100644 --- a/pyramid/view.py +++ b/pyramid/view.py @@ -276,6 +276,9 @@ class view_config(object): ``False``). The view will only be invoked if all custom predicates return ``True``. + See the :meth:`pyramid.config.Configurator.add_view`` method for + descriptions of the ``decorator`` and ``mapper`` arguments. + Any individual or all parameters can be omitted. The simplest :class:`pyramid.view.view_config` declaration is:: diff --git a/pyramid/zcml.py b/pyramid/zcml.py index a2088e505..298086912 100644 --- a/pyramid/zcml.py +++ b/pyramid/zcml.py @@ -128,6 +128,14 @@ class IViewDirective(Interface): description=(u'Accepts a regular expression.'), required = False) + decorator = GlobalObject( + title = u'View decorator', + required = False) + + mapper = GlobalObject( + title = u'View mapper', + required = False) + custom_predicates = Tokens( title=u"One or more custom dotted names to custom predicate callables", description=(u"A list of dotted name references to callables that " @@ -156,6 +164,8 @@ def view( header=None, path_info=None, traverse=None, + decorator=None, + mapper=None, custom_predicates=(), context=None, cacheable=True, # not used, here for b/w compat < 0.8 @@ -169,7 +179,8 @@ def view( request_method=request_method, request_param=request_param, containment=containment, attr=attr, renderer=renderer, wrapper=wrapper, xhr=xhr, accept=accept, header=header, - path_info=path_info, custom_predicates=custom_predicates) + path_info=path_info, custom_predicates=custom_predicates, + decorator=decorator, mapper=mapper) _view = view # for directives that take a view arg |
