aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/views.py
diff options
context:
space:
mode:
authorBenoit C2012-01-09 21:09:38 +0100
committerBenoit C2012-01-09 21:09:38 +0100
commit94f24e2e2f6bff77fcc6ee23f5c90716becab192 (patch)
treeaea16a88b9f15028e97088b70e9ca844a3416e1b /djangorestframework/views.py
parente712ab0ba193e22e121fcd56dfea166bd84f57ed (diff)
downloaddjango-rest-framework-94f24e2e2f6bff77fcc6ee23f5c90716becab192.tar.bz2
Introduce a final methods in View class
Diffstat (limited to 'djangorestframework/views.py')
-rw-r--r--djangorestframework/views.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/djangorestframework/views.py b/djangorestframework/views.py
index 4606e50b..3df88391 100644
--- a/djangorestframework/views.py
+++ b/djangorestframework/views.py
@@ -154,19 +154,8 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
except ErrorResponse, exc:
response = exc.response
- # Always add these headers.
- #
- # TODO - this isn't actually the correct way to set the vary header,
- # also it's currently sub-optimal for HTTP caching - need to sort that out.
- response.headers['Allow'] = ', '.join(self.allowed_methods)
- response.headers['Vary'] = 'Authenticate, Accept'
-
- # merge with headers possibly set at some point in the view
- response.headers.update(self.headers)
-
set_script_prefix(orig_prefix)
-
- return self.render(response)
+ return self.final(request, response)
def options(self, request, *args, **kwargs):
response_obj = {
@@ -183,6 +172,21 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
response_obj['fields'] = field_name_types
return response_obj
+ def final(self, request, response, *args, **kargs):
+ """
+ As initial, final can be overriden to add code that must be set after the render
+ """
+ # Always add these headers.
+ #
+ # TODO - this isn't actually the correct way to set the vary header,
+ # also it's currently sub-optimal for HTTP caching - need to sort that out.
+ response.headers['Allow'] = ', '.join(self.allowed_methods)
+ response.headers['Vary'] = 'Authenticate, Accept'
+
+ # merge with headers possibly set at some point in the view
+ response.headers.update(self.headers)
+ return self.render(response)
+
class ModelView(View):
"""