From 047e495f67f93411fed2e0f12882703a11c8647c Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 2 Sep 2017 15:40:44 +0200 Subject: [PATCH] Paginator pour room --- topologie/templates/topologie/aff_chambres.html | 4 ++++ topologie/templates/topologie/index_room.html | 1 + topologie/views.py | 12 ++++++++++++ 3 files changed, 17 insertions(+) diff --git a/topologie/templates/topologie/aff_chambres.html b/topologie/templates/topologie/aff_chambres.html index 5236a301..d3393fc2 100644 --- a/topologie/templates/topologie/aff_chambres.html +++ b/topologie/templates/topologie/aff_chambres.html @@ -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 room_list.paginator %} +{% include "pagination.html" with list=room_list %} +{% endif %} + diff --git a/topologie/templates/topologie/index_room.html b/topologie/templates/topologie/index_room.html index e17a77c1..bff4b1c2 100644 --- a/topologie/templates/topologie/index_room.html +++ b/topologie/templates/topologie/index_room.html @@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

Chambres

{% if is_infra %} Ajouter une chambre +
{% endif %} {% include "topologie/aff_chambres.html" with room_list=room_list %}
diff --git a/topologie/views.py b/topologie/views.py index d9bd849f..974ca511 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -105,6 +105,18 @@ def index_port(request, switch_id): @permission_required('cableur') def index_room(request): room_list = Room.objects.order_by('name') + options, created = GeneralOption.objects.get_or_create() + pagination_number = options.pagination_number + paginator = Paginator(room_list, pagination_number) + page = request.GET.get('page') + try: + room_list = paginator.page(page) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + room_list = paginator.page(1) + except EmptyPage: + # If page is out of range (e.g. 9999), deliver last page of results. + room_list = paginator.page(paginator.num_pages) return render(request, 'topologie/index_room.html', {'room_list': room_list}) @login_required