Review feedback too numerous to mention

This commit is contained in:
Neil Martinsen-Burrell 2023-01-05 15:20:50 -06:00
parent 56606f32e0
commit f7e0975e4c
No known key found for this signature in database
GPG key ID: 6A3C818CC10D0184
17 changed files with 196 additions and 57 deletions

View file

@ -7,9 +7,11 @@ import logging
from typing import Union
from django import forms
from django.core.validators import RegexValidator
from django.shortcuts import render
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import resolve
from django.utils.safestring import mark_safe
from formtools.wizard.views import NamedUrlSessionWizardView # type: ignore
from formtools.wizard.storage.session import SessionStorage # type: ignore
@ -22,6 +24,11 @@ from registrar.models import Contact, DomainApplication, Domain
logger = logging.getLogger(__name__)
REQUIRED_SUFFIX = mark_safe(
' <abbr class="usa-hint usa-hint--required" title="required">*</abbr>'
)
class RegistrarForm(forms.Form):
"""Subclass used to remove the default colon suffix from all fields."""
@ -52,6 +59,7 @@ class OrganizationTypeForm(RegistrarForm):
required=True,
choices=DomainApplication.OrganizationChoices.choices,
widget=forms.RadioSelect,
error_messages={"required": "This question is required."},
)
@ -59,19 +67,32 @@ class OrganizationFederalForm(RegistrarForm):
federal_type = forms.ChoiceField(
choices=DomainApplication.BranchChoices.choices,
widget=forms.RadioSelect,
error_messages={"required": "This question is required."},
)
class OrganizationElectionForm(RegistrarForm):
is_election_board = forms.BooleanField(
is_election_board = forms.NullBooleanField(
widget=forms.RadioSelect(
choices=[
(True, "Yes"),
(False, "No"),
],
),
required=False, # use field validation to require an answer
)
def clean_is_election_board(self):
"""This box must be checked to proceed but offer a clear error."""
# already converted to a boolean
is_election_board = self.cleaned_data["is_election_board"]
if is_election_board is None:
raise forms.ValidationError(
"Please select Yes or No.",
code="required",
)
return is_election_board
class OrganizationContactForm(RegistrarForm):
# for federal agencies we also want to know the top-level agency.
@ -81,19 +102,35 @@ class OrganizationContactForm(RegistrarForm):
# it is a federal agency.
required=False,
choices=DomainApplication.AGENCY_CHOICES,
label_suffix=REQUIRED_SUFFIX,
)
organization_name = forms.CharField(
label="Organization Name", label_suffix=REQUIRED_SUFFIX
)
address_line1 = forms.CharField(
label="Street address",
label_suffix=REQUIRED_SUFFIX,
)
organization_name = forms.CharField(label="Organization Name")
address_line1 = forms.CharField(label="Street address")
address_line2 = forms.CharField(
required=False,
label="Street address line 2",
)
city = forms.CharField(label="City")
city = forms.CharField(label="City", label_suffix=REQUIRED_SUFFIX)
state_territory = forms.ChoiceField(
label="State, territory, or military post",
choices=[("", "--Select--")] + DomainApplication.StateTerritoryChoices.choices,
label_suffix=REQUIRED_SUFFIX,
)
zipcode = forms.CharField(
label="ZIP code",
label_suffix=REQUIRED_SUFFIX,
validators=[
RegexValidator(
"^[0-9]{5}(?:-[0-9]{4})?$|^$",
message="Please enter a ZIP code in the form 12345 or 12345-6789",
)
],
)
zipcode = forms.CharField(label="ZIP code")
urbanization = forms.CharField(
required=False,
label="Urbanization (Puerto Rico only)",
@ -120,17 +157,31 @@ class AuthorizingOfficialForm(RegistrarForm):
if contact is not None:
super().from_database(contact)
first_name = forms.CharField(label="First name/given name")
first_name = forms.CharField(
label="First name/given name",
label_suffix=REQUIRED_SUFFIX,
)
middle_name = forms.CharField(
required=False,
label="Middle name (optional)",
label="Middle name",
)
last_name = forms.CharField(
label="Last name/family name",
label_suffix=REQUIRED_SUFFIX,
)
title = forms.CharField(
label="Title or role in your organization",
label_suffix=REQUIRED_SUFFIX,
)
last_name = forms.CharField(label="Last name/family name")
title = forms.CharField(label="Title or role in your organization")
email = forms.EmailField(
label="Email", error_messages={"invalid": "Please enter a valid email address."}
label="Email",
label_suffix=REQUIRED_SUFFIX,
error_messages={"invalid": "Please enter a valid email address."}
)
phone = PhoneNumberField(
label="Phone",
label_suffix=REQUIRED_SUFFIX,
)
phone = PhoneNumberField(label="Phone")
class CurrentSitesForm(RegistrarForm):
@ -164,6 +215,11 @@ class CurrentSitesForm(RegistrarForm):
return inputted_site
# something has been inputted
if inputted_site.startswith("http://") or inputted_site.startswith("https://"):
# strip of the protocol that the pasted from their web browser
inputted_site = inputted_site.split("//", 1)[1]
if Domain.string_could_be_domain(inputted_site):
return inputted_site
else:
@ -247,7 +303,11 @@ class DotGovDomainForm(RegistrarForm):
class PurposeForm(RegistrarForm):
purpose = forms.CharField(label="Purpose", widget=forms.Textarea())
purpose = forms.CharField(
label="Purpose",
widget=forms.Textarea(),
error_messages={"required": "You must enter some information about the purpose of your domain"}
)
class YourContactForm(RegistrarForm):
@ -270,17 +330,31 @@ class YourContactForm(RegistrarForm):
if contact is not None:
super().from_database(contact)
first_name = forms.CharField(label="First name/given name")
first_name = forms.CharField(
label="First name/given name",
label_suffix=REQUIRED_SUFFIX,
)
middle_name = forms.CharField(
required=False,
label="Middle name (optional)",
label="Middle name",
)
last_name = forms.CharField(
label="Last name/family name",
label_suffix=REQUIRED_SUFFIX,
)
title = forms.CharField(
label="Title or role in your organization",
label_suffix=REQUIRED_SUFFIX,
)
last_name = forms.CharField(label="Last name/family name")
title = forms.CharField(label="Title or role in your organization")
email = forms.EmailField(
label="Email", error_messages={"invalid": "Please enter a valid email address."}
label="Email",
label_suffix=REQUIRED_SUFFIX,
error_messages={"invalid": "Please enter a valid email address."}
)
phone = PhoneNumberField(
label="Phone",
label_suffix=REQUIRED_SUFFIX,
)
phone = PhoneNumberField(label="Phone")
class OtherContactsForm(RegistrarForm):
@ -305,17 +379,32 @@ class OtherContactsForm(RegistrarForm):
if other_contacts is not None:
super().from_database(other_contacts)
first_name = forms.CharField(label="First name/given name")
first_name = forms.CharField(
label="First name/given name",
label_suffix=REQUIRED_SUFFIX,
)
middle_name = forms.CharField(
required=False,
label="Middle name (optional)",
label="Middle name",
)
last_name = forms.CharField(
label="Last name/family name",
label_suffix=REQUIRED_SUFFIX,
)
title = forms.CharField(
label="Title or role in your organization",
label_suffix=REQUIRED_SUFFIX,
)
last_name = forms.CharField(label="Last name/family name")
title = forms.CharField(label="Title or role in your organization")
email = forms.EmailField(
label="Email", error_messages={"invalid": "Please enter a valid email address."}
label="Email",
label_suffix=REQUIRED_SUFFIX,
error_messages={"invalid": "Please enter a valid email address."}
)
phone = PhoneNumberField(
label="Phone",
label_suffix=REQUIRED_SUFFIX,
)
phone = PhoneNumberField(label="Phone")
class SecurityEmailForm(RegistrarForm):