Skip to content

Commit e38e029

Browse files
committed
Improve pagination style and set default page size to 10 records
1 parent d45f409 commit e38e029

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

tally_ho/apps/tally/templates/includes/pagination.html

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,70 @@
22
{% load i18n %}
33

44
{% if objects.has_other_pages %}
5-
<div class="pagination pagination-centered">
6-
<ul class="step-links">
5+
<nav aria-label="Page navigation">
6+
<ul class="pagination justify-content-center">
77
{# Use page_key (defaulting to 'page' if not provided) #}
88
{% with current_page_key=page_key|default:'page' %}
9+
{% comment %} Previous Page Link {% endcomment %}
910
{% if objects.has_previous %}
10-
<li><a href="?{{ current_page_key }}={{ objects.previous_page_number }}{% for key, value in request.GET.items %}{% if key != current_page_key and key != '_' %}&amp;{{ key }}={{ value }}{% endif %}{% endfor %}">&laquo; {% trans 'previous' %}</a></li>
11+
<li class="page-item">
12+
<a class="page-link" href="?{{ current_page_key }}={{ objects.previous_page_number }}{% for key, value in request.GET.items %}{% if key != current_page_key and key != '_' %}&amp;{{ key }}={{ value }}{% endif %}{% endfor %}" aria-label="{% trans 'Previous' %}">
13+
<span aria-hidden="true">&laquo;</span>
14+
<span class="visually-hidden">{% trans 'Previous' %}</span>
15+
</a>
16+
</li>
1117
{% else %}
12-
<li class="disabled"><span>&laquo; {% trans 'previous' %}</span></li>
18+
<li class="page-item disabled">
19+
<span class="page-link" aria-hidden="true">&laquo;</span>
20+
<span class="visually-hidden">{% trans 'Previous' %}</span>
21+
</li>
1322
{% endif %}
1423

24+
{% comment %} Page Number Links {% endcomment %}
1525
{% for i in objects.paginator.page_range %}
1626
{% if objects.number == i %}
17-
<li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
27+
<li class="page-item active" aria-current="page"><span class="page-link">{{ i }}</span></li>
1828
{% elif i > objects.number|add:'-3' and i < objects.number|add:'3' %}
19-
<li><a href="?{{ current_page_key }}={{ i }}{% for key, value in request.GET.items %}{% if key != current_page_key and key != '_' %}&amp;{{ key }}={{ value }}{% endif %}{% endfor %}">{{ i }}</a></li>
29+
<li class="page-item"><a class="page-link" href="?{{ current_page_key }}={{ i }}{% for key, value in request.GET.items %}{% if key != current_page_key and key != '_' %}&amp;{{ key }}={{ value }}{% endif %}{% endfor %}">{{ i }}</a></li>
2030
{% elif i == 1 or i == objects.paginator.num_pages %}
21-
{# Always show first and last page #}
22-
{% if i == 1 and objects.number > 3 %}<li><span>...</span></li>{% endif %}
23-
<li><a href="?{{ current_page_key }}={{ i }}{% for key, value in request.GET.items %}{% if key != current_page_key and key != '_' %}&amp;{{ key }}={{ value }}{% endif %}{% endfor %}">{{ i }}</a></li>
24-
{% if i == objects.paginator.num_pages and objects.number < objects.paginator.num_pages|add:'-2' %}<li><span>...</span></li>{% endif %}
31+
{# Always show first and last page, add ellipsis if needed #}
32+
{% if i == 1 and objects.number > 4 %}
33+
<li class="page-item"><a class="page-link" href="?{{ current_page_key }}=1{% for key, value in request.GET.items %}{% if key != current_page_key and key != '_' %}&amp;{{ key }}={{ value }}{% endif %}{% endfor %}">1</a></li>
34+
<li class="page-item disabled"><span class="page-link">...</span></li>
35+
{% elif i == objects.paginator.num_pages and objects.number < objects.paginator.num_pages|add:'-3' %}
36+
<li class="page-item disabled"><span class="page-link">...</span></li>
37+
<li class="page-item"><a class="page-link" href="?{{ current_page_key }}={{ i }}{% for key, value in request.GET.items %}{% if key != current_page_key and key != '_' %}&amp;{{ key }}={{ value }}{% endif %}{% endfor %}">{{ i }}</a></li>
38+
{% elif i == 1 %}
39+
{# Show first page if it's within the nearby range but wasn't caught by the main elif #}
40+
<li class="page-item"><a class="page-link" href="?{{ current_page_key }}={{ i }}{% for key, value in request.GET.items %}{% if key != current_page_key and key != '_' %}&amp;{{ key }}={{ value }}{% endif %}{% endfor %}">{{ i }}</a></li>
41+
{% elif i == objects.paginator.num_pages %}
42+
{# Show last page if it's within the nearby range but wasn't caught by the main elif #}
43+
<li class="page-item"><a class="page-link" href="?{{ current_page_key }}={{ i }}{% for key, value in request.GET.items %}{% if key != current_page_key and key != '_' %}&amp;{{ key }}={{ value }}{% endif %}{% endfor %}">{{ i }}</a></li>
44+
{% endif %}
2545
{% endif %}
2646
{% endfor %}
2747

48+
{% comment %} Next Page Link {% endcomment %}
2849
{% if objects.has_next %}
29-
<li><a href="?{{ current_page_key }}={{ objects.next_page_number }}{% for key, value in request.GET.items %}{% if key != current_page_key and key != '_' %}&amp;{{ key }}={{ value }}{% endif %}{% endfor %}">{% trans 'next' %} &raquo;</a></li>
50+
<li class="page-item">
51+
<a class="page-link" href="?{{ current_page_key }}={{ objects.next_page_number }}{% for key, value in request.GET.items %}{% if key != current_page_key and key != '_' %}&amp;{{ key }}={{ value }}{% endif %}{% endfor %}" aria-label="{% trans 'Next' %}">
52+
<span aria-hidden="true">&raquo;</span>
53+
<span class="visually-hidden">{% trans 'Next' %}</span>
54+
</a>
55+
</li>
3056
{% else %}
31-
<li class="disabled"><span>{% trans 'next' %} &raquo;</span></li>
57+
<li class="page-item disabled">
58+
<span class="page-link" aria-hidden="true">&raquo;</span>
59+
<span class="visually-hidden">{% trans 'Next' %}</span>
60+
</li>
3261
{% endif %}
3362
{% endwith %}
3463
</ul>
35-
<span class="current page-info">
64+
</nav>
65+
66+
{# Optional: Keep the page info text, maybe style it with Bootstrap utilities #}
67+
<div class="text-center mt-2">
68+
<span class="text-muted page-info">
3669
{% blocktrans with number=objects.number num_pages=objects.paginator.num_pages %}
3770
Page {{ number }} of {{ num_pages }}.
3871
{% endblocktrans %}

tally_ho/libs/views/pagination.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def paging(objects_list, request, page_kwarg='page'):
1010
1111
:returns: A page for this list and request.
1212
"""
13-
paginator = Paginator(objects_list, 100)
13+
paginator = Paginator(objects_list, 10)
1414
page = request.GET.get(page_kwarg)
1515

1616
return paginate(paginator, page)

0 commit comments

Comments
 (0)