aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/generics.py
diff options
context:
space:
mode:
authorRoss McFarland2013-10-19 20:43:23 -0700
committerRoss McFarland2013-10-19 21:11:27 -0700
commit63e6a3b4925bf54e80ae63502a0353136e846b31 (patch)
treed3f95c8d4f1a8926c749a81e2ff07451778354bb /rest_framework/generics.py
parentc3aeb16557f2cbb1c1218b5af7bab646e4958234 (diff)
downloaddjango-rest-framework-63e6a3b4925bf54e80ae63502a0353136e846b31.tar.bz2
paginator should validate page and provide default
- use the standard paginator.validate_number method rather strict_postive_int. - support optional paginator method, default_page_number, to get the default page number rather than hard-coding it to 1 - this allows supporting non-integer based pagination which can be an important performance tweak on extermely large datasets or high request loads - relatively thorough unit tests of the changes
Diffstat (limited to 'rest_framework/generics.py')
-rw-r--r--rest_framework/generics.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/rest_framework/generics.py b/rest_framework/generics.py
index 4f134bce..6b42a1d5 100644
--- a/rest_framework/generics.py
+++ b/rest_framework/generics.py
@@ -145,10 +145,18 @@ class GenericAPIView(views.APIView):
allow_empty_first_page=self.allow_empty)
page_kwarg = self.kwargs.get(self.page_kwarg)
page_query_param = self.request.QUERY_PARAMS.get(self.page_kwarg)
- page = page_kwarg or page_query_param or 1
+ page = page_kwarg or page_query_param
+ if not page:
+ # we didn't recieve a page
+ if hasattr(paginator, 'default_page_number'):
+ # our paginator has a method that will provide a default
+ page = paginator.default_page_number()
+ else:
+ # fall back on the base default value
+ page = 1
try:
- page_number = strict_positive_int(page)
- except ValueError:
+ page_number = paginator.validate_number(page)
+ except InvalidPage:
if page == 'last':
page_number = paginator.num_pages
else: