mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
Updates to Cisa Rep fields in Additional Details. Refactored Cisa Rep to utilize ContactsModel
This commit is contained in:
parent
cfce03ac8d
commit
a789b34bc0
5 changed files with 126 additions and 25 deletions
|
@ -646,21 +646,72 @@ class NoOtherContactsForm(BaseDeletableRegistrarForm):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CisaRepresentativeForm(BaseDeletableRegistrarForm):
|
# class CisaRepresentativeForm(BaseDeletableRegistrarForm):
|
||||||
cisa_representative_email = forms.EmailField(
|
# cisa_representative_email = forms.EmailField(
|
||||||
required=True,
|
# required=False,
|
||||||
|
# max_length=None,
|
||||||
|
# label="Your representative’s email",
|
||||||
|
# validators=[
|
||||||
|
# MaxLengthValidator(
|
||||||
|
# 320,
|
||||||
|
# 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 CisaRepresentativeForm(RegistrarForm):
|
||||||
|
JOIN = "cisa_representative"
|
||||||
|
|
||||||
|
logger.debug("GETTING CISA REP")
|
||||||
|
|
||||||
|
def to_database(self, obj):
|
||||||
|
logger.debug("SAVING CISA REP")
|
||||||
|
if not self.is_valid():
|
||||||
|
return
|
||||||
|
contact = getattr(obj, "cisa_representative", None)
|
||||||
|
logger.debug("EXISTING REP: %s" % contact)
|
||||||
|
if contact is not None and not contact.has_more_than_one_join("cisa_representative_domain_requests"):
|
||||||
|
# if contact exists in the database and is not joined to other entities
|
||||||
|
super().to_database(contact)
|
||||||
|
else:
|
||||||
|
# no contact exists OR contact exists which is joined also to other entities;
|
||||||
|
# in either case, create a new contact and update it
|
||||||
|
contact = Contact()
|
||||||
|
super().to_database(contact)
|
||||||
|
logger.debug("NEW REP: %s" % contact)
|
||||||
|
obj.cisa_representative = contact
|
||||||
|
obj.save()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_database(cls, obj):
|
||||||
|
contact = getattr(obj, "cisa_representative", None)
|
||||||
|
return super().from_database(contact)
|
||||||
|
|
||||||
|
first_name = forms.CharField(
|
||||||
|
label="First name / given name",
|
||||||
|
error_messages={"required": "Enter your first name / given name."},
|
||||||
|
)
|
||||||
|
last_name = forms.CharField(
|
||||||
|
label="Last name / family name",
|
||||||
|
error_messages={"required": "Enter your last name / family name."},
|
||||||
|
)
|
||||||
|
email = forms.EmailField(
|
||||||
|
label="Email",
|
||||||
max_length=None,
|
max_length=None,
|
||||||
label="Your representative’s email",
|
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."),
|
||||||
|
},
|
||||||
validators=[
|
validators=[
|
||||||
MaxLengthValidator(
|
MaxLengthValidator(
|
||||||
320,
|
320,
|
||||||
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."),
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -668,6 +719,7 @@ 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"""
|
||||||
|
|
||||||
form_is_checked = property(lambda self: self.domain_request.has_cisa_representative) # type: ignore
|
form_is_checked = property(lambda self: self.domain_request.has_cisa_representative) # type: ignore
|
||||||
|
logger.debug("CHECKING FOR YES/NO CHECK -- %s" % form_is_checked)
|
||||||
field_name = "has_cisa_representative"
|
field_name = "has_cisa_representative"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
# Generated by Django 4.2.10 on 2024-05-16 23:08
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("registrar", "0094_create_groups_v12"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="domaininformation",
|
||||||
|
name="cisa_representative_email",
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="domainrequest",
|
||||||
|
name="cisa_representative_email",
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="domaininformation",
|
||||||
|
name="cisa_representative",
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True,
|
||||||
|
help_text='Cisa Representative listed under "additional information" in the request form',
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.PROTECT,
|
||||||
|
related_name="cisa_representative_domain_requests_information",
|
||||||
|
to="registrar.contact",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="domainrequest",
|
||||||
|
name="cisa_representative",
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True,
|
||||||
|
help_text='Cisa Representative listed under "additional information" in the request form',
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.PROTECT,
|
||||||
|
related_name="cisa_representative_domain_requests",
|
||||||
|
to="registrar.contact",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -206,11 +206,13 @@ class DomainInformation(TimeStampedModel):
|
||||||
verbose_name="Additional details",
|
verbose_name="Additional details",
|
||||||
)
|
)
|
||||||
|
|
||||||
cisa_representative_email = models.EmailField(
|
cisa_representative = models.ForeignKey(
|
||||||
|
"registrar.Contact",
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
verbose_name="CISA regional representative",
|
related_name="cisa_representative_domain_requests_information",
|
||||||
max_length=320,
|
on_delete=models.PROTECT,
|
||||||
|
help_text='Cisa Representative listed under "additional information" in the request form',
|
||||||
)
|
)
|
||||||
|
|
||||||
is_policy_acknowledged = models.BooleanField(
|
is_policy_acknowledged = models.BooleanField(
|
||||||
|
|
|
@ -457,11 +457,14 @@ class DomainRequest(TimeStampedModel):
|
||||||
help_text="Determines if the user has a anything_else or not",
|
help_text="Determines if the user has a anything_else or not",
|
||||||
)
|
)
|
||||||
|
|
||||||
cisa_representative_email = models.EmailField(
|
|
||||||
|
cisa_representative = models.ForeignKey(
|
||||||
|
"registrar.Contact",
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
verbose_name="CISA regional representative",
|
related_name="cisa_representative_domain_requests",
|
||||||
max_length=320,
|
on_delete=models.PROTECT,
|
||||||
|
help_text='Cisa Representative listed under "additional information" in the request form',
|
||||||
)
|
)
|
||||||
|
|
||||||
# This is a drop-in replacement for an has_cisa_representative() function.
|
# This is a drop-in replacement for an has_cisa_representative() function.
|
||||||
|
@ -534,15 +537,16 @@ class DomainRequest(TimeStampedModel):
|
||||||
We handle that here for def save().
|
We handle that here for def save().
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
cisa_rep_is_not_none = self.cisa_representative is not None
|
||||||
|
logger.debug("CISA REPRESENTATIVE IS %s" % cisa_rep_is_not_none)
|
||||||
|
|
||||||
# This ensures that if we have prefilled data, the form is prepopulated
|
# This ensures that if we have prefilled data, the form is prepopulated
|
||||||
if self.cisa_representative_email is not None:
|
if cisa_rep_is_not_none:
|
||||||
self.has_cisa_representative = self.cisa_representative_email != ""
|
self.has_cisa_representative = True
|
||||||
|
|
||||||
# This check is required to ensure that the form doesn't start out checked
|
# This check is required to ensure that the form doesn't start out checked
|
||||||
if self.has_cisa_representative is not None:
|
if self.has_cisa_representative is not None:
|
||||||
self.has_cisa_representative = (
|
self.has_cisa_representative = cisa_rep_is_not_none
|
||||||
self.cisa_representative_email != "" and self.cisa_representative_email is not None
|
|
||||||
)
|
|
||||||
|
|
||||||
# This ensures that if we have prefilled data, the form is prepopulated
|
# This ensures that if we have prefilled data, the form is prepopulated
|
||||||
if self.anything_else is not None:
|
if self.anything_else is not None:
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
{# commented out so it does not appear at this point on this page #}
|
{# commented out so it does not appear at this point on this page #}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
<!-- TODO-NL: (refactor) Breakup into two separate components-->
|
|
||||||
{% block form_fields %}
|
{% block form_fields %}
|
||||||
<fieldset class="usa-fieldset margin-top-2">
|
<fieldset class="usa-fieldset margin-top-2">
|
||||||
<legend>
|
<legend>
|
||||||
|
@ -22,13 +21,13 @@
|
||||||
{% input_with_errors forms.0.has_cisa_representative %}
|
{% input_with_errors forms.0.has_cisa_representative %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{# forms.0 is a small yes/no form that toggles the visibility of "cisa representative" formset #}
|
{# forms.0 is a small yes/no form that toggles the visibility of "cisa representative" formset #}
|
||||||
<!-- TODO-NL: Hookup forms.0 to yes/no form for cisa representative (backend def)-->
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<div id="cisa-representative" class="cisa-representative-form">
|
<div id="cisa-representative" class="cisa-representative-form">
|
||||||
{% input_with_errors forms.1.cisa_representative_email %}
|
{% input_with_errors forms.1.first_name %}
|
||||||
|
{% input_with_errors forms.1.last_name %}
|
||||||
|
{% input_with_errors forms.1.email %}
|
||||||
{# forms.1 is a form for inputting the e-mail of a cisa representative #}
|
{# forms.1 is a form for inputting the e-mail of a cisa representative #}
|
||||||
<!-- TODO-NL: Hookup forms.1 to cisa representative form (backend def) -->
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,7 +41,6 @@
|
||||||
{% input_with_errors forms.2.has_anything_else_text %}
|
{% input_with_errors forms.2.has_anything_else_text %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{# forms.2 is a small yes/no form that toggles the visibility of "cisa representative" formset #}
|
{# forms.2 is a small yes/no form that toggles the visibility of "cisa representative" formset #}
|
||||||
<!-- TODO-NL: Hookup forms.2 to yes/no form for anything else form (backend def)-->
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<div id="anything-else">
|
<div id="anything-else">
|
||||||
|
@ -50,6 +48,5 @@
|
||||||
{% input_with_errors forms.3.anything_else %}
|
{% input_with_errors forms.3.anything_else %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{# forms.3 is a form for inputting the e-mail of a cisa representative #}
|
{# forms.3 is a form for inputting the e-mail of a cisa representative #}
|
||||||
<!-- TODO-NL: Hookup forms.3 to anything else form (backend def) -->
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue