mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-13 16:04:49 +02:00
Remove country code
This commit is contained in:
parent
c86a9d5fff
commit
13b1ca0238
4 changed files with 23 additions and 32 deletions
|
@ -51,7 +51,6 @@ class Command(BaseCommand):
|
||||||
"city",
|
"city",
|
||||||
"state_territory",
|
"state_territory",
|
||||||
"zipcode",
|
"zipcode",
|
||||||
"country_code",
|
|
||||||
]
|
]
|
||||||
proceed = TerminalHelper.prompt_for_execution(
|
proceed = TerminalHelper.prompt_for_execution(
|
||||||
system_exit_on_terminate=True,
|
system_exit_on_terminate=True,
|
||||||
|
@ -122,43 +121,48 @@ class Command(BaseCommand):
|
||||||
di_to_update = []
|
di_to_update = []
|
||||||
di_failed_to_update = []
|
di_failed_to_update = []
|
||||||
|
|
||||||
# Fetch all TransitionDomains in one query
|
# Grab each TransitionDomain we want to change. Store it.
|
||||||
|
# Fetches all TransitionDomains in one query.
|
||||||
transition_domains = TransitionDomain.objects.filter(
|
transition_domains = TransitionDomain.objects.filter(
|
||||||
username__in=[item.username for item in desired_objects],
|
username__in=[item.username for item in desired_objects],
|
||||||
domain_name__in=[item.domain_name for item in desired_objects]
|
domain_name__in=[item.domain_name for item in desired_objects]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Fetch all Domains in one query
|
if len(desired_objects) != len(transition_domains):
|
||||||
|
raise Exception("Could not find all desired TransitionDomains")
|
||||||
|
|
||||||
|
# Then, for each domain_name grab the associated domain object.
|
||||||
|
# Fetches all Domains in one query.
|
||||||
domains = Domain.objects.filter(
|
domains = Domain.objects.filter(
|
||||||
name__in=[td.domain_name for td in transition_domains]
|
name__in=[td.domain_name for td in transition_domains]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Fetch all DomainInformations in one query
|
# Then, use each domain object to map domain <--> DomainInformation
|
||||||
|
# Fetches all DomainInformations in one query.
|
||||||
domain_informations = DomainInformation.objects.filter(
|
domain_informations = DomainInformation.objects.filter(
|
||||||
domain__in=domains
|
domain__in=domains
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create dictionaries for faster lookup
|
# Create dictionaries for faster lookup
|
||||||
transition_domains_dict = {td.domain_name: td for td in transition_domains}
|
|
||||||
domains_dict = {d.name: d for d in domains}
|
domains_dict = {d.name: d for d in domains}
|
||||||
domain_informations_dict = {di.domain.name: di for di in domain_informations}
|
domain_informations_dict = {di.domain.name: di for di in domain_informations}
|
||||||
|
|
||||||
for item in desired_objects:
|
for item in transition_domains:
|
||||||
try:
|
try:
|
||||||
current_transition_domain = transition_domains_dict[item.domain_name]
|
# Grab the current Domain. This ensures we are pointing towards the right place.
|
||||||
current_domain = domains_dict[current_transition_domain.domain_name]
|
current_domain = domains_dict[item.domain_name]
|
||||||
|
|
||||||
|
# Based on the current domain, grab the right DomainInformation object.
|
||||||
current_domain_information = domain_informations_dict[current_domain.name]
|
current_domain_information = domain_informations_dict[current_domain.name]
|
||||||
|
|
||||||
# TODO - add verification to each, for instance check address_line length
|
current_domain_information.address_line1 = item.address_line
|
||||||
current_domain_information.address_line1 = current_transition_domain.address_line
|
current_domain_information.city = item.city
|
||||||
current_domain_information.city = current_transition_domain.city
|
current_domain_information.state_territory = item.state_territory
|
||||||
current_domain_information.state_territory = current_transition_domain.state_territory
|
current_domain_information.zipcode = item.zipcode
|
||||||
current_domain_information.zipcode = current_transition_domain.zipcode
|
|
||||||
# TODO - Country Code
|
|
||||||
#current_domain_information.country_code = current_transition_domain.country_code
|
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
logger.info(f"Updating {current_domain.name}...")
|
logger.info(f"Updating {current_domain.name}...")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
di_failed_to_update.append(current_domain_information)
|
di_failed_to_update.append(current_domain_information)
|
||||||
|
@ -192,7 +196,6 @@ class Command(BaseCommand):
|
||||||
"city",
|
"city",
|
||||||
"state_territory",
|
"state_territory",
|
||||||
"zipcode",
|
"zipcode",
|
||||||
#"country_code",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
DomainInformation.objects.bulk_update(di_to_update, changed_fields)
|
DomainInformation.objects.bulk_update(di_to_update, changed_fields)
|
||||||
|
|
|
@ -804,6 +804,7 @@ class OrganizationDataLoader:
|
||||||
if self.debug:
|
if self.debug:
|
||||||
logger.info(item.display_transition_domain())
|
logger.info(item.display_transition_domain())
|
||||||
logger.info(
|
logger.info(
|
||||||
|
f"Successfully updated TransitionDomain: \n"
|
||||||
f"{TerminalColors.OKCYAN}"
|
f"{TerminalColors.OKCYAN}"
|
||||||
f"{item.display_transition_domain()}"
|
f"{item.display_transition_domain()}"
|
||||||
f"{TerminalColors.ENDC}"
|
f"{TerminalColors.ENDC}"
|
||||||
|
@ -813,6 +814,7 @@ class OrganizationDataLoader:
|
||||||
self.tds_failed_to_update.append(item)
|
self.tds_failed_to_update.append(item)
|
||||||
if self.debug:
|
if self.debug:
|
||||||
logger.error(
|
logger.error(
|
||||||
|
f"Failed to update TransitionDomain: \n"
|
||||||
f"{TerminalColors.YELLOW}"
|
f"{TerminalColors.YELLOW}"
|
||||||
f"{item.display_transition_domain()}"
|
f"{item.display_transition_domain()}"
|
||||||
f"{TerminalColors.ENDC}"
|
f"{TerminalColors.ENDC}"
|
||||||
|
@ -846,7 +848,6 @@ class OrganizationDataLoader:
|
||||||
"city",
|
"city",
|
||||||
"state_territory",
|
"state_territory",
|
||||||
"zipcode",
|
"zipcode",
|
||||||
"country_code",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
TransitionDomain.objects.bulk_update(update_list, changed_fields)
|
TransitionDomain.objects.bulk_update(update_list, changed_fields)
|
||||||
|
@ -886,15 +887,14 @@ class OrganizationDataLoader:
|
||||||
transition_domain.city = org_info.orgcity
|
transition_domain.city = org_info.orgcity
|
||||||
transition_domain.state_territory = org_info.orgstate
|
transition_domain.state_territory = org_info.orgstate
|
||||||
transition_domain.zipcode = org_info.orgzip
|
transition_domain.zipcode = org_info.orgzip
|
||||||
transition_domain.country_code = org_info.orgcountrycode
|
|
||||||
|
|
||||||
# Log what happened to each field
|
# Log what happened to each field. The first value
|
||||||
|
# is the field name that was updated, second is the value
|
||||||
changed_fields = [
|
changed_fields = [
|
||||||
("address_line", transition_domain.address_line),
|
("address_line", transition_domain.address_line),
|
||||||
("city", transition_domain.city),
|
("city", transition_domain.city),
|
||||||
("state_territory", transition_domain.state_territory),
|
("state_territory", transition_domain.state_territory),
|
||||||
("zipcode", transition_domain.zipcode),
|
("zipcode", transition_domain.zipcode),
|
||||||
("country_code", transition_domain.country_code),
|
|
||||||
]
|
]
|
||||||
self.log_add_or_changed_values(EnumFilenames.AUTHORITY_ADHOC, changed_fields, domain_name)
|
self.log_add_or_changed_values(EnumFilenames.AUTHORITY_ADHOC, changed_fields, domain_name)
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,6 @@ class Migration(migrations.Migration):
|
||||||
name="city",
|
name="city",
|
||||||
field=models.TextField(blank=True, help_text="City", null=True),
|
field=models.TextField(blank=True, help_text="City", null=True),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
|
||||||
model_name="transitiondomain",
|
|
||||||
name="country_code",
|
|
||||||
field=models.CharField(blank=True, help_text="Country code", max_length=2, null=True),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name="transitiondomain",
|
model_name="transitiondomain",
|
||||||
name="state_territory",
|
name="state_territory",
|
||||||
|
|
|
@ -128,12 +128,6 @@ class TransitionDomain(TimeStampedModel):
|
||||||
help_text="Zip code",
|
help_text="Zip code",
|
||||||
db_index=True,
|
db_index=True,
|
||||||
)
|
)
|
||||||
country_code = models.CharField(
|
|
||||||
max_length=2,
|
|
||||||
null=True,
|
|
||||||
blank=True,
|
|
||||||
help_text="Country code",
|
|
||||||
)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.username}, {self.domain_name}"
|
return f"{self.username}, {self.domain_name}"
|
||||||
|
@ -161,5 +155,4 @@ class TransitionDomain(TimeStampedModel):
|
||||||
f"city: {self.city}, \n"
|
f"city: {self.city}, \n"
|
||||||
f"state_territory: {self.state_territory}, \n"
|
f"state_territory: {self.state_territory}, \n"
|
||||||
f"zipcode: {self.zipcode}, \n"
|
f"zipcode: {self.zipcode}, \n"
|
||||||
f"country_code: {self.country_code}, \n"
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue