summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Willison <simon@simonwillison.net>2008-07-02 08:32:14 +0000
committerSimon Willison <simon@simonwillison.net>2008-07-02 08:32:14 +0000
commit2e5cc7413fdf0ee3cee92d855cf9b75999c8d79a (patch)
tree7edf1fe511dff18b9505ac32f778fba238b90fb5
parent0e8710d5900a75b9a4a1caebb82c939896e99cff (diff)
newforms-admin: Fixed failing test by changing never_cache header to handle views that don't return a response object. The test traceback was:
====================================================================== ERROR: Test add view restricts access and actually adds items. ---------------------------------------------------------------------- Traceback (most recent call last): File ".../tests/regressiontests/admin_views/tests.py", line 178, in testAddView post = self.client.post('/test_admin/admin/admin_views/article/add/', self.super_login) File ".../django/test/client.py", line 265, in post return self.request(**r) File ".../django/core/handlers/base.py", line 82, in get_response response = callback(request, *callback_args, **callback_kwargs) File ".../django/contrib/admin/sites.py", line 113, in root response = self.login(request) File ".../django/views/decorators/cache.py", line 45, in _wrapped_view_func add_never_cache_headers(response) File ".../django/utils/cache.py", line 118, in add_never_cache_headers patch_response_headers(response, cache_timeout=-1) File ".../django/utils/cache.py", line 106, in patch_response_headers if not response.has_header('ETag'): AttributeError: 'NoneType' object has no attribute 'has_header' git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7824 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/views/decorators/cache.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/django/views/decorators/cache.py b/django/views/decorators/cache.py
index 8b620c1345..5f2bec20be 100644
--- a/django/views/decorators/cache.py
+++ b/django/views/decorators/cache.py
@@ -42,6 +42,9 @@ def never_cache(view_func):
"""
def _wrapped_view_func(request, *args, **kwargs):
response = view_func(request, *args, **kwargs)
- add_never_cache_headers(response)
+ # Although rare, it is possible for a view to return None (e.g. the
+ # django.contrib.admin.sites.AdminSite.login view in one corner-case)
+ if response:
+ add_never_cache_headers(response)
return response
return wraps(view_func)(_wrapped_view_func)