From ab27bdb42d5b2c525466fe5570959f66b4814326 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 7 Aug 2010 04:41:40 +0000 Subject: Features -------- - There can only be one Not Found view in any ``repoze.bfg`` application. If you use ``repoze.bfg.view.append_slash_notfound_view`` as the Not Found view, it still must generate a NotFound response when it cannot redirect to a slash-appended URL; this not found response will be visible to site users. As of this release, if you wish to use a custom notfound view callable when ``append_slash_notfound_view`` does not redirect to a slash-appended URL, use a wrapper function as the ``repoze.bfg.exceptions.NotFound`` view; have this wrapper attach a view callable which returns a response to the request object named ``custom_notfound_view`` before calling ``append_slash_notfound_view``. For example:: from webob.exc import HTTPNotFound from repoze.bfg.exceptions import NotFound from repoze.bfg.view import append_slash_notfound_view def notfound_view(exc, request): def fallback_notfound_view(exc, request): return HTTPNotFound('It aint there, stop trying!') request.fallback_notfound_view = fallback_notfound_view return append_slash_notfound_view(exc, request) config.add_view(notfound_view, context=NotFound) ``custom_notfound_view`` must adhere to the two-argument view callable calling convention of ``(context, request)`` (``context`` will be the exception object). If ``custom_notfound_view`` is not found on the request object, a default notfound response will be generated when the ``append_slash_notfound_view`` doesn't redirect to a slash-appended URL. Documentation -------------- - Expanded the "Cleaning Up After a Request" section of the URL Dispatch narrative chapter. - Expanded the "Redirecting to Slash-Appended Routes" section of the URL Dispatch narrative chapter. --- repoze/bfg/tests/test_view.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'repoze/bfg/tests') diff --git a/repoze/bfg/tests/test_view.py b/repoze/bfg/tests/test_view.py index bb178029c..27f468c74 100644 --- a/repoze/bfg/tests/test_view.py +++ b/repoze/bfg/tests/test_view.py @@ -429,6 +429,15 @@ class AppendSlashNotFoundView(BaseTest, unittest.TestCase): response = self._callFUT(context, request) self.assertEqual(response.status, '404 Not Found') + def test_custom_notfound_view(self): + request = self._makeRequest(PATH_INFO='/abc') + def notfound(exc, request): + return 'abc' + request.custom_notfound_view = notfound + context = Exception() + response = self._callFUT(context, request) + self.assertEqual(response, 'abc') + def test_no_path(self): request = self._makeRequest() context = Exception() -- cgit v1.2.3