diff options
| author | Michael Merickel <michael@merickel.org> | 2012-11-04 19:10:16 -0600 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2012-11-04 19:10:16 -0600 |
| commit | f194db1b3020e1c3610092f292c16a2f07219269 (patch) | |
| tree | 525e43f1d33d1697014108ca88432e23879f8ef3 | |
| parent | 49b189d0a1ed4ac102361f9b0e27ad3931f9f821 (diff) | |
| download | pyramid-f194db1b3020e1c3610092f292c16a2f07219269.tar.gz pyramid-f194db1b3020e1c3610092f292c16a2f07219269.tar.bz2 pyramid-f194db1b3020e1c3610092f292c16a2f07219269.zip | |
reversed the ordering of decorator arg to add_view
| -rw-r--r-- | pyramid/config/views.py | 22 | ||||
| -rw-r--r-- | pyramid/tests/test_config/test_views.py | 2 |
2 files changed, 13 insertions, 11 deletions
diff --git a/pyramid/config/views.py b/pyramid/config/views.py index 02d5b52bf..0cd61cba5 100644 --- a/pyramid/config/views.py +++ b/pyramid/config/views.py @@ -42,6 +42,7 @@ from pyramid.compat import ( url_quote, WIN, is_bound_method, + is_nonstr_iter ) from pyramid.exceptions import ( @@ -838,19 +839,19 @@ class ViewsConfiguratorMixin(object): decorator A :term:`dotted Python name` to function (or the function itself, - or a list or tuple of the aforementioned) - which will be used to decorate the registered :term:`view - callable`. The decorator function(s) will be called with the view - callable as a single argument. The view callable it is passed will - accept ``(context, request)``. The decorator(s) must return a + or an iterable of the aforementioned) which will be used to + decorate the registered :term:`view callable`. The decorator + function(s) will be called with the view callable as a single + argument. The view callable it is passed will accept + ``(context, request)``. The decorator(s) must return a replacement view callable which also accepts ``(context, request)``. - If decorator is a tuple or list of callables, the callables will be - combined and used in the order provided as a decorator. + If decorator is an iterable, the callables will be combined and + used in the order provided as a decorator. For example:: - @view_config(..., decorator=[decorator1, decorator2]) + @view_config(..., decorator=[decorator2, decorator1]) def myview(request): .... @@ -1096,12 +1097,13 @@ class ViewsConfiguratorMixin(object): def combine(*decorators): def decorated(view_callable): - for decorator in decorators: + # reversed() is allows a more natural ordering in the api + for decorator in reversed(decorators): view_callable = decorator(view_callable) return view_callable return decorated - if isinstance(decorator, (tuple, list)): + if is_nonstr_iter(decorator): decorator = combine(*map(self.maybe_dotted, decorator)) else: decorator = self.maybe_dotted(decorator) diff --git a/pyramid/tests/test_config/test_views.py b/pyramid/tests/test_config/test_views.py index a62e5f2ea..8324eb2b9 100644 --- a/pyramid/tests/test_config/test_views.py +++ b/pyramid/tests/test_config/test_views.py @@ -199,7 +199,7 @@ class TestViewsConfigurationMixin(unittest.TestCase): return 'wrapped2' + fn(context, request) return inner config = self._makeOne(autocommit=True) - config.add_view(view=view, decorator=(view_wrapper1, view_wrapper2), + config.add_view(view=view, decorator=(view_wrapper2, view_wrapper1), renderer=null_renderer) wrapper = self._getViewCallable(config) self.assertFalse(wrapper is view) |
