mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-10 06:24:45 +02:00
tweak to prevent duplication
This commit is contained in:
parent
d0bdc194d2
commit
2ade162ec4
4 changed files with 41 additions and 10 deletions
|
@ -43,6 +43,11 @@ class UserFixture:
|
||||||
"username": "2ffe71b0-cea4-4097-8fb6-7a35b901dd70",
|
"username": "2ffe71b0-cea4-4097-8fb6-7a35b901dd70",
|
||||||
"first_name": "Neil",
|
"first_name": "Neil",
|
||||||
"last_name": "Martinsen-Burrell",
|
"last_name": "Martinsen-Burrell",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"username": "7185e6cd-d3c8-4adc-90a3-ceddba71d24f",
|
||||||
|
"first_name": "Jon",
|
||||||
|
"last_name": "Roberts",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.1.6 on 2023-05-08 12:48
|
# Generated by Django 4.1.6 on 2023-05-08 15:30
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
@ -233,7 +233,7 @@ class Migration(migrations.Migration):
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"domain",
|
"domain",
|
||||||
models.ForeignKey(
|
models.OneToOneField(
|
||||||
blank=True,
|
blank=True,
|
||||||
help_text="Domain to which this information belongs",
|
help_text="Domain to which this information belongs",
|
||||||
null=True,
|
null=True,
|
||||||
|
@ -242,6 +242,17 @@ class Migration(migrations.Migration):
|
||||||
to="registrar.domain",
|
to="registrar.domain",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"domain_application",
|
||||||
|
models.OneToOneField(
|
||||||
|
blank=True,
|
||||||
|
help_text="Associated domain application",
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.PROTECT,
|
||||||
|
related_name="domainapplication_info",
|
||||||
|
to="registrar.domainapplication",
|
||||||
|
),
|
||||||
|
),
|
||||||
(
|
(
|
||||||
"investigator",
|
"investigator",
|
||||||
models.ForeignKey(
|
models.ForeignKey(
|
||||||
|
|
|
@ -527,7 +527,7 @@ class DomainApplication(TimeStampedModel):
|
||||||
# remove PK from domainapplication as it use different PK
|
# remove PK from domainapplication as it use different PK
|
||||||
# for domain/domaininformation
|
# for domain/domaininformation
|
||||||
|
|
||||||
domain_info, _ = DomainInformation.create_from_da_dict(domain_info)
|
domain_info = DomainInformation.create_from_da(self)
|
||||||
|
|
||||||
# create the permission for the user
|
# create the permission for the user
|
||||||
UserDomainRole = apps.get_model("registrar.UserDomainRole")
|
UserDomainRole = apps.get_model("registrar.UserDomainRole")
|
||||||
|
@ -595,7 +595,7 @@ class DomainApplication(TimeStampedModel):
|
||||||
# import pdb; pdb.set_trace()
|
# import pdb; pdb.set_trace()
|
||||||
if field.get_internal_type() in ("ForeignKey", "OneToOneField"):
|
if field.get_internal_type() in ("ForeignKey", "OneToOneField"):
|
||||||
# get the related instance of the FK value
|
# get the related instance of the FK value
|
||||||
print(f"{field.name}: ID: {field.value_from_object(instance)}")
|
# print(f"{field.name}: ID: {field.value_from_object(instance)}")
|
||||||
fk_id = field.value_from_object(instance)
|
fk_id = field.value_from_object(instance)
|
||||||
if fk_id:
|
if fk_id:
|
||||||
data[field.name] = field.related_model.objects.get(id=fk_id)
|
data[field.name] = field.related_model.objects.get(id=fk_id)
|
||||||
|
|
|
@ -13,7 +13,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class DomainInformation(TimeStampedModel):
|
class DomainInformation(TimeStampedModel):
|
||||||
|
|
||||||
"""A registrant's application for a new domain."""
|
"""A registrant's domain information for that domain, exported from DomainApplication."""
|
||||||
|
|
||||||
class StateTerritoryChoices(models.TextChoices):
|
class StateTerritoryChoices(models.TextChoices):
|
||||||
ALABAMA = "AL", "Alabama (AL)"
|
ALABAMA = "AL", "Alabama (AL)"
|
||||||
|
@ -264,6 +264,16 @@ class DomainInformation(TimeStampedModel):
|
||||||
related_name="information_investigating",
|
related_name="information_investigating",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
domain_application = models.OneToOneField(
|
||||||
|
"registrar.DomainApplication",
|
||||||
|
on_delete=models.PROTECT,
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
related_name="domainapplication_info",
|
||||||
|
help_text="Associated domain application",
|
||||||
|
unique=True
|
||||||
|
)
|
||||||
|
|
||||||
# ##### data fields from the initial form #####
|
# ##### data fields from the initial form #####
|
||||||
organization_type = models.CharField(
|
organization_type = models.CharField(
|
||||||
max_length=255,
|
max_length=255,
|
||||||
|
@ -370,7 +380,7 @@ class DomainInformation(TimeStampedModel):
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
)
|
)
|
||||||
|
|
||||||
domain = models.ForeignKey(
|
domain = models.OneToOneField(
|
||||||
"registrar.Domain",
|
"registrar.Domain",
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
blank=True,
|
blank=True,
|
||||||
|
@ -440,10 +450,15 @@ class DomainInformation(TimeStampedModel):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_from_da_dict(cls, da_dict):
|
def create_from_da(cls, domain_application):
|
||||||
"""Takes in a DomainApplication dict and converts it into DomainInformation"""
|
"""Takes in a DomainApplication dict and converts it into DomainInformation"""
|
||||||
# we don't want to pass the id to avoid conflicts
|
da_dict = domain_application.to_dict()
|
||||||
da_dict.pop("id")
|
# remove the id so one can be assinged on creation
|
||||||
|
da_id = da_dict.pop("id")
|
||||||
|
# check if we have a record that corresponds with the domain application, if so short circuit the create
|
||||||
|
domain_info = cls.objects.filter(domain_application__id=da_id).first()
|
||||||
|
if domain_info:
|
||||||
|
return domain_info
|
||||||
# the following information below is not needed in the domain information:
|
# the following information below is not needed in the domain information:
|
||||||
da_dict.pop("status")
|
da_dict.pop("status")
|
||||||
da_dict.pop("current_websites")
|
da_dict.pop("current_websites")
|
||||||
|
@ -452,7 +467,7 @@ class DomainInformation(TimeStampedModel):
|
||||||
other_contacts = da_dict.pop("other_contacts")
|
other_contacts = da_dict.pop("other_contacts")
|
||||||
alternative_domains = da_dict.pop("alternative_domains") #just in case
|
alternative_domains = da_dict.pop("alternative_domains") #just in case
|
||||||
domain_info = cls(**da_dict)
|
domain_info = cls(**da_dict)
|
||||||
|
domain_info.domain_application = domain_application
|
||||||
#Save so the object now have PK (needed to process the manytomany below before first)
|
#Save so the object now have PK (needed to process the manytomany below before first)
|
||||||
domain_info.save()
|
domain_info.save()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue