diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-11-19 18:21:09 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-11-19 18:21:09 +0000 |
| commit | 1c02105e4fce880bca80e58be3191d2e1368596a (patch) | |
| tree | 6c0858b9ad1924e03a8f230d3762ee29d8cbd0d4 /repoze/bfg/view.py | |
| parent | a664df6400b3721a40f665d04b751e7a50b42ebc (diff) | |
| download | pyramid-1c02105e4fce880bca80e58be3191d2e1368596a.tar.gz pyramid-1c02105e4fce880bca80e58be3191d2e1368596a.tar.bz2 pyramid-1c02105e4fce880bca80e58be3191d2e1368596a.zip | |
- Each of the ``repoze.bfg.view.render_view``,
``repoze.bfg.view.render_view_to_iterable``,
``repoze.bfg.view.render_view_to_response``,
``repoze.bfg.view.append_slash_notfound_view``,
``repoze.bfg.view.default_notfound_view``,
``repoze.bfg.view.default_forbidden_view``, and the
``repoze.bfg.configuration.rendered_response`` functions now expects
to be called with a request object that has a ``registry`` attribute
which represents the current ZCA registry. This should only be a
problem when passing a custom request object to code which ends up
calling these functions in a unit test. To retrofit tests that end
up calling these functions which expect to be able to use a
non-registry-aware request object, use the
``repoze.bfg.threadlocal.get_current_request`` API in the test to
create the request; this will return a
``repoze.bfg.testing.DummyRequest`` that has the current registry as
its ``registry`` attribute. Alternatively, use the
``repoze.bfg.threadlocal.get_current_registry`` API: call this
function and add an attribute to your unit test request object named
``registry`` with the result.
- The ``repoze.bfg.view.derive_view`` callable has been removed. Use
``repoze.bfg.configuration.Configurator.derive_view`` instead (still
not an API, however).
Diffstat (limited to 'repoze/bfg/view.py')
| -rw-r--r-- | repoze/bfg/view.py | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/repoze/bfg/view.py b/repoze/bfg/view.py index 8ef8f3bb6..d94da9570 100644 --- a/repoze/bfg/view.py +++ b/repoze/bfg/view.py @@ -18,9 +18,7 @@ from webob.exc import HTTPFound from paste.urlparser import StaticURLParser -from zope.component import getSiteManager from zope.component import providedBy -from zope.component import queryUtility from zope.deprecation import deprecated from zope.interface.advice import getFrameInfo @@ -62,8 +60,8 @@ def render_view_to_response(context, request, name='', secure=True): ``args`` attribute explains why the view access was disallowed. If ``secure`` is ``False``, no permission checking is done.""" provides = map(providedBy, (context, request)) - sm = getSiteManager() - view = sm.adapters.lookup(provides, IView, name=name) + reg = request.registry + view = reg.adapters.lookup(provides, IView, name=name) if view is None: return None @@ -454,7 +452,12 @@ def default_view(context, request, status): """ % (status, status, msg) headers = [('Content-Length', str(len(html))), ('Content-Type', 'text/html')] - response_factory = queryUtility(IResponseFactory, default=Response) + response_factory = Response + registry = getattr(request, 'registry', None) + if registry is not None: + # be kind to old tests + response_factory = registry.queryUtility(IResponseFactory, + default=Response) return response_factory(status = status, headerlist = headers, app_iter = [html]) @@ -490,7 +493,8 @@ def append_slash_notfound_view(context, request): """ path = request.environ.get('PATH_INFO', '/') - mapper = queryUtility(IRoutesMapper) + registry = request.registry + mapper = registry.queryUtility(IRoutesMapper) if mapper is not None and not path.endswith('/'): slashpath = path + '/' for route in mapper.get_routes(): @@ -498,14 +502,3 @@ def append_slash_notfound_view(context, request): return HTTPFound(location=slashpath) return default_view(context, request, '404 Not Found') -def derive_view(original_view, permission=None, predicates=(), attr=None, - renderer_name=None, wrapper_viewname=None, viewname=None): - reg = getSiteManager() - from repoze.bfg.configuration import Configurator - config = Configurator(reg) - return config.derive_view(original_view, permission=permission, - predicates=predicates, attr=attr, - renderer_name=renderer_name, - wrapper_viewname=wrapper_viewname, - viewname=viewname) - |
