From 5575995437ef37d1ad3be7b889c272213e5421e8 Mon Sep 17 00:00:00 2001 From: grisel-davy Date: Thu, 3 May 2018 13:45:13 +0200 Subject: [PATCH] Fixe #111: Supression du paginateur si page unique --- re2o/utils.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/re2o/utils.py b/re2o/utils.py index 5a4f9400..639d6a07 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -297,16 +297,20 @@ def re2o_paginator(request, query_set, pagination_number): :request: :query_set: Query_set to paginate :pagination_number: Number of entries to display""" - paginator = Paginator(query_set, pagination_number) - page = request.GET.get('page') - try: - results = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - results = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - results = paginator.page(paginator.num_pages) + if query_set.count() > pagination_number: + paginator = Paginator(query_set, pagination_number) + page = request.GET.get('page') + try: + results = paginator.page(page) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + results = paginator.page(1) + except EmptyPage: + # If page is out of range (e.g. 9999), deliver last page of results. + results = paginator.page(paginator.num_pages) + else: + #If there is only one page, deliver the page without paginator + return query_set return results