8
0
Fork 0
mirror of https://gitlab.federez.net/re2o/re2o synced 2024-07-02 12:14:05 +00:00

Gentil paginateur

This commit is contained in:
Gabriel Detraz 2017-10-26 18:48:09 +02:00 committed by root
parent 315560ba5c
commit a2e03538e3
3 changed files with 17 additions and 0 deletions

View file

@ -22,6 +22,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
{% if switch_list.paginator %}
{% include "pagination.html" with list=switch_list %}
{% endif %}
<table class="table table-striped">
<thead>
<tr>

View file

@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<h2>Switchs</h2>
{% if is_infra %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:new-switch' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un switch</a>
<hr>
{% endif %}
{% include "topologie/aff_switch.html" with switch_list=switch_list %}
<br />

View file

@ -89,6 +89,18 @@ def index(request):
request.GET.get('order'),
SortTable.TOPOLOGIE_INDEX
)
options, _created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number
paginator = Paginator(switch_list, pagination_number)
page = request.GET.get('page')
try:
switch_list = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
switch_list = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
switch_list = paginator.page(paginator.num_pages)
return render(request, 'topologie/index.html', {
'switch_list': switch_list
})