Skip to content

Commit 33fb4fa

Browse files
author
Eric Honkanen
committed
Added backwards compatibility with DRF 2.4.X, fixed media_type pass through
1 parent 25636c3 commit 33fb4fa

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

rest_framework_ember/pagination.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
from rest_framework_ember.utils import get_resource_name
66

7+
# DRF 2.4.X compatibility.
8+
ReadOnlyField = getattr(serializers, 'ReadOnlyField', serializers.Field)
79

8-
class NextPageLinkField(serializers.ReadOnlyField):
10+
11+
class NextPageLinkField(ReadOnlyField):
912
"""
1013
Field that returns a link to the next page in paginated results.
1114
"""
@@ -20,7 +23,7 @@ def to_representation(self, value):
2023
return replace_query_param(url, self.page_field, page)
2124

2225

23-
class NextPageField(serializers.ReadOnlyField):
26+
class NextPageField(ReadOnlyField):
2427
"""
2528
Field that returns a link to the next page in paginated results.
2629
"""
@@ -32,7 +35,7 @@ def to_representation(self, value):
3235
return value.next_page_number()
3336

3437

35-
class PreviousPageLinkField(serializers.ReadOnlyField):
38+
class PreviousPageLinkField(ReadOnlyField):
3639
"""
3740
Field that returns a link to the previous page in paginated results.
3841
"""
@@ -47,7 +50,7 @@ def to_representation(self, value):
4750
return replace_query_param(url, self.page_field, page)
4851

4952

50-
class PreviousPageField(serializers.ReadOnlyField):
53+
class PreviousPageField(ReadOnlyField):
5154
"""
5255
Field that returns a link to the previous page in paginated results.
5356
"""
@@ -59,7 +62,7 @@ def to_representation(self, value):
5962
return value.previous_page_number()
6063

6164

62-
class PageField(serializers.ReadOnlyField):
65+
class PageField(ReadOnlyField):
6366
"""
6467
Field that returns a link to the previous page in paginated results.
6568
"""
@@ -76,8 +79,8 @@ class PaginationSerializer(pagination.BasePaginationSerializer):
7679
page = PageField(source='*')
7780
previous = PreviousPageField(source='*')
7881
previous_link = PreviousPageLinkField(source='*')
79-
count = serializers.ReadOnlyField(source='paginator.count')
80-
total = serializers.ReadOnlyField(source='paginator.num_pages')
82+
count = ReadOnlyField(source='paginator.count')
83+
total = ReadOnlyField(source='paginator.num_pages')
8184

8285

8386
class EmberPaginationSerializer(PaginationSerializer):

rest_framework_ember/parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def parse(self, stream, media_type=None, parser_context=None):
2626
"""
2727
Parses the incoming bytestream as JSON and returns the resulting data
2828
"""
29-
result = super(JSONParser, self).parse(stream, media_type=None,
29+
result = super(JSONParser, self).parse(stream, media_type=media_type,
3030
parser_context=None)
3131
resource = result.get(get_resource_name(parser_context.get('view', None)))
3232
return format_keys(resource, 'underscore')

0 commit comments

Comments
 (0)