mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
Add correct error messages, allow default state to be none
This commit is contained in:
parent
7e7919691e
commit
03be457e37
4 changed files with 77 additions and 13 deletions
|
@ -647,7 +647,6 @@ class CisaRepresentativeForm(BaseDeletableRegistrarForm):
|
||||||
cisa_representative_email = forms.EmailField(
|
cisa_representative_email = forms.EmailField(
|
||||||
required=True,
|
required=True,
|
||||||
max_length=None,
|
max_length=None,
|
||||||
error_messages={"invalid": ("Enter your email address in the required format, like name@example.com.")},
|
|
||||||
label="Your representative’s email",
|
label="Your representative’s email",
|
||||||
validators=[
|
validators=[
|
||||||
MaxLengthValidator(
|
MaxLengthValidator(
|
||||||
|
@ -655,14 +654,17 @@ class CisaRepresentativeForm(BaseDeletableRegistrarForm):
|
||||||
message="Response must be less than 320 characters.",
|
message="Response must be less than 320 characters.",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
error_messages={
|
||||||
|
"invalid": ("Enter your email address in the required format, like name@example.com."),
|
||||||
|
"required": ("Enter the email address of your CISA regional representative."),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CisaRepresentativeYesNoForm(BaseYesNoForm):
|
class CisaRepresentativeYesNoForm(BaseYesNoForm):
|
||||||
"""Yes/no toggle for the CISA regions question on additional details"""
|
"""Yes/no toggle for the CISA regions question on additional details"""
|
||||||
|
|
||||||
# Note that these can be set as functions/init if you need more fine-grained control
|
form_is_checked = property(lambda self: self.domain_request.has_cisa_representative)
|
||||||
form_is_checked = property(lambda self: self.domain_request.has_cisa_representative()) # type: ignore
|
|
||||||
field_name = "has_cisa_representative"
|
field_name = "has_cisa_representative"
|
||||||
|
|
||||||
|
|
||||||
|
@ -677,6 +679,12 @@ class AdditionalDetailsForm(BaseDeletableRegistrarForm):
|
||||||
message="Response must be less than 2000 characters.",
|
message="Response must be less than 2000 characters.",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
error_messages={
|
||||||
|
"required": (
|
||||||
|
"Provide additional details you’d like us to know. "
|
||||||
|
"If you have nothing to add, select “No.”"
|
||||||
|
)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -684,7 +692,7 @@ class AdditionalDetailsYesNoForm(BaseYesNoForm):
|
||||||
"""Yes/no toggle for the anything else question on additional details"""
|
"""Yes/no toggle for the anything else question on additional details"""
|
||||||
|
|
||||||
# Note that these can be set as functions/init if you need more fine-grained control.
|
# Note that these can be set as functions/init if you need more fine-grained control.
|
||||||
form_is_checked = property(lambda self: self.domain_request.has_anything_else_text()) # type: ignore
|
form_is_checked = property(lambda self: self.domain_request.has_anything_else_text) # type: ignore
|
||||||
field_name = "has_anything_else_text"
|
field_name = "has_anything_else_text"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -263,6 +263,8 @@ class BaseYesNoForm(RegistrarForm):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print(f"wjat are the error messages? {choice_field.error_messages}")
|
||||||
|
|
||||||
return choice_field
|
return choice_field
|
||||||
|
|
||||||
def get_initial_value(self):
|
def get_initial_value(self):
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
# Generated by Django 4.2.10 on 2024-04-18 17:59
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("registrar", "0085_domaininformation_cisa_representative_email_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="domainrequest",
|
||||||
|
name="has_anything_else_text",
|
||||||
|
field=models.BooleanField(
|
||||||
|
blank=True, help_text="Determines if the user has a anything_else or not", null=True
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="domainrequest",
|
||||||
|
name="has_cisa_representative",
|
||||||
|
field=models.BooleanField(
|
||||||
|
blank=True, help_text="Determines if the user has a representative email or not", null=True
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -647,6 +647,15 @@ class DomainRequest(TimeStampedModel):
|
||||||
verbose_name="Additional details",
|
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(
|
cisa_representative_email = models.EmailField(
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
|
@ -655,6 +664,15 @@ class DomainRequest(TimeStampedModel):
|
||||||
max_length=320,
|
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(
|
is_policy_acknowledged = models.BooleanField(
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
|
@ -707,8 +725,25 @@ class DomainRequest(TimeStampedModel):
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
"""Save override for custom properties"""
|
"""Save override for custom properties"""
|
||||||
self.sync_organization_type()
|
self.sync_organization_type()
|
||||||
|
self.sync_yes_no_form_fields()
|
||||||
|
|
||||||
super().save(*args, **kwargs)
|
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):
|
def __str__(self):
|
||||||
try:
|
try:
|
||||||
if self.requested_domain and self.requested_domain.name:
|
if self.requested_domain and self.requested_domain.name:
|
||||||
|
@ -1047,16 +1082,8 @@ class DomainRequest(TimeStampedModel):
|
||||||
"""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:
|
|
||||||
"""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:
|
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]:
|
def is_federal(self) -> Union[bool, None]:
|
||||||
"""Is this domain request for a federal agency?
|
"""Is this domain request for a federal agency?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue