mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-06 15:16:20 +01:00
handle no pagination
This commit is contained in:
@@ -174,6 +174,10 @@ class DataTablesView(View):
|
||||
draw = int(table_conf["draw"])
|
||||
start = int(table_conf["start"])
|
||||
length = int(table_conf["length"])
|
||||
if length <= 0:
|
||||
logger.warning(
|
||||
"Using no pagination is not recommended for server side rendered datatables"
|
||||
)
|
||||
limit = start + length
|
||||
|
||||
|
||||
@@ -192,7 +196,10 @@ class DataTablesView(View):
|
||||
)
|
||||
|
||||
# build output
|
||||
for row in qs[start:limit]:
|
||||
if length > 0:
|
||||
qs = qs[start:limit]
|
||||
|
||||
for row in qs:
|
||||
ctx = {"row": row}
|
||||
row = []
|
||||
for t in self.columns:
|
||||
|
||||
@@ -267,3 +267,12 @@ class TestDataTables(TestCase):
|
||||
response.setup(request)
|
||||
data = json.loads(response.get(request).content)["data"]
|
||||
self.assertEqual(len(data), 19)
|
||||
|
||||
def test_view_cc_no_pagination(self):
|
||||
self.get_params["length"] = "-1"
|
||||
self.client.force_login(self.user)
|
||||
request = self.factory.get('/fake-url/', data=self.get_params)
|
||||
response = TestView()
|
||||
response.setup(request)
|
||||
data = json.loads(response.get(request).content)["data"]
|
||||
self.assertEqual(len(data), 20)
|
||||
|
||||
Reference in New Issue
Block a user