Respond to PR feedback

This commit is contained in:
Seamus Johnston 2022-12-06 15:51:41 -06:00
parent 07993a8d75
commit 90557c51e8
No known key found for this signature in database
GPG key ID: 2F21225985069105
4 changed files with 47 additions and 22 deletions

View file

@ -52,7 +52,6 @@ class OrganizationTypeForm(RegistrarForm):
class OrganizationFederalForm(RegistrarForm): class OrganizationFederalForm(RegistrarForm):
federal_type = forms.ChoiceField( federal_type = forms.ChoiceField(
required=False,
choices=DomainApplication.BranchChoices.choices, choices=DomainApplication.BranchChoices.choices,
widget=forms.RadioSelect, widget=forms.RadioSelect,
) )
@ -60,7 +59,6 @@ class OrganizationFederalForm(RegistrarForm):
class OrganizationElectionForm(RegistrarForm): class OrganizationElectionForm(RegistrarForm):
is_election_board = forms.BooleanField( is_election_board = forms.BooleanField(
required=False,
widget=forms.RadioSelect( widget=forms.RadioSelect(
choices=[ choices=[
(True, "Yes"), (True, "Yes"),
@ -120,9 +118,10 @@ class CurrentSitesForm(RegistrarForm):
if not self.is_valid(): if not self.is_valid():
return return
obj.save() obj.save()
normalized = Domain.normalize(self.cleaned_data["current_site"]) normalized = Domain.normalize(self.cleaned_data["current_site"], blank=True)
# TODO: ability to update existing records if normalized:
obj.current_websites.create(website=normalized) # TODO: ability to update existing records
obj.current_websites.create(website=normalized)
def from_database(self, obj): def from_database(self, obj):
"""Initializes this form's fields with values gotten from `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`.""" """Adds this form's cleaned data to `obj` and saves `obj`."""
if not self.is_valid(): if not self.is_valid():
return return
normalized = Domain.normalize(self.cleaned_data["requested_domain"], "gov") normalized = Domain.normalize(
requested_domain = getattr(obj, "requested_domain", None) self.cleaned_data["requested_domain"], "gov", blank=True
if requested_domain is not None: )
requested_domain.name = normalized if normalized:
requested_domain.save() requested_domain = getattr(obj, "requested_domain", None)
else: if requested_domain is not None:
requested_domain = Domain.objects.create(name=normalized) requested_domain.name = normalized
obj.requested_domain = requested_domain requested_domain.save()
obj.save() else:
requested_domain = Domain.objects.create(name=normalized)
obj.requested_domain = requested_domain
obj.save()
obj.save() obj.save()
normalized = Domain.normalize(self.cleaned_data["alternative_domain"], "gov") normalized = Domain.normalize(
# TODO: ability to update existing records self.cleaned_data["alternative_domain"], "gov", blank=True
obj.alternative_domains.create(website=normalized) )
if normalized:
# TODO: ability to update existing records
obj.alternative_domains.create(website=normalized)
def from_database(self, obj): def from_database(self, obj):
"""Initializes this form's fields with values gotten from `obj`.""" """Initializes this form's fields with values gotten from `obj`."""
@ -252,7 +257,9 @@ class SecurityEmailForm(RegistrarForm):
class AnythingElseForm(RegistrarForm): class AnythingElseForm(RegistrarForm):
anything_else = forms.CharField( 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(),
) )

View file

@ -93,10 +93,17 @@ class Domain(TimeStampedModel):
DOMAIN_REGEX = re.compile(r"^(?!-)[A-Za-z0-9-]{1,63}(?<!-)\.[A-Za-z]{2,6}") DOMAIN_REGEX = re.compile(r"^(?!-)[A-Za-z0-9-]{1,63}(?<!-)\.[A-Za-z]{2,6}")
@classmethod @classmethod
def normalize(cls, domain: str, tld=None) -> str: # noqa: C901 def normalize(cls, domain: str, tld=None, blank=False) -> str: # noqa: C901
"""Return `domain` in form `<second level>.<tld>`, if possible. """Return `domain` in form `<second level>.<tld>`.
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() cleaned = domain.lower()
# starts with https or http # starts with https or http
if cleaned.startswith("https://"): if cleaned.startswith("https://"):

View file

@ -32,7 +32,11 @@
<tbody> <tbody>
{% for application in domain_applications %} {% for application in domain_applications %}
<tr> <tr>
<th>{{ application.requested_domain.name }}</th> <th>
<a href="{% url 'edit-application' application.pk %}">
{{ application.requested_domain.name|default:"New domain request" }}
</a>
</th>
<td>{{ application.status }}</td> <td>{{ application.status }}</td>
</tr> </tr>
{% endfor %} {% endfor %}

View file

@ -602,6 +602,13 @@ class DomainApplicationTests(TestWithUser, WebTest):
url = reverse("edit-application", kwargs={"id": application.pk}) url = reverse("edit-application", kwargs={"id": application.pk})
response = self.client.get(url) 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"}) url = reverse("application_step", kwargs={"step": "organization_type"})
response = self.client.get(url, follow=True) response = self.client.get(url, follow=True)
self.assertContains(response, "<input>") self.assertContains(response, "<input>")