Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 00e19f1

Browse files
author
Christopher Keele
committed
Expose that handy tables.paginate to the class based view, so pagination can be customized.
1 parent 99b4eef commit 00e19f1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

django_tables2/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class RequestConfig(object):
1212
default ``per_page`` value).
1313
1414
"""
15-
def __init__(self, request, paginate=True):
15+
def __init__(self, request, paginate):
1616
self.request = request
1717
self.paginate = paginate
1818

django_tables2/views.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class SingleTableMixin(object):
2626
table_class = None
2727
table_data = None
2828
context_table_name = None
29+
paginate = True
2930

3031
def get_table(self):
3132
"""
@@ -34,7 +35,8 @@ def get_table(self):
3435
"""
3536
table_class = self.get_table_class()
3637
table = table_class(self.get_table_data())
37-
RequestConfig(self.request).configure(table)
38+
paginate = self.get_paginate()
39+
RequestConfig(self.request, paginate).configure(table)
3840
return table
3941

4042
def get_table_class(self):
@@ -64,6 +66,20 @@ def get_table_data(self):
6466
raise ImproperlyConfigured(u"Table data was not specified. Define "
6567
u"%(cls)s.table_data"
6668
% {"cls": type(self).__name__})
69+
70+
def get_paginate(self):
71+
"""
72+
Returns pagination options: True for default, False for no pagination, and a dictionary for custom pagination.
73+
"""
74+
if isinstance(self.paginate, int):
75+
return bool(self.paginate)
76+
else:
77+
try:
78+
# Duck type for dictionary-like objects
79+
self.paginate.keys()
80+
return self.paginate
81+
except TypeError:
82+
print "%(cls)s.paginate must be true, false, or a dictionary." % {"cls": type(self).__name__}
6783

6884
def get_context_data(self, **kwargs):
6985
"""

0 commit comments

Comments
 (0)