8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 11:53:12 +00:00

Merge branch 'Fix_111_properly' into 'master'

Fix #111 properly

Closes #111

See merge request federez/re2o!154
This commit is contained in:
chirac 2018-05-05 16:06:31 +02:00
commit 1955229842
2 changed files with 13 additions and 16 deletions

View file

@ -340,20 +340,16 @@ def re2o_paginator(request, query_set, pagination_number):
:request:
:query_set: Query_set to paginate
:pagination_number: Number of entries to display"""
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
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)
return results

View file

@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% load url_insert_param %}
{% if list.paginator.num_pages > 1 %}
<ul class="pagination nav navbar-nav">
{% if list.has_previous %}
<li><a href="{% url_insert_param request.get_full_path page=1 %}"> << </a></li>
@ -39,5 +40,5 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<li><a href="{% url_insert_param request.get_full_path page=list.next_page_number %}"> > </a></li>
<li><a href="{% url_insert_param request.get_full_path page=list.paginator.page_range|length %}"> >> </a></li>
{% endif %}
</ul>
</ul>
{% endif %}