Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e6290af

Browse files
n2ygksliverc
authored andcommitted
deprecated JsonApi paginators class prefix to JSONAPI prefix for consistency (#463)
1 parent 81d2236 commit e6290af

File tree

6 files changed

+64
-21
lines changed

6 files changed

+64
-21
lines changed

‎CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
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).
77
* Add optional [jsonapi-style](http://jsonapi.org/format/) sort filter backend. See [usage docs](docs/usage.md#filter-backends)
8+
* For naming consistency, renamed new `JsonApi`-prefix pagination classes to `JSONAPI`-prefix.
9+
* Deprecates `JsonApiPageNumberPagination` and `JsonApiLimitOffsetPagination`
810

911
v2.5.0 - Released July 11, 2018
1012

‎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',
@@ -58,15 +58,15 @@ You can configure fixed values for the page size or limit -- or allow the client
5858
via query parameters.
5959

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

7979
```python
80-
from rest_framework_json_api.pagination import JsonApiPageNumberPagination, JsonApiLimitOffsetPagination
80+
from rest_framework_json_api.pagination import JSONAPIPageNumberPagination, JSONAPILimitOffsetPagination
8181

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

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

‎example/tests/unit/test_pagination.py

Lines changed: 13 additions & 3 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,17 +85,27 @@ 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+
8893

8994
# TODO: This test fails under py27 but it's not clear why so just leave it out for now.
9095
@pytest.mark.xfail((sys.version_info.major, sys.version_info.minor) == (2, 7),
9196
reason="python2.7 fails for unknown reason")
9297
class TestPageNumber:
9398
"""
94-
Unit tests for `pagination.JsonApiPageNumberPagination`.
99+
Unit tests for `pagination.JSONAPIPageNumberPagination`.
95100
TODO: add unit tests for changing query parameter names, limits, etc.
96101
"""
97102
def test_page_number_deprecation(self):
98103
with pytest.warns(DeprecationWarning) as record:
99104
pagination.PageNumberPagination()
100105
assert len(record) == 1
101106
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
@@ -34,7 +34,7 @@ def get_object(self):
3434
return super(BlogViewSet, self).get_object()
3535

3636

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

6565

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

‎rest_framework_json_api/pagination.py

Lines changed: 37 additions & 6 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,7 +100,23 @@ def get_paginated_response(self, data):
100100
})
101101

102102

103-
class PageNumberPagination(JsonApiPageNumberPagination):
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):
104120
"""
105121
Deprecated paginator that uses different query parameters
106122
"""
@@ -109,22 +125,37 @@ class PageNumberPagination(JsonApiPageNumberPagination):
109125

110126
def __init__(self):
111127
warnings.warn(
112-
'PageNumberPagination is deprecated. Use JsonApiPageNumberPagination '
128+
'PageNumberPagination is deprecated. Use JSONAPIPageNumberPagination '
113129
'or create custom pagination. See '
114130
'https://django-rest-framework-json-api.readthedocs.io/en/stable/usage.html#pagination',
115131
DeprecationWarning)
116132
super(PageNumberPagination, self).__init__()
117133

118134

119-
class LimitOffsetPagination(JsonApiLimitOffsetPagination):
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):
120151
"""
121152
Deprecated paginator that uses a different max_limit
122153
"""
123154
max_limit = None
124155

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /