Skip to content

Commit cfe89ea

Browse files
committed
Revert "deprecated JsonApi paginators class prefix to JSONAPI prefix for consistency (#463)"
This reverts commit e6290af.
1 parent 51b9946 commit cfe89ea

File tree

6 files changed

+21
-64
lines changed

6 files changed

+21
-64
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* Add `HyperlinkedRelatedField` and `SerializerMethodHyperlinkedRelatedField`. See [usage docs](docs/usage.md#related-fields)
55
* Add related urls support. See [usage docs](docs/usage.md#related-urls)
66
* Replaced binary `drf_example` sqlite3 db with a [fixture](example/fixtures/drf_example.yaml). See [usage docs](docs/usage.md#running-the-example-app).
7-
* For naming consistency, renamed new `JsonApi`-prefix pagination classes to `JSONAPI`-prefix.
8-
* Deprecates `JsonApiPageNumberPagination` and `JsonApiLimitOffsetPagination`
97
* Add optional [jsonapi-style](http://jsonapi.org/format/) filter backends. See [usage docs](docs/usage.md#filter-backends)
108

119
v2.5.0 - Released July 11, 2018

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ override ``settings.REST_FRAMEWORK``
161161
'PAGE_SIZE': 10,
162162
'EXCEPTION_HANDLER': 'rest_framework_json_api.exceptions.exception_handler',
163163
'DEFAULT_PAGINATION_CLASS':
164-
'rest_framework_json_api.pagination.JSONAPIPageNumberPagination',
164+
'rest_framework_json_api.pagination.JsonApiPageNumberPagination',
165165
'DEFAULT_PARSER_CLASSES': (
166166
'rest_framework_json_api.parsers.JSONParser',
167167
'rest_framework.parsers.FormParser',

docs/usage.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ REST_FRAMEWORK = {
1616
'PAGE_SIZE': 10,
1717
'EXCEPTION_HANDLER': 'rest_framework_json_api.exceptions.exception_handler',
1818
'DEFAULT_PAGINATION_CLASS':
19-
'rest_framework_json_api.pagination.JSONAPIPageNumberPagination',
19+
'rest_framework_json_api.pagination.JsonApiPageNumberPagination',
2020
'DEFAULT_PARSER_CLASSES': (
2121
'rest_framework_json_api.parsers.JSONParser',
2222
'rest_framework.parsers.FormParser',
@@ -59,15 +59,15 @@ You can configure fixed values for the page size or limit -- or allow the client
5959
via query parameters.
6060

6161
Two pagination classes are available:
62-
- `JSONAPIPageNumberPagination` breaks a response up into pages that start at a given page number
63-
with a given size (number of items per page). It can be configured with the following attributes:
62+
- `JsonApiPageNumberPagination` breaks a response up into pages that start at a given page number with a given size
63+
(number of items per page). It can be configured with the following attributes:
6464
- `page_query_param` (default `page[number]`)
6565
- `page_size_query_param` (default `page[size]`) Set this to `None` if you don't want to allow the client
6666
to specify the size.
6767
- `max_page_size` (default `100`) enforces an upper bound on the `page_size_query_param`.
6868
Set it to `None` if you don't want to enforce an upper bound.
69-
- `JSONAPILimitOffsetPagination` breaks a response up into pages that start from an item's offset
70-
in the viewset for a given number of items (the limit).
69+
- `JsonApiLimitOffsetPagination` breaks a response up into pages that start from an item's offset in the viewset for
70+
a given number of items (the limit).
7171
It can be configured with the following attributes:
7272
- `offset_query_param` (default `page[offset]`).
7373
- `limit_query_param` (default `page[limit]`).
@@ -78,14 +78,14 @@ Two pagination classes are available:
7878
These examples show how to configure the parameters to use non-standard names and different limits:
7979

8080
```python
81-
from rest_framework_json_api.pagination import JSONAPIPageNumberPagination, JSONAPILimitOffsetPagination
81+
from rest_framework_json_api.pagination import JsonApiPageNumberPagination, JsonApiLimitOffsetPagination
8282

83-
class MyPagePagination(JSONAPIPageNumberPagination):
83+
class MyPagePagination(JsonApiPageNumberPagination):
8484
page_query_param = 'page_number'
8585
page_size_query_param = 'page_size'
8686
max_page_size = 1000
8787

88-
class MyLimitPagination(JSONAPILimitOffsetPagination):
88+
class MyLimitPagination(JsonApiLimitOffsetPagination):
8989
offset_query_param = 'offset'
9090
limit_query_param = 'limit'
9191
max_limit = None

example/tests/unit/test_pagination.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
class TestLimitOffset:
1515
"""
16-
Unit tests for `pagination.JSONAPILimitOffsetPagination`.
16+
Unit tests for `pagination.JsonApiLimitOffsetPagination`.
1717
"""
1818

1919
def setup(self):
20-
class ExamplePagination(pagination.JSONAPILimitOffsetPagination):
20+
class ExamplePagination(pagination.JsonApiLimitOffsetPagination):
2121
default_limit = 10
2222
max_limit = 15
2323

@@ -85,27 +85,17 @@ def test_limit_offset_deprecation(self):
8585
assert len(record) == 1
8686
assert 'LimitOffsetPagination' in str(record[0].message)
8787

88-
with pytest.warns(DeprecationWarning) as record:
89-
pagination.JsonApiLimitOffsetPagination()
90-
assert len(record) == 1
91-
assert 'JsonApiLimitOffsetPagination' in str(record[0].message)
92-
9388

9489
# TODO: This test fails under py27 but it's not clear why so just leave it out for now.
9590
@pytest.mark.xfail((sys.version_info.major, sys.version_info.minor) == (2, 7),
9691
reason="python2.7 fails for unknown reason")
9792
class TestPageNumber:
9893
"""
99-
Unit tests for `pagination.JSONAPIPageNumberPagination`.
94+
Unit tests for `pagination.JsonApiPageNumberPagination`.
10095
TODO: add unit tests for changing query parameter names, limits, etc.
10196
"""
10297
def test_page_number_deprecation(self):
10398
with pytest.warns(DeprecationWarning) as record:
10499
pagination.PageNumberPagination()
105100
assert len(record) == 1
106101
assert 'PageNumberPagination' in str(record[0].message)
107-
108-
with pytest.warns(DeprecationWarning) as record:
109-
pagination.JsonApiPageNumberPagination()
110-
assert len(record) == 1
111-
assert 'JsonApiPageNumberPagination' in str(record[0].message)

example/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get_object(self):
3535
return super(BlogViewSet, self).get_object()
3636

3737

38-
class JSONAPIViewSet(ModelViewSet):
38+
class JsonApiViewSet(ModelViewSet):
3939
"""
4040
This is an example on how to configure DRF-jsonapi from
4141
within a class. It allows using DRF-jsonapi alongside
@@ -59,12 +59,12 @@ def handle_exception(self, exc):
5959
exc.status_code = HTTP_422_UNPROCESSABLE_ENTITY
6060
# exception handler can't be set on class so you have to
6161
# override the error response in this method
62-
response = super(JSONAPIViewSet, self).handle_exception(exc)
62+
response = super(JsonApiViewSet, self).handle_exception(exc)
6363
context = self.get_exception_handler_context()
6464
return format_drf_errors(response, context, exc)
6565

6666

67-
class BlogCustomViewSet(JSONAPIViewSet):
67+
class BlogCustomViewSet(JsonApiViewSet):
6868
queryset = Blog.objects.all()
6969
serializer_class = BlogSerializer
7070

rest_framework_json_api/pagination.py

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from rest_framework.views import Response
1010

1111

12-
class JSONAPIPageNumberPagination(PageNumberPagination):
12+
class JsonApiPageNumberPagination(PageNumberPagination):
1313
"""
1414
A json-api compatible pagination format
1515
"""
@@ -50,7 +50,7 @@ def get_paginated_response(self, data):
5050
})
5151

5252

53-
class JSONAPILimitOffsetPagination(LimitOffsetPagination):
53+
class JsonApiLimitOffsetPagination(LimitOffsetPagination):
5454
"""
5555
A limit/offset based style. For example:
5656
http://api.example.org/accounts/?page[limit]=100
@@ -100,23 +100,7 @@ def get_paginated_response(self, data):
100100
})
101101

102102

103-
class JsonApiPageNumberPagination(JSONAPIPageNumberPagination):
104-
"""
105-
Deprecated due to desire to use `JSONAPI` prefix for all classes.
106-
"""
107-
page_query_param = 'page'
108-
page_size_query_param = 'page_size'
109-
110-
def __init__(self):
111-
warnings.warn(
112-
'JsonApiPageNumberPagination is deprecated. Use JSONAPIPageNumberPagination '
113-
'or create custom pagination. See '
114-
'https://django-rest-framework-json-api.readthedocs.io/en/stable/usage.html#pagination',
115-
DeprecationWarning)
116-
super(JsonApiPageNumberPagination, self).__init__()
117-
118-
119-
class PageNumberPagination(JSONAPIPageNumberPagination):
103+
class PageNumberPagination(JsonApiPageNumberPagination):
120104
"""
121105
Deprecated paginator that uses different query parameters
122106
"""
@@ -125,37 +109,22 @@ class PageNumberPagination(JSONAPIPageNumberPagination):
125109

126110
def __init__(self):
127111
warnings.warn(
128-
'PageNumberPagination is deprecated. Use JSONAPIPageNumberPagination '
112+
'PageNumberPagination is deprecated. Use JsonApiPageNumberPagination '
129113
'or create custom pagination. See '
130114
'https://django-rest-framework-json-api.readthedocs.io/en/stable/usage.html#pagination',
131115
DeprecationWarning)
132116
super(PageNumberPagination, self).__init__()
133117

134118

135-
class JsonApiLimitOffsetPagination(JSONAPILimitOffsetPagination):
136-
"""
137-
Deprecated due to desire to use `JSONAPI` prefix for all classes.
138-
"""
139-
max_limit = None
140-
141-
def __init__(self):
142-
warnings.warn(
143-
'JsonApiLimitOffsetPagination is deprecated. Use JSONAPILimitOffsetPagination '
144-
'or create custom pagination. See '
145-
'https://django-rest-framework-json-api.readthedocs.io/en/stable/usage.html#pagination',
146-
DeprecationWarning)
147-
super(JsonApiLimitOffsetPagination, self).__init__()
148-
149-
150-
class LimitOffsetPagination(JSONAPILimitOffsetPagination):
119+
class LimitOffsetPagination(JsonApiLimitOffsetPagination):
151120
"""
152121
Deprecated paginator that uses a different max_limit
153122
"""
154123
max_limit = None
155124

156125
def __init__(self):
157126
warnings.warn(
158-
'LimitOffsetPagination is deprecated. Use JSONAPILimitOffsetPagination '
127+
'LimitOffsetPagination is deprecated. Use JsonApiLimitOffsetPagination '
159128
'or create custom pagination. See '
160129
'https://django-rest-framework-json-api.readthedocs.io/en/stable/usage.html#pagination',
161130
DeprecationWarning)

0 commit comments

Comments
 (0)