mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-16 19:22:24 +03:00
chore: Catch obsolete properties usage
This commit is contained in:
parent
398ba98e1b
commit
969080f02e
|
@ -5,13 +5,14 @@ In addition, Django's built in 403 and 404 exceptions are handled.
|
||||||
(`django.http.Http404` and `django.core.exceptions.PermissionDenied`)
|
(`django.http.Http404` and `django.core.exceptions.PermissionDenied`)
|
||||||
"""
|
"""
|
||||||
import math
|
import math
|
||||||
|
import warnings
|
||||||
|
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.utils.encoding import force_str
|
from django.utils.encoding import force_str
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.utils.translation import ngettext
|
from django.utils.translation import ngettext
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import RemovedInDRF317Warning, status
|
||||||
from rest_framework.utils.serializer_helpers import ReturnDict, ReturnList
|
from rest_framework.utils.serializer_helpers import ReturnDict, ReturnList
|
||||||
|
|
||||||
|
|
||||||
|
@ -233,12 +234,18 @@ class Throttled(APIException):
|
||||||
detail = force_str(self.default_detail)
|
detail = force_str(self.default_detail)
|
||||||
if wait is not None:
|
if wait is not None:
|
||||||
wait = math.ceil(wait)
|
wait = math.ceil(wait)
|
||||||
detail = " ".join((detail, force_str(self.extra_detail(wait))))
|
detail = " ".join((detail, self.extra_detail(wait)))
|
||||||
self.wait = wait
|
self.wait = wait
|
||||||
super().__init__(detail, code)
|
super().__init__(detail, code)
|
||||||
|
|
||||||
@staticmethod
|
def extra_detail(self, wait):
|
||||||
def extra_detail(wait):
|
if hasattr(self, 'extra_detail_singular') or hasattr(self, 'extra_detail_plural'):
|
||||||
|
warnings.warn("You're using incorrect way of specifying extra_detail, please override `extra_detail` instead. This will be removed in DRF 3.17", RemovedInDRF317Warning)
|
||||||
|
return ngettext(
|
||||||
|
getattr(self, 'extra_detail_singular', 'Expected available in {wait} second.'),
|
||||||
|
getattr(self, 'extra_detail_plural', 'Expected available in {wait} seconds.'),
|
||||||
|
wait,
|
||||||
|
).format(wait=wait)
|
||||||
return ngettext(
|
return ngettext(
|
||||||
'Expected available in {wait} second.',
|
'Expected available in {wait} second.',
|
||||||
'Expected available in {wait} seconds.',
|
'Expected available in {wait} seconds.',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user