Amélioration de l'outil de navigation
This commit is contained in:
parent
9c6fa7d5ce
commit
371e6cc9a1
@ -39,21 +39,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<footer>
|
<footer>
|
||||||
<span>
|
{% include 'agenda_culturel/paginator_filter.html' %}
|
||||||
{% if paginator_filter.has_previous %}
|
|
||||||
<a href="?page=1" role="button">« 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 »</a>
|
|
||||||
{% endif %}
|
|
||||||
</span>
|
|
||||||
</footer>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
@ -25,21 +25,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<footer>
|
<footer>
|
||||||
<span>
|
{% include 'agenda_culturel/paginator_filter.html' %}
|
||||||
{% if paginator_filter.has_previous %}
|
|
||||||
<a href="?page=1" role="button">« 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 »</a>
|
|
||||||
{% endif %}
|
|
||||||
</span>
|
|
||||||
</footer>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
@ -37,25 +37,9 @@
|
|||||||
</article>
|
</article>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% if paginator_filter.paginator.num_pages != 1 %}
|
|
||||||
<footer>
|
<footer>
|
||||||
<span>
|
{% include 'agenda_culturel/paginator_filter.html' %}
|
||||||
{% if paginator_filter.has_previous %}
|
|
||||||
<a href="?page=1" role="button">« 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 »</a>
|
|
||||||
{% endif %}
|
|
||||||
</span>
|
|
||||||
</footer>
|
</footer>
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</article>
|
</article>
|
||||||
|
@ -71,11 +71,50 @@ from .celery import (
|
|||||||
run_all_recurrent_imports,
|
run_all_recurrent_imports,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
import urllib
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
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
|
# Useful for translation
|
||||||
@ -701,7 +740,7 @@ def moderation(request):
|
|||||||
filter = EventFilterAdmin(
|
filter = EventFilterAdmin(
|
||||||
request.GET, queryset=Event.objects.all().order_by("-created_date")
|
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")
|
page = request.GET.get("page")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -724,7 +763,7 @@ def contactmessages(request):
|
|||||||
filter = ContactMessagesFilterAdmin(
|
filter = ContactMessagesFilterAdmin(
|
||||||
request.GET, queryset=ContactMessage.objects.all().order_by("-date")
|
request.GET, queryset=ContactMessage.objects.all().order_by("-date")
|
||||||
)
|
)
|
||||||
paginator = Paginator(filter.qs, 10)
|
paginator = PaginatorFilter(filter, 10, request)
|
||||||
page = request.GET.get("page")
|
page = request.GET.get("page")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -849,7 +888,7 @@ def event_search(request, full=False):
|
|||||||
request=request,
|
request=request,
|
||||||
)
|
)
|
||||||
|
|
||||||
paginator = Paginator(filter.qs, 10)
|
paginator = PaginatorFilter(filter, 10, request)
|
||||||
page = request.GET.get("page")
|
page = request.GET.get("page")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user