mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-04 08:52:16 +02:00
Finish script
This commit is contained in:
parent
e91c160a67
commit
d68ccdc1b1
1 changed files with 12 additions and 9 deletions
|
@ -2,8 +2,6 @@ import logging
|
|||
from django.core.management import BaseCommand
|
||||
from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalColors, TerminalHelper
|
||||
from registrar.models import DomainRequest
|
||||
from django.db.models import F
|
||||
|
||||
from registrar.models.utility.generic_helper import normalize_string
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -15,7 +13,12 @@ class Command(BaseCommand, PopulateScriptTemplate):
|
|||
def handle(self, **kwargs):
|
||||
"""Loops through each DomainRequest object and populates
|
||||
its last_status_update and first_submitted_date values"""
|
||||
filter_conditions = {"portfolio__isnull": False, "sub_organization__isnull": True}
|
||||
filter_conditions = {
|
||||
"portfolio__isnull": False,
|
||||
"organization_name__isnull": False,
|
||||
"sub_organization__isnull": True,
|
||||
"portfolio__organization_name__isnull": False,
|
||||
}
|
||||
fields_to_update = ["requested_suborganization", "suborganization_city", "suborganization_state_territory"]
|
||||
self.mass_update_records(DomainRequest, filter_conditions, fields_to_update)
|
||||
|
||||
|
@ -29,15 +32,10 @@ class Command(BaseCommand, PopulateScriptTemplate):
|
|||
f"sub_city: {record.city}, suborg_state_territory: {record.state_territory}."
|
||||
)
|
||||
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKBLUE, message)
|
||||
|
||||
|
||||
def should_skip_record(self, record) -> bool:
|
||||
"""Skips updating the record if the portfolio name is the same as the org name,
|
||||
or if we are trying to update a record in an invalid status."""
|
||||
portfolio_normalized = normalize_string(record.portfolio.organization_name)
|
||||
org_normalized = normalize_string(record.organization_name)
|
||||
if portfolio_normalized == org_normalized:
|
||||
return True
|
||||
|
||||
invalid_statuses = [
|
||||
DomainRequest.DomainRequestStatus.APPROVED,
|
||||
DomainRequest.DomainRequestStatus.REJECTED,
|
||||
|
@ -47,4 +45,9 @@ class Command(BaseCommand, PopulateScriptTemplate):
|
|||
if record.status in invalid_statuses:
|
||||
return True
|
||||
|
||||
portfolio_normalized = normalize_string(record.portfolio.organization_name)
|
||||
org_normalized = normalize_string(record.organization_name)
|
||||
if portfolio_normalized == org_normalized:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue