Fixed #34315 -- Preserved admin changelist filters on "Close" button.

This commit is contained in:
Bakdolot 2023-02-08 00:03:24 +06:00 committed by Mariusz Felisiak
parent 9f20f382ca
commit 325c44ac6c
2 changed files with 19 additions and 1 deletions

View File

@ -5,7 +5,10 @@
{% if show_save_as_new %}<input type="submit" value="{% translate 'Save as new' %}" name="_saveasnew">{% endif %} {% if show_save_as_new %}<input type="submit" value="{% translate 'Save as new' %}" name="_saveasnew">{% endif %}
{% if show_save_and_add_another %}<input type="submit" value="{% translate 'Save and add another' %}" name="_addanother">{% endif %} {% if show_save_and_add_another %}<input type="submit" value="{% translate 'Save and add another' %}" name="_addanother">{% endif %}
{% if show_save_and_continue %}<input type="submit" value="{% if can_change %}{% translate 'Save and continue editing' %}{% else %}{% translate 'Save and view' %}{% endif %}" name="_continue">{% endif %} {% if show_save_and_continue %}<input type="submit" value="{% if can_change %}{% translate 'Save and continue editing' %}{% else %}{% translate 'Save and view' %}{% endif %}" name="_continue">{% endif %}
{% if show_close %}<a href="{% url opts|admin_urlname:'changelist' %}" class="closelink">{% translate 'Close' %}</a>{% endif %} {% if show_close %}
{% url opts|admin_urlname:'changelist' as changelist_url %}
<a href="{% add_preserved_filters changelist_url %}" class="closelink">{% translate 'Close' %}</a>
{% endif %}
{% if show_delete_link and original %} {% if show_delete_link and original %}
{% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %} {% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
<a href="{% add_preserved_filters delete_url %}" class="deletelink">{% translate "Delete" %}</a> <a href="{% add_preserved_filters delete_url %}" class="deletelink">{% translate "Delete" %}</a>

View File

@ -7937,6 +7937,21 @@ class AdminKeepChangeListFiltersTests(TestCase):
self.assertRedirects(response, self.get_add_url()) self.assertRedirects(response, self.get_add_url())
post_data.pop("_addanother") post_data.pop("_addanother")
def test_change_view_close_link(self):
viewuser = User.objects.create_user(
username="view", password="secret", is_staff=True
)
viewuser.user_permissions.add(
get_perm(User, get_permission_codename("view", User._meta))
)
self.client.force_login(viewuser)
response = self.client.get(self.get_change_url())
close_link = re.search(
'<a href="(.*?)" class="closelink">Close</a>', response.content.decode()
)
close_link = close_link[1].replace("&amp;", "&")
self.assertURLEqual(close_link, self.get_changelist_url())
def test_change_view_without_preserved_filters(self): def test_change_view_without_preserved_filters(self):
response = self.client.get(self.get_change_url(add_preserved_filters=False)) response = self.client.get(self.get_change_url(add_preserved_filters=False))
# The action attribute is omitted. # The action attribute is omitted.