feat: Fix pagination when searching

This commit is contained in:
2025-08-12 06:12:27 +02:00
parent 84ad047c01
commit 5d333b28ab
4 changed files with 25 additions and 9 deletions

View File

@@ -23,13 +23,12 @@
</div>
</div>
<div class="column is-one-third">
<form method="post" autocomplete="off">
{% csrf_token %}
<form method="GET" autocomplete="off">
<input type="hidden" name="longitude" maxlength="200" id="longitude">
<input type="hidden" name="latitude" maxlength="200" id="latitude">
<!--- https://docs.djangoproject.com/en/5.2/topics/forms/#reusable-form-templates -->
{{ search_form }}
<button class="button is-primary is-fullwidth" type="submit" value="search" name="search">
<button class="button is-primary is-fullwidth" type="submit" value="search" name="action">
<i class="fas fa-search fa-fw"></i> {% trans 'Suchen' %}
</button>
</form>
@@ -44,17 +43,17 @@
<nav class="pagination" role="navigation" aria-label="{% trans 'Paginierung' %}">
{% if rescue_organizations_to_list.has_previous %}
<a class="pagination-previous"
href="?page={{ rescue_organizations_to_list.previous_page_number }}">{% trans 'Vorherige' %}</a>
href="?page={% url_replace request 'page' rescue_organizations_to_list.previous_page_number %}">{% trans 'Vorherige' %}</a>
{% endif %}
{% if rescue_organizations_to_list.has_next %}
<a class="pagination-next"
href="?page={{ rescue_organizations_to_list.next_page_number }}">{% trans 'Nächste' %}</a>
href="?{% url_replace request 'page' rescue_organizations_to_list.next_page_number %}">{% trans 'Nächste' %}</a>
{% endif %}
<ul class="pagination-list">
{% for page in elided_page_range %}
{% if page != "…" %}
<li>
<a href="?page={{ page }}"
<a href="?{% url_replace request 'page' page %}"
class="pagination-link {% if page == rescue_organizations_to_list.number %} is-current{% endif %}"
aria-label="{% blocktranslate %}Gehe zu Seite {{ page }}.{% endblocktranslate %}">
{{ page }}

View File

@@ -122,3 +122,12 @@ def host():
def time_since_hr(timestamp):
t_delta = timezone.now() - timestamp
return time_since_as_hr_string(t_delta)
@register.simple_tag
def url_replace(request, field, value):
dict_ = request.GET.copy()
dict_[field] = value
return dict_.urlencode()

View File

@@ -217,8 +217,8 @@ class RescueOrgSearch:
return fitting_rescue_orgs
def rescue_org_search_from_request(self, request):
if request.method == 'POST':
self.search_form = RescueOrgSearchForm(request.POST)
if request.method == 'GET' and request.GET.get("action", False) == "search":
self.search_form = RescueOrgSearchForm(request.GET)
self.search_form.is_valid()
if self.search_form.cleaned_data["location_string"] != "" and self.search_form.cleaned_data[

View File

@@ -771,7 +771,15 @@ def list_rescue_organizations(request, species=None, template='fellchensammlung/
context = {"rescue_organizations_to_list": rescue_organizations_to_list,
"show_rescue_orgs": True,
"elided_page_range": paginator.get_elided_page_range(page_number, on_each_side=2, on_ends=1),
"search_form": org_search.search_form, }
"search_form": org_search.search_form,
"place_not_found": org_search.place_not_found,
"map_center": org_search.position,
"search_center": org_search.position,
"map_pins": [org_search],
"location": org_search.location,
"search_radius": org_search.max_distance,
"zoom_level": zoom_level_for_radius(org_search.max_distance),
}
return render(request, template, context=context)