This commit is contained in:
CocoByte 2024-04-11 14:04:15 -06:00
parent 81f6e3e389
commit 44c74c7c86
No known key found for this signature in database
GPG key ID: BBFAA2526384C97F
3 changed files with 25 additions and 13 deletions

View file

@ -778,9 +778,11 @@ OtherContactsFormSet = forms.formset_factory(
formset=BaseOtherContactsFormSet, formset=BaseOtherContactsFormSet,
) )
class BaseDeletableRegistrarForm(RegistrarForm): class BaseDeletableRegistrarForm(RegistrarForm):
"""Adds special validation and delete functionality. """Adds special validation and delete functionality.
Used by forms that are tied to a Yes/No form.""" Used by forms that are tied to a Yes/No form."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.form_data_marked_for_deletion = False self.form_data_marked_for_deletion = False
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -830,6 +832,7 @@ class BaseDeletableRegistrarForm(RegistrarForm):
setattr(obj, name, value) setattr(obj, name, value)
obj.save() obj.save()
class NoOtherContactsForm(BaseDeletableRegistrarForm): class NoOtherContactsForm(BaseDeletableRegistrarForm):
no_other_contacts_rationale = forms.CharField( no_other_contacts_rationale = forms.CharField(
required=True, required=True,
@ -845,12 +848,14 @@ class NoOtherContactsForm(BaseDeletableRegistrarForm):
error_messages={"required": ("Rationale for no other employees is required.")}, error_messages={"required": ("Rationale for no other employees is required.")},
) )
class CisaRepresentativeForm(BaseDeletableRegistrarForm): class CisaRepresentativeForm(BaseDeletableRegistrarForm):
cisa_representative_email = forms.EmailField( cisa_representative_email = forms.EmailField(
required=False, required=False,
label="Are you working with a CISA representative?", #TODO-NL: (design check) - is this the right label? label="Are you working with a CISA representative?", # TODO-NL: (design check) - is this the right label?
) )
class CisaRepresentativeYesNoForm(RegistrarForm): class CisaRepresentativeYesNoForm(RegistrarForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Extend the initialization of the form from RegistrarForm __init__""" """Extend the initialization of the form from RegistrarForm __init__"""
@ -871,7 +876,7 @@ class CisaRepresentativeYesNoForm(RegistrarForm):
initial=initial_value, initial=initial_value,
widget=forms.RadioSelect, widget=forms.RadioSelect,
error_messages={ error_messages={
"required": "This question is required.", "required": "This question is required.",
}, },
) )
@ -889,6 +894,7 @@ class AdditionalDetailsForm(BaseDeletableRegistrarForm):
], ],
) )
class AdditionalDetailsYesNoForm(RegistrarForm): class AdditionalDetailsYesNoForm(RegistrarForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Extend the initialization of the form from RegistrarForm __init__""" """Extend the initialization of the form from RegistrarForm __init__"""
@ -909,10 +915,11 @@ class AdditionalDetailsYesNoForm(RegistrarForm):
initial=initial_value, initial=initial_value,
widget=forms.RadioSelect, widget=forms.RadioSelect,
error_messages={ error_messages={
"required": "This question is required.", #TODO-NL: (design check) - is this required? "required": "This question is required.", # TODO-NL: (design check) - is this required?
}, },
) )
class RequirementsForm(RegistrarForm): class RequirementsForm(RegistrarForm):
is_policy_acknowledged = forms.BooleanField( is_policy_acknowledged = forms.BooleanField(
label="I read and agree to the requirements for operating a .gov domain.", label="I read and agree to the requirements for operating a .gov domain.",

View file

@ -1037,14 +1037,14 @@ class DomainRequest(TimeStampedModel):
def has_other_contacts(self) -> bool: def has_other_contacts(self) -> bool:
"""Does this domain request have other contacts listed?""" """Does this domain request have other contacts listed?"""
return self.other_contacts.exists() return self.other_contacts.exists()
def has_anything_else_text(self) -> bool: def has_anything_else_text(self) -> bool:
"""Does this domain request have an 'anything else?' entry""" """Does this domain request have an 'anything else?' entry"""
return self.anything_else != "" and self.anything_else != None #TODO-NL: how to handle falsy strings again? return self.anything_else != "" and self.anything_else is not None
def has_cisa_representative(self) -> bool: def has_cisa_representative(self) -> bool:
"""Does this domain request have cisa representative?""" """Does this domain request have cisa representative?"""
return self.cisa_representative_email != "" and self.cisa_representative_email != None return self.cisa_representative_email != "" and self.cisa_representative_email is not None
def is_federal(self) -> Union[bool, None]: def is_federal(self) -> Union[bool, None]:
"""Is this domain request for a federal agency? """Is this domain request for a federal agency?

View file

@ -366,7 +366,8 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
or self.domain_request.no_other_contacts_rationale is not None or self.domain_request.no_other_contacts_rationale is not None
), ),
"anything_else": ( "anything_else": (
(self.domain_request.anything_else is not None and self.domain_request.cisa_representative_email) or self.domain_request.is_policy_acknowledged is not None (self.domain_request.anything_else is not None and self.domain_request.cisa_representative_email)
or self.domain_request.is_policy_acknowledged is not None
), ),
"requirements": self.domain_request.is_policy_acknowledged is not None, "requirements": self.domain_request.is_policy_acknowledged is not None,
"review": self.domain_request.is_policy_acknowledged is not None, "review": self.domain_request.is_policy_acknowledged is not None,
@ -580,7 +581,8 @@ class OtherContacts(DomainRequestWizard):
all_forms_valid = False all_forms_valid = False
return all_forms_valid return all_forms_valid
#DONE-NL: rename this to "Additional Details" (note: this is a find-replace job. VS will not refactor properly)
# DONE-NL: rename this to "Additional Details" (note: this is a find-replace job. VS will not refactor properly)
class AdditionalDetails(DomainRequestWizard): class AdditionalDetails(DomainRequestWizard):
# TODO-NL: Delete this old (original code for anything else) # TODO-NL: Delete this old (original code for anything else)
@ -590,7 +592,12 @@ class AdditionalDetails(DomainRequestWizard):
template_name = "domain_request_additional_details.html" template_name = "domain_request_additional_details.html"
# OLD: forms = [forms.OtherContactsYesNoForm, forms.OtherContactsFormSet, forms.NoOtherContactsForm] # OLD: forms = [forms.OtherContactsYesNoForm, forms.OtherContactsFormSet, forms.NoOtherContactsForm]
# TODO-NL: (refactor) -- move form hookups into respective areas # TODO-NL: (refactor) -- move form hookups into respective areas
forms = [forms.CisaRepresentativeYesNoForm, forms.CisaRepresentativeForm, forms.AdditionalDetailsYesNoForm, forms.AdditionalDetailsForm] forms = [
forms.CisaRepresentativeYesNoForm,
forms.CisaRepresentativeForm,
forms.AdditionalDetailsYesNoForm,
forms.AdditionalDetailsForm,
]
# TODO-NL: (refactor) -- move validation into respective areas # TODO-NL: (refactor) -- move validation into respective areas
def is_valid(self, forms: list) -> bool: def is_valid(self, forms: list) -> bool:
@ -605,7 +612,7 @@ class AdditionalDetails(DomainRequestWizard):
anything_else_yes_no_form = forms[2] anything_else_yes_no_form = forms[2]
anything_else_form = forms[3] anything_else_form = forms[3]
# ------- Validate cisa representative ------- # ------- Validate cisa representative -------
cisa_rep_portion_is_valid = True cisa_rep_portion_is_valid = True
# test first for yes_no_form validity # test first for yes_no_form validity
if cisa_representative_email_yes_no_form.is_valid(): if cisa_representative_email_yes_no_form.is_valid():
@ -621,7 +628,6 @@ class AdditionalDetails(DomainRequestWizard):
cisa_representative_email_form.mark_form_for_deletion() cisa_representative_email_form.mark_form_for_deletion()
cisa_rep_portion_is_valid = False cisa_rep_portion_is_valid = False
# ------- Validate anything else ------- # ------- Validate anything else -------
anything_else_portion_is_valid = True anything_else_portion_is_valid = True
# test first for yes_no_form validity # test first for yes_no_form validity
@ -638,7 +644,6 @@ class AdditionalDetails(DomainRequestWizard):
anything_else_form.mark_form_for_deletion() anything_else_form.mark_form_for_deletion()
anything_else_portion_is_valid = False anything_else_portion_is_valid = False
# ------- Return combined validation result ------- # ------- Return combined validation result -------
all_forms_valid = cisa_rep_portion_is_valid and anything_else_portion_is_valid all_forms_valid = cisa_rep_portion_is_valid and anything_else_portion_is_valid
return all_forms_valid return all_forms_valid