Amélioration de l'outil de navigation

This commit is contained in:
Jean-Marie Favreau 2024-07-07 15:10:14 +02:00
parent 9c6fa7d5ce
commit 371e6cc9a1
4 changed files with 47 additions and 52 deletions

View File

@ -39,21 +39,7 @@
</tbody>
</table>
<footer>
<span>
{% if paginator_filter.has_previous %}
<a href="?page=1" role="button">&laquo; premier</a>
<a href="?page={{ paginator_filter.previous_page_number }}" role="button">précédent</a>
{% endif %}
<span>
Page {{ paginator_filter.number }} sur {{ paginator_filter.paginator.num_pages }}
</span>
{% if paginator_filter.has_next %}
<a href="?page={{ paginator_filter.next_page_number }}" role="button">suivant</a>
<a href="?page={{ paginator_filter.paginator.num_pages }}" role="button">dernier &raquo;</a>
{% endif %}
</span>
{% include 'agenda_culturel/paginator_filter.html' %}
</footer>
</article>

View File

@ -25,21 +25,7 @@
{% endfor %}
</div>
<footer>
<span>
{% if paginator_filter.has_previous %}
<a href="?page=1" role="button">&laquo; premier</a>
<a href="?page={{ paginator_filter.previous_page_number }}" role="button">précédent</a>
{% endif %}
<span>
Page {{ paginator_filter.number }} sur {{ paginator_filter.paginator.num_pages }}
</span>
{% if paginator_filter.has_next %}
<a href="?page={{ paginator_filter.next_page_number }}" role="button">suivant</a>
<a href="?page={{ paginator_filter.paginator.num_pages }}" role="button">dernier &raquo;</a>
{% endif %}
</span>
{% include 'agenda_culturel/paginator_filter.html' %}
</footer>
</article>

View File

@ -37,25 +37,9 @@
</article>
{% endfor %}
</div>
{% if paginator_filter.paginator.num_pages != 1 %}
<footer>
<span>
{% if paginator_filter.has_previous %}
<a href="?page=1" role="button">&laquo; premier</a>
<a href="?page={{ paginator_filter.previous_page_number }}" role="button">précédent</a>
{% endif %}
<span>
Page {{ paginator_filter.number }} sur {{ paginator_filter.paginator.num_pages }}
</span>
{% if paginator_filter.has_next %}
<a href="?page={{ paginator_filter.next_page_number }}" role="button">suivant</a>
<a href="?page={{ paginator_filter.paginator.num_pages }}" role="button">dernier &raquo;</a>
{% endif %}
</span>
</footer>
{% endif %}
<footer>
{% include 'agenda_culturel/paginator_filter.html' %}
</footer>
</div>
{% endif %}
</article>

View File

@ -71,11 +71,50 @@ from .celery import (
run_all_recurrent_imports,
)
import urllib
import logging
logger = logging.getLogger(__name__)
class PaginatorFilter(Paginator):
def __init__(self, filter, nb, request):
self.request = request
self.filter = filter
super().__init__(filter.qs, nb)
self.url_first_page = PaginatorFilter.update_param(self.request.get_full_path(), 'page', 1)
self.url_last_page = PaginatorFilter.update_param(self.request.get_full_path(), 'page', self.num_pages)
def update_param(params, key, value):
p = params.split('?')
root = p[0]
if len(p) > 1:
other = p[1]
others = other.split('&')
others = [o for o in others if not o.startswith(key)]
others += [key + '=' + str(value)]
return root + '?' + '&'.join(others)
else:
return root + '?' + key + '=' + str(value)
def page(self, *args, **kwargs):
page = super().page(*args, **kwargs)
try:
page.url_previous_page = PaginatorFilter.update_param(self.request.get_full_path(), 'page', page.previous_page_number())
except EmptyPage:
page.url_previous_page = self.request.get_full_path()
try:
page.url_next_page = PaginatorFilter.update_param(self.request.get_full_path(), 'page', page.next_page_number())
except EmptyPage:
page.url_next_page = self.request.get_full_path()
return page
#
#
# Useful for translation
@ -701,7 +740,7 @@ def moderation(request):
filter = EventFilterAdmin(
request.GET, queryset=Event.objects.all().order_by("-created_date")
)
paginator = Paginator(filter.qs, 10)
paginator = PaginatorFilter(filter, 10, request)
page = request.GET.get("page")
try:
@ -724,7 +763,7 @@ def contactmessages(request):
filter = ContactMessagesFilterAdmin(
request.GET, queryset=ContactMessage.objects.all().order_by("-date")
)
paginator = Paginator(filter.qs, 10)
paginator = PaginatorFilter(filter, 10, request)
page = request.GET.get("page")
try:
@ -849,7 +888,7 @@ def event_search(request, full=False):
request=request,
)
paginator = Paginator(filter.qs, 10)
paginator = PaginatorFilter(filter, 10, request)
page = request.GET.get("page")
try: