Skip to content

Commit

Permalink
Keep query params on pagination next.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Apr 6, 2024
1 parent 1f6c02a commit af891db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
10 changes: 10 additions & 0 deletions gameserver/templatetags/search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re

from django import template
from django.http import QueryDict
from django.shortcuts import resolve_url

register = template.Library()
Expand All @@ -17,3 +18,12 @@ def get_search_page(request):
elif match := re.fullmatch(r"^/contest/([^/]+)/scoreboard$", request.path):
return resolve_url("contest_scoreboard", slug=match.group(1))
return


@register.filter
def format_GET(GET: QueryDict):
GET = GET.copy()
GET.pop("page", None)
if GET.get("nfts", None) == "":
del GET["nfts"]
return GET.urlencode()
20 changes: 14 additions & 6 deletions templates/paginator/snippet.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{% load search %}
<!--@formatter:off-->

{% if page_obj.paginator %}
<nav>
<ul class="pagination pagination-sm justify-content-center">
{% if page_obj.has_previous %}
<li class="page-item">
<a class="page-link pag-item" href="?page=1">&laquo;</a>
<a class="page-link pag-item" href="?page={{ page_obj.previous_page_number }}">&lt;</a>
<a class="page-link pag-item"
href="?page=1{% if request.GET %}&{{ request.GET.urlencode }}{% endif %}">&laquo;</a>
<a class="page-link pag-item" href="?page={{ page_obj.previous_page_number }}{% if request.GET %}&{{ request.GET|format_GET }}{% endif %}">&lt;</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link pag-item" aria-disabled="true" href="#">&laquo;</a>
<a class="page-link pag-item" aria-disabled="true" href="#">&lt;</a></li>
<a class="page-link pag-item" aria-disabled="true" href="#">&lt;</a>
</li>
{% endif %}
<li class="page-item disabled">
<a class="page-link" href="#" aria-disabled="true">
Expand All @@ -18,14 +23,17 @@
</li>
{% if page_obj.has_next %}
<li class="page-item">
<a class="page-link pag-item" href="?page={{ page_obj.next_page_number }}">&gt;</a>
<a class="page-link pag-item" href="?page={{ page_obj.paginator.num_pages }}">&raquo;</a>
<a class="page-link pag-item" href="?page={{ page_obj.next_page_number }}{% if request.GET %}&{{ request.GET|format_GET }}{% endif %}">&gt;</a>
<a class="page-link pag-item" href="?page={{ page_obj.paginator.num_pages }}{% if request.GET %}&{{ request.GET|format_GET }}{% endif %}">&raquo;</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link pag-item" aria-disabled="true" href="#">&gt;</a>
<a class="page-link pag-item" aria-disabled="true" href="#">&raquo;</a></li>
<a class="page-link pag-item" aria-disabled="true" href="#">&raquo;</a>
</li>
{% endif %}
</ul>
</nav>
{% endif %}

<!--@formatter:on-->

0 comments on commit af891db

Please sign in to comment.