mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Tweak media_type -> accepted_media_type. Need to document, but marginally less confusing
This commit is contained in:
parent
d9cba6398e
commit
b4cd699b75
|
@ -9,7 +9,7 @@ class Response(SimpleTemplateResponse):
|
|||
"""
|
||||
|
||||
def __init__(self, data=None, status=None, headers=None,
|
||||
renderer=None, media_type=None):
|
||||
renderer=None, accepted_media_type=None):
|
||||
"""
|
||||
Alters the init arguments slightly.
|
||||
For example, drop 'template_name', and instead use 'data'.
|
||||
|
@ -21,14 +21,15 @@ class Response(SimpleTemplateResponse):
|
|||
self.data = data
|
||||
self.headers = headers and headers[:] or []
|
||||
self.renderer = renderer
|
||||
self.media_type = media_type
|
||||
self.accepted_media_type = accepted_media_type
|
||||
|
||||
@property
|
||||
def rendered_content(self):
|
||||
self['Content-Type'] = self.renderer.media_type
|
||||
if self.data is None:
|
||||
return self.renderer.render()
|
||||
return self.renderer.render(self.data, self.media_type)
|
||||
render_media_type = self.accepted_media_type or self.renderer.media_type
|
||||
return self.renderer.render(self.data, render_media_type)
|
||||
|
||||
@property
|
||||
def status_text(self):
|
||||
|
|
|
@ -161,7 +161,7 @@ class APIView(View):
|
|||
"""
|
||||
return [throttle(self) for throttle in self.throttle_classes]
|
||||
|
||||
def content_negotiation(self, request, force=False):
|
||||
def perform_content_negotiation(self, request, force=False):
|
||||
"""
|
||||
Determine which renderer and media type to use render the response.
|
||||
"""
|
||||
|
@ -199,7 +199,7 @@ class APIView(View):
|
|||
self.format = self.get_format_suffix(**kwargs)
|
||||
self.check_permissions(request)
|
||||
self.check_throttles(request)
|
||||
self.renderer, self.media_type = self.content_negotiation(request)
|
||||
self.renderer, self.accepted_media_type = self.perform_content_negotiation(request)
|
||||
|
||||
def finalize_response(self, request, response, *args, **kwargs):
|
||||
"""
|
||||
|
@ -207,9 +207,9 @@ class APIView(View):
|
|||
"""
|
||||
if isinstance(response, Response):
|
||||
if not getattr(self, 'renderer', None):
|
||||
self.renderer, self.media_type = self.content_negotiation(request, force=True)
|
||||
self.renderer, self.accepted_media_type = self.perform_content_negotiation(request, force=True)
|
||||
response.renderer = self.renderer
|
||||
response.media_type = self.media_type
|
||||
response.accepted_media_type = self.accepted_media_type
|
||||
|
||||
for key, value in self.headers.items():
|
||||
response[key] = value
|
||||
|
|
Loading…
Reference in New Issue
Block a user