new file mode 100644
@@ -0,0 +1,28 @@
+from django import template
+from django.http import HttpRequest
+from django.core.paginator import Paginator
+
+register = template.Library()
+
+
+# Return new page URL for the current view.
+# Usage: {% page_url request 2 %}
+@register.simple_tag
+def page_url(request: "HttpRequest", page: int) -> "str":
+ new_query = request.GET.copy()
+ new_query['page'] = f'{page}'
+ return '?' + new_query.urlencode()
+
+
+# Return elided page range for the current page object.
+# Usage: {% page_obj|elided_page_range %}
+@register.filter
+def elided_page_range(page_obj: "Paginator.page") -> "list[int]":
+ if not isinstance(page_obj.paginator, Paginator):
+ return []
+
+ return page_obj.paginator.get_elided_page_range(
+ number=page_obj.number,
+ on_each_side=3,
+ on_ends=1,
+ )
\ No newline at end of file
@@ -90,12 +90,7 @@
<input type="submit" class="btn btn-default" name="add_all" value="Add all"></input>
{% if is_paginated %}
- {% comment %}
- {% load bootstrap_pagination %}
- <div class="text-center">
- {% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
- </div>
- {% endcomment %}
+ {% include "layerindex/paginator.html" %}
{% endif %}
{% else %}
{% if searched %}
@@ -65,12 +65,7 @@
</table>
{% if is_paginated %}
- {% comment %}
- {% load bootstrap_pagination %}
- <div class="text-center">
- {% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
- </div>
- {% endcomment %}
+ {% include "layerindex/paginator.html" %}
{% endif %}
{% else %}
{% if search_keyword %}
@@ -287,12 +287,7 @@
</table>
{% if is_paginated %}
- {% comment %}
- {% load bootstrap_pagination %}
- <div class="text-center">
- {% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
- </div>
- {% endcomment %}
+ {% include "layerindex/paginator.html" %}
{% endif %}
{% else %}
{% if searched %}
@@ -65,12 +65,7 @@
</table>
{% if is_paginated %}
- {% comment %}
- {% load bootstrap_pagination %}
- <div class="text-center">
- {% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
- </div>
- {% endcomment %}
+ {% include "layerindex/paginator.html" %}
{% endif %}
{% else %}
{% if search_keyword %}
@@ -60,12 +60,7 @@
</table>
{% if is_paginated %}
- {% comment %}
- {% load bootstrap_pagination %}
- <div class="text-center">
- {% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
- </div>
- {% endcomment %}
+ {% include "layerindex/paginator.html" %}
{% endif %}
@@ -105,12 +105,7 @@
</table>
{% if is_paginated %}
- {% comment %}
- {% load bootstrap_pagination %}
- <div class="text-center">
- {% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
- </div>
- {% endcomment %}
+ {% include "layerindex/paginator.html" %}
{% endif %}
{% else %}
<p>No matching layers in database.</p>
@@ -64,12 +64,7 @@
</table>
{% if is_paginated %}
- {% comment %}
- {% load bootstrap_pagination %}
- <div class="text-center">
- {% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
- </div>
- {% endcomment %}
+ {% include "layerindex/paginator.html" %}
{% endif %}
{% else %}
{% if search_keyword %}
new file mode 100644
@@ -0,0 +1,20 @@
+{% load paginator %}
+<nav aria-label="Pagination Navigation" class="text-center">
+ <ul class="pagination">
+ {% for i in page_obj|elided_page_range %}
+ {% if page_obj.number == i %}
+ <li class="page-item active">
+ <span aria-current="page">{{ i }}</span>
+ </li>
+ {% else %}
+ {% if i == page_obj.paginator.ELLIPSIS %}
+ <li class="pagination-ellipsis" aria-hidden="true"><span>{{ i }}</span></li>
+ {% else %}
+ <li class="page-item">
+ <a href="{% page_url request i %}" aria-label="Go to page {{ i }}">{{ i }}</a>
+ </li>
+ {% endif %}
+ {% endif %}
+ {% endfor %}
+ </ul>
+</nav>
\ No newline at end of file
@@ -90,12 +90,7 @@
</table>
{% if is_paginated %}
- {% comment %}
- {% load bootstrap_pagination %}
- <div class="text-center">
- {% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
- </div>
- {% endcomment %}
+ {% include "layerindex/paginator.html" %}
{% endif %}
{% else %}
{% if search_keyword %}
@@ -69,12 +69,7 @@
</div>
{% if is_paginated %}
- {% comment %}
- {% load bootstrap_pagination %}
- <div class="text-center">
- {% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
- </div>
- {% endcomment %}
+ {% include "layerindex/paginator.html" %}
{% endif %}
{% else %}
<p>No unpublished layers to review.</p>
@@ -54,12 +54,7 @@
</div>
{% if is_paginated %}
-{% comment %}
- {% load bootstrap_pagination %}
- <div class="text-center">
- {% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
- </div>
-{% endcomment %}
+{% include "layerindex/paginator.html" %}
{% endif %}
{% endautoescape %}
Signed-off-by: Piotr Buliński <piotr@qbee.io> --- layerindex/templatetags/paginator.py | 28 ++++++++++++++++++++++ templates/layerindex/bulkchangesearch.html | 7 +----- templates/layerindex/classes.html | 7 +----- templates/layerindex/classicrecipes.html | 7 +----- templates/layerindex/distros.html | 7 +----- templates/layerindex/history.html | 7 +----- templates/layerindex/layers.html | 7 +----- templates/layerindex/machines.html | 7 +----- templates/layerindex/paginator.html | 20 ++++++++++++++++ templates/layerindex/recipes.html | 7 +----- templates/layerindex/reviewlist.html | 7 +----- templates/layerindex/updatelist.html | 7 +----- 12 files changed, 58 insertions(+), 60 deletions(-) create mode 100644 layerindex/templatetags/paginator.py create mode 100644 templates/layerindex/paginator.html