mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-23 11:53:12 +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:
commit
34d29349ed
1 changed files with 14 additions and 10 deletions
|
@ -340,16 +340,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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue