summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2011-05-24 21:28:43 +0000
committerLuke Plant <L.Plant.98@cantab.net>2011-05-24 21:28:43 +0000
commita482cc0ba38febda15194dc121989eed3b6deec2 (patch)
treef3cc1905c0553f2ae24b2538b6f771c8dddf4eb8 /django
parentd7036e52ab856b9e7125391cddcd18c08b5b0938 (diff)
Fixed #16004 - csrf_protect does not send cookie if view returns TemplateResponse
The root bug was in decorator_from_middleware, and the fix also corrects bugs with gzip_page and other decorators. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16276 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/core/handlers/base.py2
-rw-r--r--django/template/response.py7
-rw-r--r--django/utils/decorators.py15
3 files changed, 17 insertions, 7 deletions
diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py
index f216886d56..d653860547 100644
--- a/django/core/handlers/base.py
+++ b/django/core/handlers/base.py
@@ -133,7 +133,7 @@ class BaseHandler(object):
if hasattr(response, 'render') and callable(response.render):
for middleware_method in self._template_response_middleware:
response = middleware_method(request, response)
- response.render()
+ response = response.render()
except http.Http404, e:
logger.warning('Not Found: %s' % request.path,
diff --git a/django/template/response.py b/django/template/response.py
index a6ef893520..73645a7d72 100644
--- a/django/template/response.py
+++ b/django/template/response.py
@@ -92,11 +92,14 @@ class SimpleTemplateResponse(HttpResponse):
Returns the baked response instance.
"""
+ retval = self
if not self._is_rendered:
self._set_content(self.rendered_content)
for post_callback in self._post_render_callbacks:
- post_callback(self)
- return self
+ newretval = post_callback(retval)
+ if newretval is not None:
+ retval = newretval
+ return retval
is_rendered = property(lambda self: self._is_rendered)
diff --git a/django/utils/decorators.py b/django/utils/decorators.py
index ee169ec7cc..22f33a76a4 100644
--- a/django/utils/decorators.py
+++ b/django/utils/decorators.py
@@ -95,10 +95,17 @@ def make_middleware_decorator(middleware_class):
if result is not None:
return result
raise
- if hasattr(middleware, 'process_response'):
- result = middleware.process_response(request, response)
- if result is not None:
- return result
+ if hasattr(response, 'render') and callable(response.render):
+ if hasattr(middleware, 'process_template_response'):
+ response = middleware.process_template_response(request, response)
+ # Defer running of process_response until after the template
+ # has been rendered:
+ if hasattr(middleware, 'process_response'):
+ callback = lambda response: middleware.process_response(request, response)
+ response.add_post_render_callback(callback)
+ else:
+ if hasattr(middleware, 'process_response'):
+ return middleware.process_response(request, response)
return response
return _wrapped_view
return _decorator