mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-13 13:16:55 +03:00
Introduce a final methods in View class
This commit is contained in:
parent
e712ab0ba1
commit
94f24e2e2f
|
@ -154,19 +154,8 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
|
||||||
except ErrorResponse, exc:
|
except ErrorResponse, exc:
|
||||||
response = exc.response
|
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)
|
set_script_prefix(orig_prefix)
|
||||||
|
return self.final(request, response)
|
||||||
return self.render(response)
|
|
||||||
|
|
||||||
def options(self, request, *args, **kwargs):
|
def options(self, request, *args, **kwargs):
|
||||||
response_obj = {
|
response_obj = {
|
||||||
|
@ -183,6 +172,21 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
|
||||||
response_obj['fields'] = field_name_types
|
response_obj['fields'] = field_name_types
|
||||||
return response_obj
|
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):
|
class ModelView(View):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user