From 2c5f77d7776ae9b221d6e5af11c1710335d65bd3 Mon Sep 17 00:00:00 2001 From: tosh <toshism@gmail.com> Date: Sat, 08 Jul 2017 04:53:54 +0200 Subject: [PATCH] backport #3105: add support for custom category in view_config decorator --- pyramid/view.py | 26 +++++++++++++++++--------- 1 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pyramid/view.py b/pyramid/view.py index dc4aae3..3b2bafa 100644 --- a/pyramid/view.py +++ b/pyramid/view.py @@ -185,14 +185,21 @@ :meth:`pyramid.config.Configurator.add_view`. If any argument is left out, its default will be the equivalent ``add_view`` default. - An additional keyword argument named ``_depth`` is provided for people who - wish to reuse this class from another decorator. The default value is - ``0`` and should be specified relative to the ``view_config`` invocation. - It will be passed in to the :term:`venusian` ``attach`` function as the - depth of the callstack when Venusian checks if the decorator is being used - in a class or module context. It's not often used, but it can be useful - in this circumstance. See the ``attach`` function in Venusian for more - information. + Two additional keyword arguments which will be passed to the + :term:`venusian` ``attach`` function are ``_depth`` and ``_category``. + + ``_depth`` is provided for people who wish to reuse this class from another + decorator. The default value is ``0`` and should be specified relative to + the ``view_config`` invocation. It will be passed in to the + :term:`venusian` ``attach`` function as the depth of the callstack when + Venusian checks if the decorator is being used in a class or module + context. It's not often used, but it can be useful in this circumstance. + + ``_category`` sets the decorator category name. It can be useful in + combination with the ``category`` argument of ``scan`` to control which + views should be processed. + + See the :py:func:`venusian.attach` function in Venusian for more information. .. seealso:: @@ -215,12 +222,13 @@ def __call__(self, wrapped): settings = self.__dict__.copy() depth = settings.pop('_depth', 0) + category = settings.pop('_category', 'pyramid') def callback(context, name, ob): config = context.config.with_package(info.module) config.add_view(view=ob, **settings) - info = self.venusian.attach(wrapped, callback, category='pyramid', + info = self.venusian.attach(wrapped, callback, category=category, depth=depth + 1) if info.scope == 'class': -- Gitblit v1.9.3