mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-11 20:19:38 +02:00
lint part 2
This commit is contained in:
parent
af7ce078bd
commit
4612154243
1 changed files with 86 additions and 67 deletions
|
@ -106,7 +106,7 @@ class Command(BaseCommand):
|
||||||
TerminalHelper.colorful_logger(logger.info, TerminalColors.FAIL, message)
|
TerminalHelper.colorful_logger(logger.info, TerminalColors.FAIL, message)
|
||||||
|
|
||||||
# POST PROCESS STEP: Add additional suborg info where applicable.
|
# POST PROCESS STEP: Add additional suborg info where applicable.
|
||||||
updated_suborg_count = self.post_process_suborganization_fields(agencies)
|
updated_suborg_count = self.post_process_all_suborganization_fields(agencies)
|
||||||
message = f"Added city and state_territory information to {updated_suborg_count} suborgs."
|
message = f"Added city and state_territory information to {updated_suborg_count} suborgs."
|
||||||
TerminalHelper.colorful_logger(logger.info, TerminalColors.MAGENTA, message)
|
TerminalHelper.colorful_logger(logger.info, TerminalColors.MAGENTA, message)
|
||||||
|
|
||||||
|
@ -355,10 +355,16 @@ class Command(BaseCommand):
|
||||||
message = f"Added portfolio '{portfolio}' to {len(domain_infos)} domains."
|
message = f"Added portfolio '{portfolio}' to {len(domain_infos)} domains."
|
||||||
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKGREEN, message)
|
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKGREEN, message)
|
||||||
|
|
||||||
def post_process_suborganization_fields(self, agencies):
|
def post_process_all_suborganization_fields(self, agencies):
|
||||||
"""Updates suborganization city/state fields from domain and request data.
|
"""Batch updates suborganization locations from domain and request data.
|
||||||
|
|
||||||
Priority order for data:
|
Args:
|
||||||
|
agencies: List of FederalAgency objects to process
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: Number of suborganizations updated
|
||||||
|
|
||||||
|
Priority for location data:
|
||||||
1. Domain information
|
1. Domain information
|
||||||
2. Domain request suborganization fields
|
2. Domain request suborganization fields
|
||||||
3. Domain request standard fields
|
3. Domain request standard fields
|
||||||
|
@ -407,6 +413,22 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
# Fourth: Process each suborg to add city / state territory info
|
# Fourth: Process each suborg to add city / state territory info
|
||||||
for suborg in suborgs_to_edit:
|
for suborg in suborgs_to_edit:
|
||||||
|
self.post_process_suborganization_fields(suborg, domains_dict, requests_dict)
|
||||||
|
|
||||||
|
# Fifth: Perform a bulk update
|
||||||
|
return Suborganization.objects.bulk_update(suborgs_to_edit, ["city", "state_territory"])
|
||||||
|
|
||||||
|
def post_process_suborganization_fields(self, suborg, domains_dict, requests_dict):
|
||||||
|
"""Updates a single suborganization's location data if valid.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
suborg: Suborganization to update
|
||||||
|
domains_dict: Dict of domain info records grouped by org name
|
||||||
|
requests_dict: Dict of domain requests grouped by org name
|
||||||
|
|
||||||
|
Priority matches parent method. Updates are skipped if location data conflicts
|
||||||
|
between multiple records of the same type.
|
||||||
|
"""
|
||||||
normalized_suborg_name = normalize_string(suborg.name)
|
normalized_suborg_name = normalize_string(suborg.name)
|
||||||
domains = domains_dict.get(normalized_suborg_name, [])
|
domains = domains_dict.get(normalized_suborg_name, [])
|
||||||
requests = requests_dict.get(normalized_suborg_name, [])
|
requests = requests_dict.get(normalized_suborg_name, [])
|
||||||
|
@ -449,7 +471,7 @@ class Command(BaseCommand):
|
||||||
if not domain and not request:
|
if not domain and not request:
|
||||||
message = f"Skipping adding city / state_territory information to suborg: {suborg}. Bad data."
|
message = f"Skipping adding city / state_territory information to suborg: {suborg}. Bad data."
|
||||||
TerminalHelper.colorful_logger(logger.warning, TerminalColors.YELLOW, message)
|
TerminalHelper.colorful_logger(logger.warning, TerminalColors.YELLOW, message)
|
||||||
continue
|
return
|
||||||
|
|
||||||
# PRIORITY:
|
# PRIORITY:
|
||||||
# 1. Domain info
|
# 1. Domain info
|
||||||
|
@ -470,6 +492,3 @@ class Command(BaseCommand):
|
||||||
f"city - {suborg.city}, state - {suborg.state_territory}"
|
f"city - {suborg.city}, state - {suborg.state_territory}"
|
||||||
)
|
)
|
||||||
TerminalHelper.colorful_logger(logger.info, TerminalColors.MAGENTA, message)
|
TerminalHelper.colorful_logger(logger.info, TerminalColors.MAGENTA, message)
|
||||||
|
|
||||||
# Fifth: Perform a bulk update
|
|
||||||
return Suborganization.objects.bulk_update(suborgs_to_edit, ["city", "state_territory"])
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue