From d77362a54e9b48cc3d78eb699514a7b520e244ad Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 28 Apr 2025 12:50:22 +0200 Subject: 🐛 old import list: fix pagination (refs #6268) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/ishtar/blocks/pagination.html | 5 +++ ishtar_common/templates/ishtar/import_list.html | 8 ++--- ishtar_common/views.py | 37 +++++++++++++++++++++- 3 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 ishtar_common/templates/ishtar/blocks/pagination.html (limited to 'ishtar_common') diff --git a/ishtar_common/templates/ishtar/blocks/pagination.html b/ishtar_common/templates/ishtar/blocks/pagination.html new file mode 100644 index 000000000..cbb77906c --- /dev/null +++ b/ishtar_common/templates/ishtar/blocks/pagination.html @@ -0,0 +1,5 @@ + diff --git a/ishtar_common/templates/ishtar/import_list.html b/ishtar_common/templates/ishtar/import_list.html index ca3edef4b..c3804d834 100644 --- a/ishtar_common/templates/ishtar/import_list.html +++ b/ishtar_common/templates/ishtar/import_list.html @@ -30,11 +30,9 @@ {% if current_page %}
-
    - {% for page_n in page_range %}
  • - {{page_n}} -
  • {% endfor %} -
+
+ {% include "ishtar/blocks/pagination.html" %} +
{% endif %} diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 7e0c01cd8..a2e6658dd 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1826,11 +1826,46 @@ class ImportListView(IshtarMixin, LoginRequiredMixin, ListView): imprt.unarchive(action) return HttpResponseRedirect(reverse(self.current_url)) + def _get_page_range(self): + page_range = [] + # same algo as ishtar_common/static/js/ishtar.js render_gallery + # TODO: harmonization... + + page_range.append(_("Previous")) + page_total = (self.imports_len // self.page_step) + 1 + page_range.append(1) + if self.current_page < 5: + for idx_page in range(2, 6): + if idx_page > page_total: + break + page_range.append(idx_page) + if page_total > 5: + page_range.append("...") + page_range.append(page_total) + else: + page_range.append("...") + if page_total > (self.current_page - 2): + page_range.append(self.current_page - 3) + if page_total > (self.current_page - 3): + page_range.append(self.current_page - 2) + page_range.append(self.current_page - 1) + page_range.append(self.current_page) + if page_total > self.current_page: + page_range.append(self.current_page + 1) + if page_total < (self.current_page + 3): + for idx_page in range(self.current_page + 2, page_total + 1): + page_range.append(idx_page) + else: + page_range.append("...") + page_range.append(page_total) + page_range.append(_("Next")) + return page_range + 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)) + dct["page_range"] = self._get_page_range() 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') -- cgit v1.2.3