diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 4a2a4515a..61409c31f 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -536,6 +536,8 @@ class MyUserAdmin(BaseUserAdmin): # in autocomplete_fields for user ordering = ["first_name", "last_name", "email"] + change_form_template = "django/admin/email_clipboard_change_form.html" + def get_search_results(self, request, queryset, search_term): """ Override for get_search_results. This affects any upstream model using autocomplete_fields, @@ -1808,6 +1810,8 @@ class VerifiedByStaffAdmin(ListHeaderAdmin): "requestor", ] + change_form_template = "django/admin/email_clipboard_change_form.html" + def truncated_notes(self, obj): # Truncate the 'notes' field to 50 characters return str(obj.notes)[:50] diff --git a/src/registrar/templates/django/admin/includes/email_clipboard_fieldset.html b/src/registrar/templates/django/admin/includes/email_clipboard_fieldset.html index ce8777420..f959f8edf 100644 --- a/src/registrar/templates/django/admin/includes/email_clipboard_fieldset.html +++ b/src/registrar/templates/django/admin/includes/email_clipboard_fieldset.html @@ -1,38 +1,13 @@ -{% extends "admin/fieldset.html" %} +{% extends "django/admin/includes/detail_table_fieldset.html" %} {% comment %} This is using a custom implementation fieldset.html (see admin/fieldset.html) {% endcomment %} -{% block fieldset_lines %} -{% for line in fieldset %} -
- {% if line.fields|length == 1 %}{{ line.errors }}{% else %}
{% endif %} - {% for field in line %} -
- {% if not line.fields|length == 1 and not field.is_readonly %}{{ field.errors }}{% endif %} -
- {% if field.is_checkbox %} - {{ field.field }}{{ field.label_tag }} - {% else %} - {{ field.label_tag }} - {% if field.is_readonly %} -
{{ field.contents }}
- {% elif field.field.name == "email" %} - {% include "admin/input_with_clipboard.html" with field=field.field %} - {% else %} - {{ field.field }} - {% endif %} - {% endif %} -
- {% if field.field.help_text %} -
-
{{ field.field.help_text|safe }}
-
- {% endif %} -
- {% endfor %} - {% if not line.fields|length == 1 %}
{% endif %} -
-{% endfor %} -{% endblock fieldset_lines %} +{% block field_other %} + {% if field.field.name == "email" %} + {% include "admin/input_with_clipboard.html" with field=field.field %} + {% else %} + {{ block.super }} + {% endif %} +{% endblock field_other %} diff --git a/src/registrar/tests/common.py b/src/registrar/tests/common.py index 655fda02b..afc30a16f 100644 --- a/src/registrar/tests/common.py +++ b/src/registrar/tests/common.py @@ -158,7 +158,7 @@ class GenericTestHelper(TestCase): Example Usage: ``` self.assert_sort_helper( - self.factory, self.superuser, self.admin, self.url, DomainInformation, "1", ("domain__name",) + "1", ("domain__name",) ) ``` @@ -204,7 +204,6 @@ class GenericTestHelper(TestCase): {"action": "delete_selected", "select_across": selected_across, "index": index, "_selected_action": "23"}, follow=True, ) - print(f"what is the response? {response}") return response diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index c69759fb2..7e42cb0d5 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -2022,10 +2022,14 @@ class TestDomainInformationAdmin(TestCase): # Check for the right title, email, and phone number in the response. # We only need to check for the end tag # (Otherwise this test will fail if we change classes, etc) + expected_email = "meoward.jones@igorville.gov" expected_creator_fields = [ # Field, expected value ("title", "Treat inspector"), - ("email", "meoward.jones@igorville.gov"), + ("email", f"{expected_email}"), + # Check for the existence of the copy button input. + # Lets keep things simple to minimize future conflicts. + ("email_copy_button_input", f'"), ] self.test_helper.assert_response_contains_distinct_values(response, expected_creator_fields) @@ -2034,20 +2038,24 @@ class TestDomainInformationAdmin(TestCase): self.assertContains(response, "Meoward Jones") # == Check for the submitter == # + expected_email = "mayor@igorville.gov" expected_submitter_fields = [ # Field, expected value ("title", "Admin Tester"), - ("email", "mayor@igorville.gov"), + ("email", f"{expected_email}"), + ("email_copy_button_input", f'"), ] self.test_helper.assert_response_contains_distinct_values(response, expected_submitter_fields) self.assertContains(response, "Testy2 Tester2") # == Check for the authorizing_official == # + expected_email = "testy@town.com" expected_ao_fields = [ # Field, expected value ("title", "Chief Tester"), ("email", "testy@town.com"), + ("email_copy_button_input", f'"), ] self.test_helper.assert_response_contains_distinct_values(response, expected_ao_fields) @@ -2069,10 +2077,12 @@ class TestDomainInformationAdmin(TestCase): self.assertContains(response, "Phone", count=3) # == Test the other_employees field == # + expected_email = "testy@town.com" expected_other_employees_fields = [ # Field, expected value ("title", "Another Tester"), - ("email", "testy2@town.com"), + ("email", f"{expected_email}"), + ("email_copy_button_input", f'"), ] self.test_helper.assert_response_contains_distinct_values(response, expected_other_employees_fields)