This repository has been archived by the owner on Oct 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #366 from aldryn/feature/pagination-improvements
Adjust pagination in templates to show not more than 10 pages
- Loading branch information
Showing
3 changed files
with
81 additions
and
52 deletions.
There are no files selected for viewing
66 changes: 40 additions & 26 deletions
66
aldryn_newsblog/boilerplates/bootstrap3/templates/aldryn_newsblog/includes/pagination.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,47 @@ | ||
{% load i18n %} | ||
|
||
<ul class="pagination"> | ||
{% if page_obj.has_previous %} | ||
<li> | ||
<a href="{{ request.path }}?page={{ page_obj.previous_page_number }}" aria-label="{% trans "Previous" %}"> | ||
<span aria-hidden="true">«</span> | ||
</a> | ||
</li> | ||
{% endif %} | ||
{% if is_paginated %} | ||
<ul> | ||
{% if page_obj.has_previous %} | ||
<li> | ||
<a href="?page={{ page_obj.previous_page_number }}" aria-label="{% trans "Previous" %}> | ||
<span aria-hidden="true">«</span> | ||
</a> | ||
</li> | ||
{% endif %} | ||
|
||
{% for num in page_obj.paginator.page_range %} | ||
{% if num %} | ||
{% if page_obj.number == num %} | ||
<li class="active"><span>{{ num }}</span></li> | ||
{% else %} | ||
<li><a href="{{ request.path }}?page={{ num }}">{{ num }}</a></li> | ||
{% if paginator.num_pages > 10 %} | ||
{% if page_obj.number > 5 %} | ||
<li><a href="?page={{ page_obj.number|add:-5 }}">...</a></li> | ||
{% endif %} | ||
|
||
{% for num in paginator.page_range %} | ||
{% if num == page_obj.number %} | ||
<li class="active"><span>{{ num }}</span></li> | ||
{% elif num > page_obj.number|add:-5 and num < page_obj.number|add:5 %} | ||
<li><a href="?page={{ num }}">{{ num }}</a></li> | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% if page_obj.number < paginator.num_pages|add:-4 %} | ||
<li><a href="?page={{ page_obj.number|add:5 }}">...</a></li> | ||
{% endif %} | ||
{% else %} | ||
<li><span><a href="{{ request.path }}?page={{ num|add:"5" }}">...</a></span></li> | ||
{% for num in page_obj.paginator.page_range %} | ||
{% if num == page_obj.number %} | ||
<li class="active"><span>{{ num }}</span></li> | ||
{% else %} | ||
<li><a href="?page={{ num }}">{{ num }}</a></li> | ||
{% endif %} | ||
{% endfor %} | ||
{% endif %} | ||
{% empty %} | ||
<li class="active"><span>1</span></li> | ||
{% endfor %} | ||
|
||
{% if page_obj.has_next %} | ||
<li> | ||
<a href="{{ request.path }}?page={{ page_obj.next_page_number }}" aria-label="{% trans "Next" %}"> | ||
<span aria-hidden="true">»</span> | ||
</a> | ||
</li> | ||
{% endif %} | ||
</ul> | ||
{% if page_obj.has_next %} | ||
<li> | ||
<a href="?page={{ page_obj.next_page_number }}" aria-label="{% trans "Next" %}> | ||
<span aria-hidden="true">»</span> | ||
</a> | ||
</li> | ||
{% endif %} | ||
</ul> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,5 @@ | |
</div> | ||
</div> | ||
</div> | ||
{% block newsblog_footer %}{% endblock %} | ||
{% endblock content %} |
66 changes: 40 additions & 26 deletions
66
aldryn_newsblog/templates/aldryn_newsblog/includes/pagination.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,47 @@ | ||
{% load i18n %} | ||
|
||
<ul> | ||
{% if page_obj.has_previous %} | ||
<li> | ||
<a href="{{ request.path }}?page={{ page_obj.previous_page_number }}"> | ||
{% trans "Previous" %} | ||
</a> | ||
</li> | ||
{% endif %} | ||
{% if is_paginated %} | ||
<ul> | ||
{% if page_obj.has_previous %} | ||
<li> | ||
<a href="?page={{ page_obj.previous_page_number }}"> | ||
{% trans "Previous" %} | ||
</a> | ||
</li> | ||
{% endif %} | ||
|
||
{% for num in page_obj.paginator.page_range %} | ||
{% if num %} | ||
{% if page_obj.number == num %} | ||
<li class="active"><span>{{ num }}</span></li> | ||
{% else %} | ||
<li><a href="{{ request.path }}?page={{ num }}">{{ num }}</a></li> | ||
{% if paginator.num_pages > 10 %} | ||
{% if page_obj.number > 5 %} | ||
<li><a href="?page={{ page_obj.number|add:-5 }}">...</a></li> | ||
{% endif %} | ||
|
||
{% for num in paginator.page_range %} | ||
{% if num == page_obj.number %} | ||
<li class="active"><span>{{ num }}</span></li> | ||
{% elif num > page_obj.number|add:-5 and num < page_obj.number|add:5 %} | ||
<li><a href="?page={{ num }}">{{ num }}</a></li> | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% if page_obj.number < paginator.num_pages|add:-4 %} | ||
<li><a href="?page={{ page_obj.number|add:5 }}">...</a></li> | ||
{% endif %} | ||
{% else %} | ||
<li><a href="{{ request.path }}?page={{ num|add:"5" }}">...</a></li> | ||
{% for num in page_obj.paginator.page_range %} | ||
{% if num == page_obj.number %} | ||
<li class="active"><span>{{ num }}</span></li> | ||
{% else %} | ||
<li><a href="?page={{ num }}">{{ num }}</a></li> | ||
{% endif %} | ||
{% endfor %} | ||
{% endif %} | ||
{% empty %} | ||
<li class="active"><span>1</span></li> | ||
{% endfor %} | ||
|
||
{% if page_obj.has_next %} | ||
<li> | ||
<a href="{{ request.path }}?page={{ page_obj.next_page_number }}"> | ||
{% trans "Next" %} | ||
</a> | ||
</li> | ||
{% endif %} | ||
</ul> | ||
{% if page_obj.has_next %} | ||
<li> | ||
<a href="?page={{ page_obj.next_page_number }}"> | ||
{% trans "Next" %} | ||
</a> | ||
</li> | ||
{% endif %} | ||
</ul> | ||
{% endif %} |