diff --git a/src/registrar/forms/application_wizard.py b/src/registrar/forms/application_wizard.py index e8e198ef8..ae9acaf63 100644 --- a/src/registrar/forms/application_wizard.py +++ b/src/registrar/forms/application_wizard.py @@ -52,7 +52,6 @@ class OrganizationTypeForm(RegistrarForm): class OrganizationFederalForm(RegistrarForm): federal_type = forms.ChoiceField( - required=False, choices=DomainApplication.BranchChoices.choices, widget=forms.RadioSelect, ) @@ -60,7 +59,6 @@ class OrganizationFederalForm(RegistrarForm): class OrganizationElectionForm(RegistrarForm): is_election_board = forms.BooleanField( - required=False, widget=forms.RadioSelect( choices=[ (True, "Yes"), @@ -120,9 +118,10 @@ class CurrentSitesForm(RegistrarForm): if not self.is_valid(): return obj.save() - normalized = Domain.normalize(self.cleaned_data["current_site"]) - # TODO: ability to update existing records - obj.current_websites.create(website=normalized) + normalized = Domain.normalize(self.cleaned_data["current_site"], blank=True) + if normalized: + # TODO: ability to update existing records + obj.current_websites.create(website=normalized) def from_database(self, obj): """Initializes this form's fields with values gotten from `obj`.""" @@ -142,20 +141,26 @@ class DotGovDomainForm(RegistrarForm): """Adds this form's cleaned data to `obj` and saves `obj`.""" if not self.is_valid(): return - normalized = Domain.normalize(self.cleaned_data["requested_domain"], "gov") - requested_domain = getattr(obj, "requested_domain", None) - if requested_domain is not None: - requested_domain.name = normalized - requested_domain.save() - else: - requested_domain = Domain.objects.create(name=normalized) - obj.requested_domain = requested_domain - obj.save() + normalized = Domain.normalize( + self.cleaned_data["requested_domain"], "gov", blank=True + ) + if normalized: + requested_domain = getattr(obj, "requested_domain", None) + if requested_domain is not None: + requested_domain.name = normalized + requested_domain.save() + else: + requested_domain = Domain.objects.create(name=normalized) + obj.requested_domain = requested_domain + obj.save() obj.save() - normalized = Domain.normalize(self.cleaned_data["alternative_domain"], "gov") - # TODO: ability to update existing records - obj.alternative_domains.create(website=normalized) + normalized = Domain.normalize( + self.cleaned_data["alternative_domain"], "gov", blank=True + ) + if normalized: + # TODO: ability to update existing records + obj.alternative_domains.create(website=normalized) def from_database(self, obj): """Initializes this form's fields with values gotten from `obj`.""" @@ -252,7 +257,9 @@ class SecurityEmailForm(RegistrarForm): class AnythingElseForm(RegistrarForm): anything_else = forms.CharField( - required=False, label="Anything else we should know", widget=forms.Textarea() + required=False, + label="Anything else we should know", + widget=forms.Textarea(), ) diff --git a/src/registrar/models/domain.py b/src/registrar/models/domain.py index e324e60fd..29126c98f 100644 --- a/src/registrar/models/domain.py +++ b/src/registrar/models/domain.py @@ -93,10 +93,17 @@ class Domain(TimeStampedModel): DOMAIN_REGEX = re.compile(r"^(?!-)[A-Za-z0-9-]{1,63}(? str: # noqa: C901 - """Return `domain` in form `.`, if possible. + def normalize(cls, domain: str, tld=None, blank=False) -> str: # noqa: C901 + """Return `domain` in form `.`. - This does not guarantee the returned string is a valid domain name.""" + Raises ValueError if string cannot be normalized. + + This does not guarantee the returned string is a valid domain name. + + Set `blank` to True to allow empty strings. + """ + if blank and len(domain.strip()) == 0: + return "" cleaned = domain.lower() # starts with https or http if cleaned.startswith("https://"): diff --git a/src/registrar/templates/home.html b/src/registrar/templates/home.html index 2010d87a2..ac5414c0b 100644 --- a/src/registrar/templates/home.html +++ b/src/registrar/templates/home.html @@ -32,7 +32,11 @@ {% for application in domain_applications %} - {{ application.requested_domain.name }} + + + {{ application.requested_domain.name|default:"New domain request" }} + + {{ application.status }} {% endfor %} diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py index 4b3234d73..28fbd64dd 100644 --- a/src/registrar/tests/test_views.py +++ b/src/registrar/tests/test_views.py @@ -602,6 +602,13 @@ class DomainApplicationTests(TestWithUser, WebTest): url = reverse("edit-application", kwargs={"id": application.pk}) response = self.client.get(url) + # TODO: this is a sketch of each page in the wizard which needs to be tested + # Django does not have tools sufficient for real end to end integration testing + # (for example, USWDS moves radio buttons off screen and replaces them with + # CSS styled "fakes" -- Django cannot determine if those are visually correct) + # -- the best that can/should be done here is to ensure the correct values + # are being passed to the templating engine + url = reverse("application_step", kwargs={"step": "organization_type"}) response = self.client.get(url, follow=True) self.assertContains(response, "")