summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ishtar_common/templates/ishtar/blocks/pagination.html5
-rw-r--r--ishtar_common/templates/ishtar/import_list.html8
-rw-r--r--ishtar_common/views.py37
3 files changed, 44 insertions, 6 deletions
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 @@
+<ul>
+ {% for page_n in page_range %}<li class="paginate_button page-item{% if page_n == '...' %} disabled{% endif %}{% if current_page == page_n %} active{% endif %}">
+ <a href="{% if page_n == '...' %}#{% else %}?page={{page_n}}{% endif %}" tabindex="0" class="page-link">{{page_n}}</a>
+ </li>{% endfor %}
+</ul>
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 %}
<div class='dataTables_wrapper'>
- <div class='dataTables_paginate'><ul>
- {% for page_n in page_range %}<li class="paginate_button page-item{% if page_n == '...' or page_n == current_page %} disabled{% endif %}">
- <a href="{% if page_n == '...' or page_n == current_page %}#{% else %}?page={{page_n}}{% endif %}" tabindex="0" class="page-link">{{page_n}}</a>
- </li>{% endfor %}
- </ul></div>
+ <div class='dataTables_paginate'>
+ {% include "ishtar/blocks/pagination.html" %}
+ </div>
</div>
{% endif %}
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 71076e52d..4a487ab90 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -1897,11 +1897,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_permission(
"ishtar_common.add_import"
)