fix script

This commit is contained in:
zandercymatics 2024-04-08 14:59:07 -06:00
parent 212d2002e3
commit a976171179
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
4 changed files with 25 additions and 14 deletions

View file

@ -1,12 +1,10 @@
import argparse import argparse
import logging import logging
import os import os
from registrar.signals import create_or_update_organization_type
from typing import List from typing import List
from django.core.management import BaseCommand from django.core.management import BaseCommand
from registrar.management.commands.utility.terminal_helper import TerminalColors, TerminalHelper, ScriptDataHelper from registrar.management.commands.utility.terminal_helper import TerminalColors, TerminalHelper, ScriptDataHelper
from registrar.models import DomainInformation, DomainRequest, Domain from registrar.models import DomainInformation, DomainRequest
from django.db import transaction
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -95,12 +93,8 @@ class Command(BaseCommand):
if request.generic_org_type is not None: if request.generic_org_type is not None:
domain_name = request.requested_domain.name domain_name = request.requested_domain.name
request.is_election_board = domain_name in self.domains_with_election_offices_set request.is_election_board = domain_name in self.domains_with_election_offices_set
if not new_request: request.sync_organization_type()
self.request_skipped.append(request) self.request_to_update.append(request)
logger.warning(f"Skipped updating {request}. No changes to be made.")
else:
request = new_request
self.request_to_update.append(request)
if debug: if debug:
logger.info(f"Updating {request} => {request.organization_type}") logger.info(f"Updating {request} => {request.organization_type}")
@ -130,6 +124,7 @@ class Command(BaseCommand):
if info.generic_org_type is not None: if info.generic_org_type is not None:
domain_name = info.domain.name domain_name = info.domain.name
info.is_election_board = domain_name in self.domains_with_election_offices_set info.is_election_board = domain_name in self.domains_with_election_offices_set
info = info.sync_organization_type()
self.di_to_update.append(info) self.di_to_update.append(info)
if debug: if debug:
logger.info(f"Updating {info} => {info.organization_type}") logger.info(f"Updating {info} => {info.organization_type}")

View file

@ -49,6 +49,7 @@ class ScriptDataHelper:
Usage: Usage:
bulk_update_fields(Domain, page.object_list, ["first_ready"]) bulk_update_fields(Domain, page.object_list, ["first_ready"])
""" """
logger.info(f"{TerminalColors.YELLOW} Bulk updating fields... {TerminalColors.ENDC}")
# Create a Paginator object. Bulk_update on the full dataset # Create a Paginator object. Bulk_update on the full dataset
# is too memory intensive for our current app config, so we can chunk this data instead. # is too memory intensive for our current app config, so we can chunk this data instead.
paginator = Paginator(update_list, batch_size) paginator = Paginator(update_list, batch_size)

View file

@ -236,8 +236,11 @@ class DomainInformation(TimeStampedModel):
except Exception: except Exception:
return "" return ""
def save(self, *args, **kwargs): def sync_organization_type(self):
"""Save override for custom properties""" """
Updates the organization_type (without saving) to match
the is_election_board and generic_organization_type fields.
"""
# Define mappings between generic org and election org. # Define mappings between generic org and election org.
# These have to be defined here, as you'd get a cyclical import error # These have to be defined here, as you'd get a cyclical import error
@ -262,6 +265,12 @@ class DomainInformation(TimeStampedModel):
# Actually updates the organization_type field # Actually updates the organization_type field
org_type_helper.create_or_update_organization_type() org_type_helper.create_or_update_organization_type()
return self
def save(self, *args, **kwargs):
"""Save override for custom properties"""
self.sync_organization_type()
super().save(*args, **kwargs) super().save(*args, **kwargs)
@classmethod @classmethod

View file

@ -666,9 +666,11 @@ class DomainRequest(TimeStampedModel):
help_text="Notes about this request", help_text="Notes about this request",
) )
def save(self, *args, **kwargs): def sync_organization_type(self):
"""Save override for custom properties""" """
Updates the organization_type (without saving) to match
the is_election_board and generic_organization_type fields.
"""
# Define mappings between generic org and election org. # Define mappings between generic org and election org.
# These have to be defined here, as you'd get a cyclical import error # These have to be defined here, as you'd get a cyclical import error
# otherwise. # otherwise.
@ -692,6 +694,10 @@ class DomainRequest(TimeStampedModel):
# Actually updates the organization_type field # Actually updates the organization_type field
org_type_helper.create_or_update_organization_type() org_type_helper.create_or_update_organization_type()
def save(self, *args, **kwargs):
"""Save override for custom properties"""
self.sync_organization_type()
super().save(*args, **kwargs) super().save(*args, **kwargs)
def __str__(self): def __str__(self):