mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Use request.QUERY_PARAMS internally
(instead of request.GET)
This commit is contained in:
parent
b9f1fbb5d2
commit
2c634c0e5c
|
@ -54,6 +54,6 @@ class DjangoFilterBackend(BaseFilterBackend):
|
|||
filter_class = self.get_filter_class(view)
|
||||
|
||||
if filter_class:
|
||||
return filter_class(request.GET, queryset=queryset)
|
||||
return filter_class(request.QUERY_PARAMS, queryset=queryset)
|
||||
|
||||
return queryset
|
||||
|
|
|
@ -33,7 +33,7 @@ class DefaultContentNegotiation(BaseContentNegotiation):
|
|||
"""
|
||||
# Allow URL style format override. eg. "?format=json
|
||||
format_query_param = self.settings.URL_FORMAT_OVERRIDE
|
||||
format = format_suffix or request.GET.get(format_query_param)
|
||||
format = format_suffix or request.QUERY_PARAMS.get(format_query_param)
|
||||
|
||||
if format:
|
||||
renderers = self.filter_renderers(renderers, format)
|
||||
|
@ -80,5 +80,5 @@ class DefaultContentNegotiation(BaseContentNegotiation):
|
|||
Allows URL style accept override. eg. "?accept=application/json"
|
||||
"""
|
||||
header = request.META.get('HTTP_ACCEPT', '*/*')
|
||||
header = request.GET.get(self.settings.URL_ACCEPT_OVERRIDE, header)
|
||||
header = request.QUERY_PARAMS.get(self.settings.URL_ACCEPT_OVERRIDE, header)
|
||||
return [token.strip() for token in header.split(',')]
|
||||
|
|
|
@ -88,7 +88,7 @@ class JSONPRenderer(JSONRenderer):
|
|||
Determine the name of the callback to wrap around the json output.
|
||||
"""
|
||||
request = renderer_context.get('request', None)
|
||||
params = request and request.GET or {}
|
||||
params = request and request.QUERY_PARAMS or {}
|
||||
return params.get(self.callback_parameter, self.default_callback)
|
||||
|
||||
def render(self, data, accepted_media_type=None, renderer_context=None):
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
from rest_framework.negotiation import DefaultContentNegotiation
|
||||
from rest_framework.request import Request
|
||||
|
||||
|
||||
factory = RequestFactory()
|
||||
|
||||
|
@ -22,16 +24,16 @@ class TestAcceptedMediaType(TestCase):
|
|||
return self.negotiator.select_renderer(request, self.renderers)
|
||||
|
||||
def test_client_without_accept_use_renderer(self):
|
||||
request = factory.get('/')
|
||||
request = Request(factory.get('/'))
|
||||
accepted_renderer, accepted_media_type = self.select_renderer(request)
|
||||
self.assertEquals(accepted_media_type, 'application/json')
|
||||
|
||||
def test_client_underspecifies_accept_use_renderer(self):
|
||||
request = factory.get('/', HTTP_ACCEPT='*/*')
|
||||
request = Request(factory.get('/', HTTP_ACCEPT='*/*'))
|
||||
accepted_renderer, accepted_media_type = self.select_renderer(request)
|
||||
self.assertEquals(accepted_media_type, 'application/json')
|
||||
|
||||
def test_client_overspecifies_accept_use_client(self):
|
||||
request = factory.get('/', HTTP_ACCEPT='application/json; indent=8')
|
||||
request = Request(factory.get('/', HTTP_ACCEPT='application/json; indent=8'))
|
||||
accepted_renderer, accepted_media_type = self.select_renderer(request)
|
||||
self.assertEquals(accepted_media_type, 'application/json; indent=8')
|
||||
|
|
Loading…
Reference in New Issue
Block a user