mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
fix script
This commit is contained in:
parent
212d2002e3
commit
a976171179
4 changed files with 25 additions and 14 deletions
|
@ -1,12 +1,10 @@
|
|||
import argparse
|
||||
import logging
|
||||
import os
|
||||
from registrar.signals import create_or_update_organization_type
|
||||
from typing import List
|
||||
from django.core.management import BaseCommand
|
||||
from registrar.management.commands.utility.terminal_helper import TerminalColors, TerminalHelper, ScriptDataHelper
|
||||
from registrar.models import DomainInformation, DomainRequest, Domain
|
||||
from django.db import transaction
|
||||
from registrar.models import DomainInformation, DomainRequest
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -95,11 +93,7 @@ class Command(BaseCommand):
|
|||
if request.generic_org_type is not None:
|
||||
domain_name = request.requested_domain.name
|
||||
request.is_election_board = domain_name in self.domains_with_election_offices_set
|
||||
if not new_request:
|
||||
self.request_skipped.append(request)
|
||||
logger.warning(f"Skipped updating {request}. No changes to be made.")
|
||||
else:
|
||||
request = new_request
|
||||
request.sync_organization_type()
|
||||
self.request_to_update.append(request)
|
||||
|
||||
if debug:
|
||||
|
@ -130,6 +124,7 @@ class Command(BaseCommand):
|
|||
if info.generic_org_type is not None:
|
||||
domain_name = info.domain.name
|
||||
info.is_election_board = domain_name in self.domains_with_election_offices_set
|
||||
info = info.sync_organization_type()
|
||||
self.di_to_update.append(info)
|
||||
if debug:
|
||||
logger.info(f"Updating {info} => {info.organization_type}")
|
||||
|
|
|
@ -49,6 +49,7 @@ class ScriptDataHelper:
|
|||
Usage:
|
||||
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
|
||||
# is too memory intensive for our current app config, so we can chunk this data instead.
|
||||
paginator = Paginator(update_list, batch_size)
|
||||
|
|
|
@ -236,8 +236,11 @@ class DomainInformation(TimeStampedModel):
|
|||
except Exception:
|
||||
return ""
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""Save override for custom properties"""
|
||||
def sync_organization_type(self):
|
||||
"""
|
||||
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.
|
||||
# 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
|
||||
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)
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -666,9 +666,11 @@ class DomainRequest(TimeStampedModel):
|
|||
help_text="Notes about this request",
|
||||
)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""Save override for custom properties"""
|
||||
|
||||
def sync_organization_type(self):
|
||||
"""
|
||||
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.
|
||||
# These have to be defined here, as you'd get a cyclical import error
|
||||
# otherwise.
|
||||
|
@ -692,6 +694,10 @@ class DomainRequest(TimeStampedModel):
|
|||
|
||||
# Actually updates the organization_type field
|
||||
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)
|
||||
|
||||
def __str__(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue