diff options
| author | Jannis Leidel <jannis@leidel.info> | 2011-09-08 13:25:31 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2011-09-08 13:25:31 +0000 |
| commit | 7cb140e6d86e9c592983ddb50bfd82480ecec7eb (patch) | |
| tree | 911a20c13b99181dada4709c1ad702c54891af8c /django | |
| parent | 2189a8e50ab7e0c76193fe1a18934641c9a05ff0 (diff) | |
Fixed #16003 -- Restored compatibility of the admin when using USE_ETAGS. Thanks for the initial patch, pterk.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16729 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/utils/cache.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/django/utils/cache.py b/django/utils/cache.py index 45d8a95f66..10d0a23ff8 100644 --- a/django/utils/cache.py +++ b/django/utils/cache.py @@ -92,6 +92,10 @@ def get_max_age(response): except (ValueError, TypeError): pass +def _set_response_etag(response): + response['ETag'] = '"%s"' % hashlib.md5(response.content).hexdigest() + return response + def patch_response_headers(response, cache_timeout=None): """ Adds some useful headers to the given HttpResponse object: @@ -107,7 +111,10 @@ def patch_response_headers(response, cache_timeout=None): if cache_timeout < 0: cache_timeout = 0 # Can't have max-age negative if settings.USE_ETAGS and not response.has_header('ETag'): - response['ETag'] = '"%s"' % hashlib.md5(response.content).hexdigest() + if hasattr(response, 'render') and callable(response.render): + response.add_post_render_callback(_set_response_etag) + else: + response = _set_response_etag(response) if not response.has_header('Last-Modified'): response['Last-Modified'] = http_date() if not response.has_header('Expires'): |
