Add a system checks file

Add a check for pagination settings for the 3.7 upgrade cycle.
This commit is contained in:
Matt Davis 2017-09-24 22:57:05 -04:00
parent a224b6b935
commit 420bc48cfd
3 changed files with 21 additions and 12 deletions

View File

@ -6,6 +6,7 @@ ______ _____ _____ _____ __
| |\ \| |___/\__/ / | | | | | | | (_| | | | | | | __/\ V V / (_) | | | <
\_| \_\____/\____/ \_/ |_| |_| \__,_|_| |_| |_|\___| \_/\_/ \___/|_| |_|\_|
"""
import checks # NOQA
__title__ = 'Django REST framework'
__version__ = '3.6.3'

20
rest_framework/checks.py Normal file
View File

@ -0,0 +1,20 @@
from django.core.checks import Tags, Warning, register
@register(Tags.compatibility)
def pagination_system_check(app_configs, **kwargs):
errors = []
# Use of default page size setting requires a default Paginator class
from rest_framework.settings import api_settings
if api_settings.PAGE_SIZE and not api_settings.DEFAULT_PAGINATION_CLASS:
errors.append(
Warning(
"You have specified a default PAGE_SIZE` pagination rest_framework setting,"
"without specifying also a `DEFAULT_PAGINATION_CLASS`.",
hint="The prior version of rest_framework defaulted this setting to "
"`PageNumberPagination` however pagination defaults to disabled now. "
"Consider specifying `DEFAULT_PAGINATION_CLASS` explicitly for your project, "
"unless you specify individual pagination_class values on specific view classes.",
)
)
return errors

View File

@ -5,7 +5,6 @@ be used for paginated responses.
"""
from __future__ import unicode_literals
import warnings
from base64 import b64decode, b64encode
from collections import OrderedDict, namedtuple
@ -147,17 +146,6 @@ PAGE_BREAK = PageLink(url=None, number=None, is_active=False, is_break=True)
class BasePagination(object):
display_page_controls = False
def __init__(self, *args, **kwargs):
# Use of default page size setting requires a default Paginator class
if api_settings.PAGE_SIZE and not api_settings.DEFAULT_PAGINATION_CLASS:
warnings.warn(
"A valid paginator class must be specified with `DEFAULT_PAGINATION_CLASS` "
"when using the `PAGE_SIZE` default pagination setting."
"Defaulting the setting to specifies `PageNumberPagination` "
"is deprecated as pagination is disabled by default.",
DeprecationWarning
)
def paginate_queryset(self, queryset, request, view=None): # pragma: no cover
raise NotImplementedError('paginate_queryset() must be implemented.')