8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 07:02:26 +00:00

Merge branch 'paginateur' into 'master'

Fixe #111: Supression du paginateur si page unique

See merge request federez/re2o!151
This commit is contained in:
chirac 2018-05-03 13:49:39 +02:00
commit 34d29349ed

View file

@ -340,16 +340,20 @@ def re2o_paginator(request, query_set, pagination_number):
:request: :request:
:query_set: Query_set to paginate :query_set: Query_set to paginate
:pagination_number: Number of entries to display""" :pagination_number: Number of entries to display"""
paginator = Paginator(query_set, pagination_number) if query_set.count() > pagination_number:
page = request.GET.get('page') paginator = Paginator(query_set, pagination_number)
try: page = request.GET.get('page')
results = paginator.page(page) try:
except PageNotAnInteger: results = paginator.page(page)
# If page is not an integer, deliver first page. except PageNotAnInteger:
results = paginator.page(1) # If page is not an integer, deliver first page.
except EmptyPage: results = paginator.page(1)
# If page is out of range (e.g. 9999), deliver last page of results. except EmptyPage:
results = paginator.page(paginator.num_pages) # 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 return results