mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-06 04:27:22 +02:00
Refactored storage of CISA rep info to NOT use Contacts model
This commit is contained in:
parent
9fecf11558
commit
8af8a8c670
12 changed files with 164 additions and 132 deletions
|
@ -647,47 +647,20 @@ class NoOtherContactsForm(BaseDeletableRegistrarForm):
|
|||
|
||||
|
||||
class CisaRepresentativeForm(BaseDeletableRegistrarForm):
|
||||
JOIN = "cisa_representative"
|
||||
|
||||
def to_database(self, obj):
|
||||
if not self.is_valid():
|
||||
return
|
||||
contact = getattr(obj, "cisa_representative", None)
|
||||
if contact is not None and not contact.has_more_than_one_join("cisa_representative_domain_requests"):
|
||||
if self.form_data_marked_for_deletion:
|
||||
# remove the CISA contact from this domain request
|
||||
obj.cisa_representative = None
|
||||
# QUESTION - should we also delete the contact object if it is not joined to other entities?
|
||||
else:
|
||||
# update existing contact if it is not joined to other enttities
|
||||
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)
|
||||
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(
|
||||
cisa_representative_first_name = forms.CharField(
|
||||
label="First name / given name",
|
||||
error_messages={"required": "Enter your first name / given name."},
|
||||
)
|
||||
last_name = forms.CharField(
|
||||
cisa_representative_last_name = forms.CharField(
|
||||
label="Last name / family name",
|
||||
error_messages={"required": "Enter your last name / family name."},
|
||||
)
|
||||
email = forms.EmailField(
|
||||
label="Email",
|
||||
cisa_representative_email = forms.EmailField(
|
||||
label="Your representative’s email (optional)",
|
||||
max_length=None,
|
||||
required=False,
|
||||
error_messages={
|
||||
"invalid": ("Enter your email address in the required format, like name@example.com."),
|
||||
"invalid": ("Enter your representative’s email address in the required format, like name@example.com."),
|
||||
},
|
||||
validators=[
|
||||
MaxLengthValidator(
|
||||
|
@ -698,6 +671,7 @@ class CisaRepresentativeForm(BaseDeletableRegistrarForm):
|
|||
)
|
||||
|
||||
|
||||
|
||||
class CisaRepresentativeYesNoForm(BaseYesNoForm):
|
||||
"""Yes/no toggle for the CISA regions question on additional details"""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue