From dd9df90fb4f9c377532bd0c9b614812b2fdbfd5b Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 10 May 2024 08:33:10 -0600 Subject: [PATCH] Infra --- src/registrar/forms/contact.py | 6 ++- src/registrar/forms/domain_request_wizard.py | 37 ++++++++++++++++++- .../forms/utility/wizard_form_helper.py | 3 -- .../templates/finish_contact_setup.html | 16 ++++---- src/registrar/views/contact.py | 6 +++ 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/registrar/forms/contact.py b/src/registrar/forms/contact.py index ae8d28dc8..1ddc1a2a0 100644 --- a/src/registrar/forms/contact.py +++ b/src/registrar/forms/contact.py @@ -1,11 +1,15 @@ from django import forms -from phonenumber_field.modelfields import PhoneNumberField # type: ignore +from phonenumber_field.formfields import PhoneNumberField # type: ignore from django.core.validators import MaxLengthValidator class ContactForm(forms.Form): """Form for adding or editing a contact""" + def __init__(self, *args, **kwargs): + kwargs.setdefault("label_suffix", "") + super(ContactForm, self).__init__(*args, **kwargs) + first_name = forms.CharField( label="First name / given name", error_messages={"required": "Enter your first name / given name."}, diff --git a/src/registrar/forms/domain_request_wizard.py b/src/registrar/forms/domain_request_wizard.py index 32c59620d..9d16a30de 100644 --- a/src/registrar/forms/domain_request_wizard.py +++ b/src/registrar/forms/domain_request_wizard.py @@ -16,7 +16,6 @@ from registrar.forms.utility.wizard_form_helper import ( from registrar.models import Contact, DomainRequest, DraftDomain, Domain, FederalAgency from registrar.templatetags.url_helpers import public_site_url from registrar.utility.enums import ValidationReturnType -from registrar.forms import ContactForm logger = logging.getLogger(__name__) @@ -386,7 +385,7 @@ class PurposeForm(RegistrarForm): ) -class YourContactForm(RegistrarForm, ContactForm): +class YourContactForm(RegistrarForm): JOIN = "submitter" def to_database(self, obj): @@ -409,6 +408,40 @@ class YourContactForm(RegistrarForm, ContactForm): contact = getattr(obj, "submitter", None) return super().from_database(contact) + first_name = forms.CharField( + label="First name / given name", + error_messages={"required": "Enter your first name / given name."}, + ) + middle_name = forms.CharField( + required=False, + label="Middle name (optional)", + ) + last_name = forms.CharField( + label="Last name / family name", + error_messages={"required": "Enter your last name / family name."}, + ) + title = forms.CharField( + label="Title or role in your organization", + error_messages={ + "required": ("Enter your title or role in your organization (e.g., Chief Information Officer).") + }, + ) + email = forms.EmailField( + label="Email", + max_length=None, + error_messages={"invalid": ("Enter your email address in the required format, like name@example.com.")}, + validators=[ + MaxLengthValidator( + 320, + message="Response must be less than 320 characters.", + ) + ], + ) + phone = PhoneNumberField( + label="Phone", + error_messages={"invalid": "Enter a valid 10-digit phone number.", "required": "Enter your phone number."}, + ) + class OtherContactsYesNoForm(BaseYesNoForm): """The yes/no field for the OtherContacts form.""" diff --git a/src/registrar/forms/utility/wizard_form_helper.py b/src/registrar/forms/utility/wizard_form_helper.py index 350605c1a..9b8a7c4d8 100644 --- a/src/registrar/forms/utility/wizard_form_helper.py +++ b/src/registrar/forms/utility/wizard_form_helper.py @@ -23,9 +23,6 @@ class RegistrarForm(forms.Form): # save a reference to a domain request object if "domain_request" in kwargs: self.domain_request = kwargs.pop("domain_request", None) - - if "contact" in kwargs: - self.contact = kwargs.pop("contact", None) super(RegistrarForm, self).__init__(*args, **kwargs) diff --git a/src/registrar/templates/finish_contact_setup.html b/src/registrar/templates/finish_contact_setup.html index c6f02f64b..1849889c8 100644 --- a/src/registrar/templates/finish_contact_setup.html +++ b/src/registrar/templates/finish_contact_setup.html @@ -41,20 +41,22 @@ Your contact information - - {% input_with_errors forms.0.first_name %} + {{form.first_name}} + {% comment %} + {% input_with_errors form.first_name %} - {% input_with_errors forms.0.middle_name %} + {% input_with_errors form.middle_name %} - {% input_with_errors forms.0.last_name %} + {% input_with_errors form.last_name %} - {% input_with_errors forms.0.title %} + {% input_with_errors form.title %} - {% input_with_errors forms.0.email %} + {% input_with_errors form.email %} {% with add_class="usa-input--medium" %} - {% input_with_errors forms.0.phone %} + {% input_with_errors form.phone %} {% endwith %} + {% endcomment %}
diff --git a/src/registrar/views/contact.py b/src/registrar/views/contact.py index 9f0e4e393..110ee254f 100644 --- a/src/registrar/views/contact.py +++ b/src/registrar/views/contact.py @@ -75,6 +75,12 @@ class ContactProfileSetupView(ContactPermissionView): template_name = "finish_contact_setup.html" form_class = ContactForm + def get_form_kwargs(self, *args, **kwargs): + """Add domain_info.organization_name instance to make a bound form.""" + form_kwargs = super().get_form_kwargs(*args, **kwargs) + form_kwargs["instance"] = self.object + return form_kwargs + def get(self, request, *args, **kwargs): self._get_contact(request) context = self.get_context_data(object=self.object)