Remove assert from WagtailPagination.paginate_queryset method

This commit is contained in:
Kim Chee Leong 2018-03-15 12:38:37 +01:00 committed by Karl Hobley
parent f7b0b6917c
commit 1ba4d84fb7

View file

@ -13,21 +13,23 @@ class WagtailPagination(BasePagination):
try:
offset = int(request.GET.get('offset', 0))
assert offset >= 0
except (ValueError, AssertionError):
if offset < 0:
raise ValueError()
except ValueError:
raise BadRequestError("offset must be a positive integer")
try:
limit_default = 20 if not limit_max else min(20, limit_max)
limit = int(request.GET.get('limit', limit_default))
if limit_max and limit > limit_max:
raise BadRequestError("limit cannot be higher than %d" % limit_max)
assert limit >= 0
except (ValueError, AssertionError):
if limit < 0:
raise ValueError()
except ValueError:
raise BadRequestError("limit must be a positive integer")
if limit_max and limit > limit_max:
raise BadRequestError(
"limit cannot be higher than %d" % limit_max)
start = offset
stop = offset + limit