Fixed #27888 -- Added link to clear all filters in the admin changelist view.

This commit is contained in:
Hasan Ramezani 2020-01-21 15:14:11 +01:00 committed by Mariusz Felisiak
parent 5a68a223c7
commit b94764e178
4 changed files with 26 additions and 0 deletions

View File

@ -187,6 +187,12 @@
color: #036;
}
#changelist-filter #changelist-filter-clear a {
font-size: 13px;
padding-bottom: 10px;
border-bottom: 1px solid #eaeaea;
}
/* DATE DRILLDOWN */
.change-list ul.toplinks {

View File

@ -60,6 +60,11 @@
{% if cl.has_filters %}
<div id="changelist-filter">
<h2>{% translate 'Filter' %}</h2>
{% if cl.has_filters or cl.search_fields %}
{% if cl.preserved_filters %}<h3 id="changelist-filter-clear">
<a href="?{% if cl.is_popup %}_popup=1{% endif %}">&#10006; {% translate "Clear all filters" %}</a>
</h3>{% endif %}
{% endif %}
{% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
</div>
{% endif %}

View File

@ -37,6 +37,9 @@ Minor features
:attr:`.ModelAdmin.list_filter` allows filtering on empty values (empty
strings and nulls) in the admin changelist view.
* Filters in the right sidebar of the admin changelist view now contains a link
to clear all filters.
:mod:`django.contrib.admindocs`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -707,6 +707,18 @@ class ChangeListTests(TestCase):
link = reverse('admin:admin_changelist_parent_change', args=(p.pk,))
self.assertNotContains(response, '<a href="%s">' % link)
def test_clear_all_filters_link(self):
self.client.force_login(self.superuser)
link = '<a href="?">&#10006; Clear all filters</a>'
response = self.client.get(reverse('admin:auth_user_changelist'))
self.assertNotContains(response, link)
for data in (
{SEARCH_VAR: 'test'},
{'is_staff__exact': '0'},
):
response = self.client.get(reverse('admin:auth_user_changelist'), data=data)
self.assertContains(response, link)
def test_tuple_list_display(self):
swallow = Swallow.objects.create(origin='Africa', load='12.34', speed='22.2')
swallow2 = Swallow.objects.create(origin='Africa', load='12.34', speed='22.2')