diff --git a/src/registrar/templates/admin/change_list_results.html b/src/registrar/templates/admin/change_list_results.html index 9ee3f9f59..831350888 100644 --- a/src/registrar/templates/admin/change_list_results.html +++ b/src/registrar/templates/admin/change_list_results.html @@ -17,7 +17,7 @@ Load our custom filters to extract info from the django generated markup. -{% if results.0.form %} +{% if results.0|contains_checkbox %} {# .gov - hardcode the select all checkbox #}
diff --git a/src/registrar/templatetags/custom_filters.py b/src/registrar/templatetags/custom_filters.py index f16408bf8..3614db18e 100644 --- a/src/registrar/templatetags/custom_filters.py +++ b/src/registrar/templatetags/custom_filters.py @@ -40,3 +40,11 @@ def slice_after(value, substring): result = value[index + len(substring) :] return result return value + + +@register.filter +def contains_checkbox(html_list): + for html_string in html_list: + if re.search(r']*type="checkbox"', html_string): + return True + return False diff --git a/src/registrar/tests/test_templatetags.py b/src/registrar/tests/test_templatetags.py index 36325ab5d..d5f8523c8 100644 --- a/src/registrar/tests/test_templatetags.py +++ b/src/registrar/tests/test_templatetags.py @@ -8,6 +8,7 @@ from registrar.templatetags.custom_filters import ( extract_a_text, find_index, slice_after, + contains_checkbox, ) @@ -83,3 +84,21 @@ class CustomFiltersTestCase(TestCase): self.assertEqual( result, value ) # Should return the original value if substring not found + + def test_contains_checkbox_with_checkbox(self): + # Test the filter when HTML list contains a checkbox + html_list = [ + '', + "
Some other HTML content
", + ] + result = contains_checkbox(html_list) + self.assertTrue(result) # Expecting True + + def test_contains_checkbox_without_checkbox(self): + # Test the filter when HTML list does not contain a checkbox + html_list = [ + "
Some HTML content without checkbox
", + "

More HTML content

", + ] + result = contains_checkbox(html_list) + self.assertFalse(result) # Expecting False