|
2 | 2 | {% load i18n %} |
3 | 3 |
|
4 | 4 | {% 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"> |
7 | 7 | {# Use page_key (defaulting to 'page' if not provided) #} |
8 | 8 | {% with current_page_key=page_key|default:'page' %} |
| 9 | + {% comment %} Previous Page Link {% endcomment %} |
9 | 10 | {% 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 != '_' %}&{{ key }}={{ value }}{% endif %}{% endfor %}">« {% 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 != '_' %}&{{ key }}={{ value }}{% endif %}{% endfor %}" aria-label="{% trans 'Previous' %}"> |
| 13 | + <span aria-hidden="true">«</span> |
| 14 | + <span class="visually-hidden">{% trans 'Previous' %}</span> |
| 15 | + </a> |
| 16 | + </li> |
11 | 17 | {% else %} |
12 | | - <li class="disabled"><span>« {% trans 'previous' %}</span></li> |
| 18 | + <li class="page-item disabled"> |
| 19 | + <span class="page-link" aria-hidden="true">«</span> |
| 20 | + <span class="visually-hidden">{% trans 'Previous' %}</span> |
| 21 | + </li> |
13 | 22 | {% endif %} |
14 | 23 |
|
| 24 | + {% comment %} Page Number Links {% endcomment %} |
15 | 25 | {% for i in objects.paginator.page_range %} |
16 | 26 | {% 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> |
18 | 28 | {% 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 != '_' %}&{{ 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 != '_' %}&{{ key }}={{ value }}{% endif %}{% endfor %}">{{ i }}</a></li> |
20 | 30 | {% 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 != '_' %}&{{ 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 != '_' %}&{{ 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 != '_' %}&{{ 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 != '_' %}&{{ 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 != '_' %}&{{ key }}={{ value }}{% endif %}{% endfor %}">{{ i }}</a></li> |
| 44 | + {% endif %} |
25 | 45 | {% endif %} |
26 | 46 | {% endfor %} |
27 | 47 |
|
| 48 | + {% comment %} Next Page Link {% endcomment %} |
28 | 49 | {% 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 != '_' %}&{{ key }}={{ value }}{% endif %}{% endfor %}">{% trans 'next' %} »</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 != '_' %}&{{ key }}={{ value }}{% endif %}{% endfor %}" aria-label="{% trans 'Next' %}"> |
| 52 | + <span aria-hidden="true">»</span> |
| 53 | + <span class="visually-hidden">{% trans 'Next' %}</span> |
| 54 | + </a> |
| 55 | + </li> |
30 | 56 | {% else %} |
31 | | - <li class="disabled"><span>{% trans 'next' %} »</span></li> |
| 57 | + <li class="page-item disabled"> |
| 58 | + <span class="page-link" aria-hidden="true">»</span> |
| 59 | + <span class="visually-hidden">{% trans 'Next' %}</span> |
| 60 | + </li> |
32 | 61 | {% endif %} |
33 | 62 | {% endwith %} |
34 | 63 | </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"> |
36 | 69 | {% blocktrans with number=objects.number num_pages=objects.paginator.num_pages %} |
37 | 70 | Page {{ number }} of {{ num_pages }}. |
38 | 71 | {% endblocktrans %} |
|
0 commit comments