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 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}")
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue