Browse files

Fixed #21510 -- Readded search reset link in changelist search bar

Thanks moritz.pfeiffer at alp-phone.ch for the report and
Tim Graham for the initial patch.
  • Loading branch information...
1 parent 5db028a commit c7c647419cb857fe53cf1368c10223c6e042c216 @claudep claudep committed Dec 7, 2013
Showing with 15 additions and 4 deletions.
  1. +1 −1 django/contrib/admin/views/main.py
  2. +2 −0 docs/releases/1.6.1.txt
  3. +12 −3 tests/admin_views/tests.py
View
2 django/contrib/admin/views/main.py
@@ -217,7 +217,7 @@ def get_results(self, request):
# Perform a slight optimization:
# full_result_count is equal to paginator.count if no filters
# were applied
- if self.get_filters_params():
+ if self.get_filters_params() or self.params.get(SEARCH_VAR):
full_result_count = self.root_queryset.count()
else:
full_result_count = result_count
View
2 docs/releases/1.6.1.txt
@@ -47,3 +47,5 @@ Bug fixes
* Fixed password hash upgrade when changing the iteration count (#21535).
* Fixed a bug in the debug view when the urlconf only contains one element
(#21530).
+* Re-added missing search result count and reset link in changelist admin view
+ (#21510).
View
15 tests/admin_views/tests.py
@@ -2275,6 +2275,15 @@ def test_pluggable_search(self):
self.assertContains(response, "\n1 pluggable search person\n")
self.assertContains(response, "Amy")
+ def test_reset_link(self):
+ """
+ Test presence of reset link in search bar ("1 result (_x total_)").
+ """
+ response = self.client.get('/test_admin/admin/admin_views/person/?q=Gui')
+ self.assertContains(response,
+ """<span class="small quiet">1 result (<a href="?">3 total</a>)</span>""",
+ html=True)
+
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminInheritedInlinesTest(TestCase):
@@ -2716,17 +2725,17 @@ def test_changelist_view_count_queries(self):
resp = self.client.get('/test_admin/admin/admin_views/person/')
self.assertEqual(resp.context['selection_note'], '0 of 2 selected')
self.assertEqual(resp.context['selection_note_all'], 'All 2 selected')
- with self.assertNumQueries(4):
+ # here one more count(*) query will run, because filters were applied
+ with self.assertNumQueries(5):
extra = {'q': 'not_in_name'}
resp = self.client.get('/test_admin/admin/admin_views/person/', extra)
self.assertEqual(resp.context['selection_note'], '0 of 0 selected')
self.assertEqual(resp.context['selection_note_all'], 'All 0 selected')
- with self.assertNumQueries(4):
+ with self.assertNumQueries(5):
extra = {'q': 'person'}
resp = self.client.get('/test_admin/admin/admin_views/person/', extra)
self.assertEqual(resp.context['selection_note'], '0 of 2 selected')
self.assertEqual(resp.context['selection_note_all'], 'All 2 selected')
- # here one more count(*) query will run, because filters were applied
with self.assertNumQueries(5):
extra = {'gender__exact': '1'}
resp = self.client.get('/test_admin/admin/admin_views/person/', extra)

0 comments on commit c7c6474

Please sign in to comment.