Add (simple) Bootstrap 4 paginator helper tag.
This commit is contained in:
parent
b65df95138
commit
d88c4632cd
2 changed files with 57 additions and 0 deletions
49
drakul/base/templates/bootstrap_paginator.html
Normal file
49
drakul/base/templates/bootstrap_paginator.html
Normal file
|
@ -0,0 +1,49 @@
|
|||
{% load base_extras %}
|
||||
|
||||
|
||||
{% if is_paginated %}
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination">
|
||||
{% if page_obj.has_previous %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?page={{ page_obj.previous_page_number }}" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
<span class="page-link">«</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% paginator_pages paginator.page_range page_obj.number as pages %}
|
||||
{% for i in pages %}
|
||||
{% if page_obj.number == i %}
|
||||
<li class="page-item active" aria-current="page">
|
||||
<span class="page-link">
|
||||
{{ i }}
|
||||
<span class="sr-only">(current)</span>
|
||||
</span>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?page={{ i }}">{{ i }}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if page_obj.has_next %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?page={{ page_obj.next_page_number }}" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
<span class="page-link">»</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
|
@ -8,3 +8,11 @@ def active(context, url_name):
|
|||
if context["request"].resolver_match.url_name == url_name:
|
||||
return "active"
|
||||
return ""
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def paginator_pages(page_range: range, current_number: int, margin=5):
|
||||
return range(
|
||||
max(page_range.start, current_number - margin),
|
||||
min(page_range.stop, current_number + margin + 1)
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue