Skip to content
This repository was archived by the owner on Jul 6, 2018. It is now read-only.

Allow more flexibility on how the pagination behaves #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions bootstrap_toolkit/templates/bootstrap_toolkit/pagination.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@
<div class="{{ pagination_css_classes }}">
<ul>

<li class="prev{% if current_page == 1 %} disabled{% endif %}">
<a href="{% if current_page == 1 %}#{% else %}{{ bootstrap_pagination_url }}page=1{% endif %}">&laquo;</a>
</li>
{% if show_prev_and_next %}
<li class="prev{% if current_page == 1 %} disabled{% endif %}">
<a href="{% if current_page == 1 %}#{% else %}{{ bootstrap_pagination_url }}page={{ current_page|add:'-1' }}{% endif %}">&larr;</a>
</li>
{% endif %}
{% if always_show_first %}
{% if 1 not in pages_shown %}
<li>
<a href="{{ bootstrap_pagination_url }}page=1">1</a>
</li>
{% endif %}
{% else %}
<li class="prev{% if current_page == 1 %} disabled{% endif %}">
<a href="{% if current_page == 1 %}#{% else %}{{ bootstrap_pagination_url }}page=1{% endif %}">&laquo;</a>
</li>
{% endif %}

{% if pages_back %}
<li>
Expand All @@ -25,10 +38,23 @@
</li>
{% endif %}

<li class="last{% if current_page == num_pages %} disabled{% endif %}">
<a href="{% if current_page == num_pages %}#{% else %}{{ bootstrap_pagination_url }}page={{ num_pages }}{% endif %}">&raquo;</a>
</li>
{% if always_show_last %}
{% if num_pages not in pages_shown %}
<li>
<a href="{{ bootstrap_pagination_url }}page={{ num_pages }}">{{ num_pages }}</a>
</li>
{% endif %}
{% else %}
<li class="last{% if current_page == num_pages %} disabled{% endif %}">
<a href="{% if current_page == num_pages %}#{% else %}{{ bootstrap_pagination_url }}page={{ num_pages }}{% endif %}">&raquo;</a>
</li>
{% endif %}

{% if show_prev_and_next %}
<li class="next{% if current_page == num_pages %} disabled{% endif %}">
<a href="{% if current_page == num_pages %}#{% else %}{{ bootstrap_pagination_url }}page={{ current_page|add:'1' }}{% endif %}">&rarr;</a>
</li>
{% endif %}
</ul>

</div>
Expand Down
6 changes: 5 additions & 1 deletion bootstrap_toolkit/templatetags/bootstrap_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ def bootstrap_pagination(page, **kwargs):
return get_pagination_context(**pagination_kwargs)


def get_pagination_context(page, pages_to_show=11, url=None, size=None, align=None, extra=None):
def get_pagination_context(page, pages_to_show=11, always_show_first=False, always_show_last=False,
show_prev_and_next=False, url=None, size=None, align=None, extra=None):
"""
Generate Bootstrap pagination context from a page object
"""
Expand Down Expand Up @@ -363,6 +364,9 @@ def get_pagination_context(page, pages_to_show=11, url=None, size=None, align=No
# Build context object
return {
'bootstrap_pagination_url': url,
'always_show_first': always_show_first,
'always_show_last': always_show_last,
'show_prev_and_next': show_prev_and_next,
'num_pages': num_pages,
'current_page': current_page,
'first_page': first_page,
Expand Down