mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 03:20:12 +03:00
Move strict_positive_int to pagination module
This commit is contained in:
parent
0bbc775b95
commit
a500b83ff2
|
@ -11,20 +11,10 @@ from django.utils.translation import ugettext as _
|
|||
from rest_framework import views, mixins, exceptions
|
||||
from rest_framework.request import clone_request
|
||||
from rest_framework.settings import api_settings
|
||||
from rest_framework.pagination import strict_positive_int
|
||||
import warnings
|
||||
|
||||
|
||||
def strict_positive_int(integer_string, cutoff=None):
|
||||
"""
|
||||
Cast a string to a strictly positive integer.
|
||||
"""
|
||||
ret = int(integer_string)
|
||||
if ret <= 0:
|
||||
raise ValueError()
|
||||
if cutoff:
|
||||
ret = min(ret, cutoff)
|
||||
return ret
|
||||
|
||||
def get_object_or_404(queryset, *filter_args, **filter_kwargs):
|
||||
"""
|
||||
Same as Django's standard shortcut, but make sure to raise 404
|
||||
|
|
|
@ -7,6 +7,18 @@ from rest_framework import serializers
|
|||
from rest_framework.templatetags.rest_framework import replace_query_param
|
||||
|
||||
|
||||
def strict_positive_int(integer_string, cutoff=None):
|
||||
"""
|
||||
Cast a string to a strictly positive integer.
|
||||
"""
|
||||
ret = int(integer_string)
|
||||
if ret <= 0:
|
||||
raise ValueError()
|
||||
if cutoff:
|
||||
ret = min(ret, cutoff)
|
||||
return ret
|
||||
|
||||
|
||||
class NextPageField(serializers.Field):
|
||||
"""
|
||||
Field that returns a link to the next page in paginated results.
|
||||
|
|
Loading…
Reference in New Issue
Block a user