Chris McDonough
2011-01-08 0b0e74764fa0f2a3d6daa8f8ce70112419ea6981
- Allow ``decorator`` and ``mapper`` arguments to view ZCML directive.

- Document ``decorator`` and ``mapper`` arguments in various places.
6 files modified
85 ■■■■ changed files
TODO.txt 9 ●●●● patch | view | raw | blame | history
docs/narr/views.rst 16 ●●●●● patch | view | raw | blame | history
docs/zcml/view.rst 14 ●●●●● patch | view | raw | blame | history
pyramid/config.py 30 ●●●● patch | view | raw | blame | history
pyramid/view.py 3 ●●●●● patch | view | raw | blame | history
pyramid/zcml.py 13 ●●●●● patch | view | raw | blame | history
TODO.txt
@@ -11,15 +11,10 @@
- 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).
docs/narr/views.rst
@@ -658,6 +658,22 @@
  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
+++++++++++++++++++
docs/zcml/view.rst
@@ -213,6 +213,20 @@
  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
~~~~~~~~
pyramid/config.py
@@ -1158,12 +1158,22 @@
        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
@@ -1302,21 +1312,13 @@
          ``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:
pyramid/view.py
@@ -276,6 +276,9 @@
    ``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::
pyramid/zcml.py
@@ -128,6 +128,14 @@
        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 @@
    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 @@
        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