Add correct error messages, allow default state to be none

This commit is contained in:
zandercymatics 2024-04-18 12:14:10 -06:00
parent 7e7919691e
commit 03be457e37
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
4 changed files with 77 additions and 13 deletions

View file

@ -647,6 +647,15 @@ class DomainRequest(TimeStampedModel):
verbose_name="Additional details",
)
# This is a drop-in replacement for a has_anything_else_text() function.
# In order to track if the user has clicked the yes/no field (while keeping a none default), we need
# a tertiary state. We should not display this in /admin.
has_anything_else_text = models.BooleanField(
null=True,
blank=True,
help_text="Determines if the user has a anything_else or not",
)
cisa_representative_email = models.EmailField(
null=True,
blank=True,
@ -655,6 +664,15 @@ class DomainRequest(TimeStampedModel):
max_length=320,
)
# This is a drop-in replacement for an has_cisa_representative() function.
# In order to track if the user has clicked the yes/no field (while keeping a none default), we need
# a tertiary state. We should not display this in /admin.
has_cisa_representative = models.BooleanField(
null=True,
blank=True,
help_text="Determines if the user has a representative email or not",
)
is_policy_acknowledged = models.BooleanField(
null=True,
blank=True,
@ -707,8 +725,25 @@ class DomainRequest(TimeStampedModel):
def save(self, *args, **kwargs):
"""Save override for custom properties"""
self.sync_organization_type()
self.sync_yes_no_form_fields()
super().save(*args, **kwargs)
def sync_yes_no_form_fields(self):
"""Some yes/no forms use a db field to track whether it was checked or not.
We handle that here for def save().
"""
# This check is required to ensure that the form doesn't start out checked
if self.has_cisa_representative is not None:
self.has_cisa_representative = (
self.cisa_representative_email != "" and self.cisa_representative_email is not None
)
if self.anything_else is not None:
self.has_anything_else_text = (
self.anything_else != "" and self.anything_else is not None
)
def __str__(self):
try:
if self.requested_domain and self.requested_domain.name:
@ -1047,16 +1082,8 @@ class DomainRequest(TimeStampedModel):
"""Does this domain request have other contacts listed?"""
return self.other_contacts.exists()
def has_anything_else_text(self) -> bool:
"""Does this domain request have an 'anything else?' entry"""
return self.anything_else != "" and self.anything_else is not None
def has_cisa_representative(self) -> bool:
"""Does this domain request have cisa representative?"""
return self.cisa_representative_email != "" and self.cisa_representative_email is not None
def has_additional_details(self) -> bool:
return self.has_anything_else_text() or self.has_cisa_representative()
return self.has_anything_else_text() or self.has_cisa_representative
def is_federal(self) -> Union[bool, None]:
"""Is this domain request for a federal agency?