1 Commits

Author SHA1 Message Date
imperosol
0f00c91b59 push url on club search form submit 2026-03-30 19:39:13 +02:00
3 changed files with 58 additions and 59 deletions

View File

@@ -22,10 +22,15 @@
{% from "core/macros.jinja" import paginate_htmx %} {% from "core/macros.jinja" import paginate_htmx %}
{% block content %} {% block content %}
{% if not is_fragment %}
<main> <main>
<h3>{% trans %}Filters{% endtrans %}</h3> <h3>{% trans %}Filters{% endtrans %}</h3>
<form> <form
id="club-list-filters"
hx-get="{{ url("club:club_list") }}"
hx-target="#content"
hx-swap="outerHtml"
hx-push-url="true"
>
<div class="row gap-4x"> <div class="row gap-4x">
{{ form }} {{ form }}
</div> </div>
@@ -40,8 +45,6 @@
<i class="fa fa-plus"></i> {% trans %}New club{% endtrans %} <i class="fa fa-plus"></i> {% trans %}New club{% endtrans %}
</a> </a>
{% endif %} {% endif %}
<div id="paginated">
{% endif %}
<section class="aria-busy-grow" id="club-list"> <section class="aria-busy-grow" id="club-list">
{% for club in object_list %} {% for club in object_list %}
<div class="card"> <div class="card">
@@ -63,14 +66,11 @@
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
{% if is_paginated %}
{{ paginate_htmx(request, page_obj, paginator, htmx_target="#paginated") }}
{% endif %}
</section> </section>
{% if not is_fragment %} {% if is_paginated %}
</div> {{ paginate_htmx(request, page_obj, paginator) }}
</main>
{% endif %} {% endif %}
</main>
{% endblock %} {% endblock %}

View File

@@ -206,7 +206,7 @@ class ClubListView(AllowFragment, FormMixin, ListView):
template_name = "club/club_list.jinja" template_name = "club/club_list.jinja"
form_class = ClubSearchForm form_class = ClubSearchForm
queryset = Club.objects.order_by("name") queryset = Club.objects.order_by("name")
paginate_by = 1 paginate_by = 20
def get_form_kwargs(self): def get_form_kwargs(self):
res = super().get_form_kwargs() res = super().get_form_kwargs()

View File

@@ -129,10 +129,10 @@
current_page (django.core.paginator.Page): the current page object current_page (django.core.paginator.Page): the current page object
paginator (django.core.paginator.Paginator): the paginator object paginator (django.core.paginator.Paginator): the paginator object
#} #}
{{ paginate_server_side(request, current_page, paginator, "") }} {{ paginate_server_side(request, current_page, paginator, False) }}
{% endmacro %} {% endmacro %}
{% macro paginate_htmx(request, current_page, paginator, htmx_target="#content") %} {% macro paginate_htmx(request, current_page, paginator) %}
{# Add pagination buttons for pages without Alpine but supporting fragments. {# Add pagination buttons for pages without Alpine but supporting fragments.
This must be coupled with a view that handles pagination This must be coupled with a view that handles pagination
@@ -144,19 +144,18 @@
request (django.http.request.HttpRequest): the current django request request (django.http.request.HttpRequest): the current django request
current_page (django.core.paginator.Page): the current page object current_page (django.core.paginator.Page): the current page object
paginator (django.core.paginator.Paginator): the paginator object paginator (django.core.paginator.Paginator): the paginator object
htmx_target (string): htmx target selector (default '#content')
#} #}
{{ paginate_server_side(request, current_page, paginator, htmx_target) }} {{ paginate_server_side(request, current_page, paginator, True) }}
{% endmacro %} {% endmacro %}
{% macro paginate_server_side(request, current_page, paginator, htmx_target) %} {% macro paginate_server_side(request, current_page, paginator, use_htmx) %}
<nav class="pagination"> <nav class="pagination">
{% if current_page.has_previous() %} {% if current_page.has_previous() %}
<a <a
{% if htmx_target -%} {% if use_htmx -%}
hx-get="?{{ querystring(request, page=current_page.previous_page_number()) }}" hx-get="?{{ querystring(request, page=current_page.previous_page_number()) }}"
hx-swap="innerHTML" hx-swap="innerHTML"
hx-target="{{ htmx_target }}" hx-target="#content"
hx-push-url="true" hx-push-url="true"
hx-trigger="click, keyup[key=='ArrowLeft'] from:body" hx-trigger="click, keyup[key=='ArrowLeft'] from:body"
{%- else -%} {%- else -%}
@@ -177,10 +176,10 @@
<strong>{{ paginator.ELLIPSIS }}</strong> <strong>{{ paginator.ELLIPSIS }}</strong>
{% else %} {% else %}
<a <a
{% if htmx_target -%} {% if use_htmx -%}
hx-get="?{{ querystring(request, page=i) }}" hx-get="?{{ querystring(request, page=i) }}"
hx-swap="innerHTML" hx-swap="innerHTML"
hx-target="{{ htmx_target }}" hx-target="#content"
hx-push-url="true" hx-push-url="true"
{%- else -%} {%- else -%}
href="?{{ querystring(request, page=i) }}" href="?{{ querystring(request, page=i) }}"
@@ -192,10 +191,10 @@
{% endfor %} {% endfor %}
{% if current_page.has_next() %} {% if current_page.has_next() %}
<a <a
{% if htmx_target -%} {% if use_htmx -%}
hx-get="?{{querystring(request, page=current_page.next_page_number())}}" hx-get="?{{querystring(request, page=current_page.next_page_number())}}"
hx-swap="innerHTML" hx-swap="innerHTML"
hx-target="{{ htmx_target }}" hx-target="#content"
hx-push-url="true" hx-push-url="true"
hx-trigger="click, keyup[key=='ArrowRight'] from:body" hx-trigger="click, keyup[key=='ArrowRight'] from:body"
{%- else -%} {%- else -%}