diff options
| author | Michael Merickel <michael@merickel.org> | 2017-07-07 21:52:21 -0500 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2017-07-07 21:52:21 -0500 |
| commit | ff94b32c213181b1d8d8a98065d222da0cdce36b (patch) | |
| tree | c897f2324b41d92e7f12ff5d8e7dca01439c30fa | |
| parent | 34eb9f4b60df183c88d9efd104136d448b494124 (diff) | |
| parent | ebc077c536fd46f69152fcf649e68a93500bb758 (diff) | |
| download | pyramid-ff94b32c213181b1d8d8a98065d222da0cdce36b.tar.gz pyramid-ff94b32c213181b1d8d8a98065d222da0cdce36b.tar.bz2 pyramid-ff94b32c213181b1d8d8a98065d222da0cdce36b.zip | |
Merge branch 'pr/3105'
| -rw-r--r-- | CONTRIBUTORS.txt | 2 | ||||
| -rw-r--r-- | pyramid/tests/test_view.py | 20 | ||||
| -rw-r--r-- | pyramid/view.py | 26 |
3 files changed, 39 insertions, 9 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 242fbbcda..062dcafd7 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -308,3 +308,5 @@ Contributors - 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 e03487a70..7a1c90deb 100644 --- a/pyramid/tests/test_view.py +++ b/pyramid/tests/test_view.py @@ -566,6 +566,26 @@ class TestViewConfigDecorator(unittest.TestCase): 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 dc4aae3fa..3b2bafa27 100644 --- a/pyramid/view.py +++ b/pyramid/view.py @@ -185,14 +185,21 @@ class view_config(object): :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 @@ class view_config(object): 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': |
