Retain filter params in ModelAdmin's search form

This basically uses the same code as django uses for the search form in
its ModelAdmin, to retain the current query params (template
admin/search_form.html).

Fixes #6006
pull/9167/head
Stefan Hammer 2022-09-15 11:29:50 +02:00 zatwierdzone przez LB (Ben Johnston)
rodzic 0fd2d3d4c1
commit 80585e68c2
4 zmienionych plików z 13 dodań i 0 usunięć

Wyświetl plik

@ -29,6 +29,7 @@ Changelog
* Fix: Ensure that disabled buttons have a consistent presentation on hover to indicate no interaction is available (Paarth Agarwal)
* Fix: Update the 'Locked pages' report menu title so that it is consistent with other pages reports and its own title on viewing (Nicholas Johnson)
* Fix: Support `formfield_callback` handling on `ModelForm.Meta` for future Django 4.2 release (Matt Westcott)
* Fix: Ensure that `ModelAdmin` correctly supports filters in combination with subsequent searches without clearing the applied filters (Stefan Hammer)
4.0.2 (xx.xx.xxxx) - IN DEVELOPMENT

Wyświetl plik

@ -41,6 +41,7 @@ Wagtail 4.1 is designated a Long Term Support (LTS) release. Long Term Support r
* Ensure that disabled buttons have a consistent presentation on hover to indicate no interaction is available (Paarth Agarwal)
* Update the 'Locked pages' report menu title so that it is consistent with other pages reports and its own title on viewing (Nicholas Johnson)
* Support `formfield_callback` handling on `ModelForm.Meta` for future Django 4.2 release (Matt Westcott)
* Ensure that `ModelAdmin` correctly supports filters in combination with subsequent searches without clearing the applied filters (Stefan Hammer)
## Upgrade considerations

Wyświetl plik

@ -6,5 +6,9 @@
<input id="id_q" name="{{ search_var }}" value="{{ view.query }}" placeholder="{% blocktrans trimmed with view.verbose_name_plural|lower as name %}Search {{ name }}{% endblocktrans %}" type="text">
{% endfield %}
<button type="submit" class="w-sr-only">{% trans 'Search' %}</button>
{# Keep all parameters from the query string (e.g. filter state). #}
{% for name, value in view.params.items %}
{% if name != search_var %}<input type="hidden" name="{{ name }}" value="{{ value }}">{% endif %}
{% endfor %}
</form>
{% endif %}

Wyświetl plik

@ -156,6 +156,13 @@ class TestBookIndexView(TestCase, WagtailTestUtils):
response, '<span class="result-count">2 out of 4</span>', html=True
)
# The search form should retain the filter
self.assertContains(
response,
'<input type="hidden" name="author__id__exact" value="1">',
html=True,
)
for book in response.context["object_list"]:
self.assertEqual(book.author_id, 1)