Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add 'page_kwarg' attribute to `MultipleObjectMixin`, removing hardcod…

…ed 'page'.
  • Loading branch information...
commit 502be865c68635d5c31fa3fa58162b48412153ad 1 parent da56e1b
Tom Christie authored October 25, 2012
4  django/views/generic/list.py
@@ -17,6 +17,7 @@ class MultipleObjectMixin(ContextMixin):
17 17
     paginate_by = None
18 18
     context_object_name = None
19 19
     paginator_class = Paginator
  20
+    page_kwarg = 'page'
20 21
 
21 22
     def get_queryset(self):
22 23
         """
@@ -39,7 +40,8 @@ def paginate_queryset(self, queryset, page_size):
39 40
         Paginate the queryset, if needed.
40 41
         """
41 42
         paginator = self.get_paginator(queryset, page_size, allow_empty_first_page=self.get_allow_empty())
42  
-        page = self.kwargs.get('page') or self.request.GET.get('page') or 1
  43
+        page_kwarg = self.page_kwarg
  44
+        page = self.kwargs.get(page_kwarg) or self.request.GET.get(page_kwarg) or 1
43 45
         try:
44 46
             page_number = int(page)
45 47
         except ValueError:
11  docs/ref/class-based-views/mixins-multiple-object.txt
@@ -69,8 +69,15 @@ MultipleObjectMixin
69 69
         An integer specifying how many objects should be displayed per page. If
70 70
         this is given, the view will paginate objects with
71 71
         :attr:`MultipleObjectMixin.paginate_by` objects per page. The view will
72  
-        expect either a ``page`` query string parameter (via ``GET``) or a
73  
-        ``page`` variable specified in the URLconf.
  72
+        expect either a ``page`` query string parameter (via ``request.GET``)
  73
+        or a ``page`` variable specified in the URLconf.
  74
+
  75
+    .. attribute:: page_kwarg
  76
+
  77
+        A string specifying the name to use for the page parameter.
  78
+        The view will expect this prameter to be available either as a query
  79
+        string parameter (via ``request.GET``) or as a kwarg variable specified
  80
+        in the URLconf.  Defaults to ``"page"``.
74 81
 
75 82
     .. attribute:: paginator_class
76 83
 

0 notes on commit 502be86

Please sign in to comment.
Something went wrong with that request. Please try again.