From 4be1e6ccd46adc6c9515d68bee12965cfc7e285e Mon Sep 17 00:00:00 2001 From: tosh Date: Mon, 26 Jun 2017 19:03:45 -0500 Subject: add support for custom category in view_config decorator --- pyramid/tests/test_view.py | 20 ++++++++++++++++++++ pyramid/view.py | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pyramid/tests/test_view.py b/pyramid/tests/test_view.py index e03487a70..43459947c 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..a3f193011 100644 --- a/pyramid/view.py +++ b/pyramid/view.py @@ -215,12 +215,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': -- cgit v1.2.3 From ea49281948ebe97a43a88e85ee0cd4260e6d3a58 Mon Sep 17 00:00:00 2001 From: tosh Date: Mon, 26 Jun 2017 19:35:38 -0500 Subject: documentation for view_config category argument --- pyramid/view.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pyramid/view.py b/pyramid/view.py index a3f193011..8dbad75e2 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 to ``scan`` to control which + views should be processed. + + See the ``attach`` function in Venusian for more information. .. seealso:: -- cgit v1.2.3 From eb596cbc0561b745d34385bc5d0c04aa01abfaa9 Mon Sep 17 00:00:00 2001 From: tosh Date: Tue, 27 Jun 2017 08:11:42 -0500 Subject: documentation updates link to relevant venusian docs improved grammer --- pyramid/view.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyramid/view.py b/pyramid/view.py index 8dbad75e2..e5db6cea4 100644 --- a/pyramid/view.py +++ b/pyramid/view.py @@ -196,10 +196,10 @@ class view_config(object): 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 to ``scan`` to control which + combination with the ``category`` argument of ``scan`` to control which views should be processed. - See the ``attach`` function in Venusian for more information. + See the :py:func:`venusian.attach` function in Venusian for more information. .. seealso:: -- cgit v1.2.3 From 0afdad53997f96fa6e800d25e2a98c25653b9d38 Mon Sep 17 00:00:00 2001 From: tosh Date: Tue, 27 Jun 2017 11:26:47 -0500 Subject: rename view_config argmuent category to _category --- pyramid/tests/test_view.py | 2 +- pyramid/view.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyramid/tests/test_view.py b/pyramid/tests/test_view.py index 43459947c..7a1c90deb 100644 --- a/pyramid/tests/test_view.py +++ b/pyramid/tests/test_view.py @@ -577,7 +577,7 @@ class TestViewConfigDecorator(unittest.TestCase): self.assertEqual(category, 'pyramid') def test_call_withcategory(self): - decorator = self._makeOne(category='not_pyramid') + decorator = self._makeOne(_category='not_pyramid') venusian = DummyVenusian() decorator.venusian = venusian def foo(): pass diff --git a/pyramid/view.py b/pyramid/view.py index e5db6cea4..3b2bafa27 100644 --- a/pyramid/view.py +++ b/pyramid/view.py @@ -186,7 +186,7 @@ class view_config(object): out, its default will be the equivalent ``add_view`` default. Two additional keyword arguments which will be passed to the - :term:`venusian` ``attach`` function are ``_depth`` and ``category``. + :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 @@ -195,7 +195,7 @@ class view_config(object): 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 + ``_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. @@ -222,7 +222,7 @@ class view_config(object): def __call__(self, wrapped): settings = self.__dict__.copy() depth = settings.pop('_depth', 0) - category = settings.pop('category', 'pyramid') + category = settings.pop('_category', 'pyramid') def callback(context, name, ob): config = context.config.with_package(info.module) -- cgit v1.2.3 From ebc077c536fd46f69152fcf649e68a93500bb758 Mon Sep 17 00:00:00 2001 From: tosh Date: Tue, 27 Jun 2017 13:58:18 -0500 Subject: add tosh lyons to contributors.txt file --- CONTRIBUTORS.txt | 2 ++ 1 file changed, 2 insertions(+) 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 -- cgit v1.2.3