From 20a963495efeb3df19f19e3c1f15902adf823a6d Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 2 Apr 2024 14:55:37 +0200 Subject: ✨ add pagination to old imports page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/static/media/styles.css | 5 +++++ ishtar_common/templates/ishtar/import_list.html | 11 +++++++++++ ishtar_common/views.py | 14 ++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/ishtar_common/static/media/styles.css b/ishtar_common/static/media/styles.css index 837f5d752..20318b9bb 100644 --- a/ishtar_common/static/media/styles.css +++ b/ishtar_common/static/media/styles.css @@ -156,6 +156,11 @@ table.dataTable tbody th, table.dataTable tbody td { background: none; border: 1px solid transparent; } + +.dataTables_wrapper .dataTables_paginate .paginate_button.disabled .page-link { + background-color: #dee2e6; +} + .dataTables_scrollBody:hover{ cursor: pointer; } diff --git a/ishtar_common/templates/ishtar/import_list.html b/ishtar_common/templates/ishtar/import_list.html index ec5e714de..ca3edef4b 100644 --- a/ishtar_common/templates/ishtar/import_list.html +++ b/ishtar_common/templates/ishtar/import_list.html @@ -27,6 +27,17 @@ {% trans 'import (group)' %} {% endif %} {% endif %} + +{% if current_page %} +
+
    + {% for page_n in page_range %}
  • + {{page_n}} +
  • {% endfor %} +
+
+{% endif %} +
{% include "ishtar/import_table.html" %}
diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 6a25fd904..f35881575 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1644,6 +1644,8 @@ class ImportListView(IshtarMixin, LoginRequiredMixin, ListView): model = models.Import page_name = _("Current imports") current_url = "current_imports" + pagination = False + page_step = 20 def _queryset_filter(self, query): return query.exclude(state="AC") @@ -1668,6 +1670,14 @@ class ImportListView(IshtarMixin, LoginRequiredMixin, ListView): ) imprt.action_list = imprt.get_actions(can_edit=can_edit, can_delete=can_delete) imports.append(imprt) + self.imports_len = len(imports) + self.current_page = 0 + if self.imports_len > self.page_step and self.pagination: + self.current_page = int(self.request.GET.get("page", 1)) + self.page_number = int((self.imports_len - 1) / self.page_step) + 1 + min_page = (self.current_page - 1) * self.page_step + max_page = (self.current_page * self.page_step) + imports = imports[min_page:max_page] return imports def post(self, request, *args, **kwargs): @@ -1743,6 +1753,9 @@ class ImportListView(IshtarMixin, LoginRequiredMixin, ListView): def get_context_data(self, **kwargs): dct = super().get_context_data(**kwargs) + if self.imports_len > self.page_step and self.pagination: + dct["current_page"] = self.current_page + dct["page_range"] = (n + 1 for n in range(self.page_number)) add_import_perm = self.request.user.ishtaruser.has_right("add_import", session=self.request.session) import_type_table = models.ImporterType.objects.filter(available=True, is_import=True, type='tab') import_type_gis = models.ImporterType.objects.filter(available=True, is_import=True, type='gis') @@ -2173,6 +2186,7 @@ class ImportListTableView(ImportListView): class ImportOldListView(ImportListView): page_name = _("Old imports") current_url = "old_imports" + pagination = True def _queryset_filter(self, query): return query.filter(state="AC") -- cgit v1.2.3