templates: provide more consistent use of ellipses in pagination (#59773)

This commit is contained in:
Paul Marillonnet 2021-12-16 12:04:38 +01:00
parent f98dfe10da
commit a3124c9c75
1 changed files with 18 additions and 3 deletions

View File

@ -14,10 +14,15 @@ Expected context variables:
{% with page_key=page_key|default:"page" %}
{% spaceless %}
<p class="paginator">
{% if page_obj.number > 1 %}
{% if page_obj.previous_page_number != 1 %}
{% if page_obj.number > 4 %}
<a href="{% querystring page_key=1 without without_key %}{{ anchor }}">1</a>
{% else %}
{% if page_obj.number >= 3 %}
<a href="{% querystring page_key=1 without without_key %}{{ anchor }}">1</a>
{% if page_obj.number == 4 %}
<a href="{% querystring page_key=2 without without_key %}{{ anchor }}">2</a>
{% endif %}
{% endif %}
{% endif %}
@ -30,11 +35,21 @@ Expected context variables:
{% if page_obj.has_next %}
<a href="{% querystring page_key=page_obj.next_page_number without without_key %}{{ anchor }}">{{ page_obj.next_page_number }}</a>
{% endif %}
{% if page_obj.number != page_obj.paginator.num_pages %}
{% if page_obj.number < page_obj.paginator.num_pages|add:"-3" %}
{% if page_obj.next_page_number != page_obj.paginator.num_pages %}
<a href="{% querystring page_key=page_obj.paginator.num_pages without without_key %}{{ anchor }}">{{ page_obj.paginator.num_pages }}</a>
{% endif %}
{% else %}
{% if page_obj.number <= page_obj.paginator.num_pages|add:"-2" %}
{% if page_obj.number == page_obj.paginator.num_pages|add:"-3" %}
{% with a_page_key=page_obj.paginator.num_pages|add:"-1" %}
<a href="{% querystring page_key=a_page_key without without_key %}{{ anchor }}">{{ a_page_key }}</a>
{% endwith %}
{% endif %}
<a href="{% querystring page_key=page_obj.paginator.num_pages without without_key %}{{ anchor }}">{{ page_obj.paginator.num_pages }}</a>
{% endif %}
{% endif %}
</p>
{% endspaceless %}