From 2e3d988956c37afa49cdf3b8f24e1c04286f0c25 Mon Sep 17 00:00:00 2001 From: Michael Merickel <michael@merickel.org> Date: Sat, 08 Jul 2017 17:54:16 +0200 Subject: [PATCH] Merge pull request #3121 from mmerickel/backport-3105-to-1.9-branch --- CONTRIBUTORS.txt | 2 ++ pyramid/view.py | 26 +++++++++++++++++--------- pyramid/tests/test_view.py | 20 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 242fbbc..062dcaf 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -308,3 +308,5 @@ - Volker Diels-Grabsch, 2017/06/09 - Denis Rykov, 2017/06/15 + +- Tosh Lyons, 2017/06/27 diff --git a/pyramid/tests/test_view.py b/pyramid/tests/test_view.py index e03487a..7a1c90d 100644 --- a/pyramid/tests/test_view.py +++ b/pyramid/tests/test_view.py @@ -566,6 +566,26 @@ decorator(foo) self.assertEqual(venusian.depth, 2) + def test_call_withoutcategory(self): + decorator = self._makeOne() + venusian = DummyVenusian() + decorator.venusian = venusian + def foo(): pass + decorator(foo) + attachments = venusian.attachments + category = attachments[0][2] + self.assertEqual(category, 'pyramid') + + def test_call_withcategory(self): + decorator = self._makeOne(_category='not_pyramid') + venusian = DummyVenusian() + decorator.venusian = venusian + def foo(): pass + decorator(foo) + attachments = venusian.attachments + category = attachments[0][2] + self.assertEqual(category, 'not_pyramid') + class Test_append_slash_notfound_view(BaseTest, unittest.TestCase): def _callFUT(self, context, request): from pyramid.view import append_slash_notfound_view 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