mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-12 20:49:41 +02:00
added domain invitation entries
Signed-off-by: CocoByte <nicolle.leclair@gmail.com>
This commit is contained in:
parent
688b5742c9
commit
604821ad07
1 changed files with 96 additions and 74 deletions
|
@ -9,6 +9,7 @@ from django.core.management import BaseCommand
|
||||||
|
|
||||||
from registrar.models import TransitionDomain
|
from registrar.models import TransitionDomain
|
||||||
from registrar.models import Domain
|
from registrar.models import Domain
|
||||||
|
from registrar.models import DomainInvitation
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ class termColors:
|
||||||
OKBLUE = "\033[94m"
|
OKBLUE = "\033[94m"
|
||||||
OKCYAN = "\033[96m"
|
OKCYAN = "\033[96m"
|
||||||
OKGREEN = "\033[92m"
|
OKGREEN = "\033[92m"
|
||||||
WARNING = "\033[93m"
|
YELLOW = "\033[93m"
|
||||||
FAIL = "\033[91m"
|
FAIL = "\033[91m"
|
||||||
ENDC = "\033[0m"
|
ENDC = "\033[0m"
|
||||||
BOLD = "\033[1m"
|
BOLD = "\033[1m"
|
||||||
|
@ -29,25 +30,53 @@ class termColors:
|
||||||
BackgroundLightYellow = "\033[103m"
|
BackgroundLightYellow = "\033[103m"
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------
|
def print_debug_mode_statements(self,
|
||||||
# MAIN SCRIPT
|
debug_on: bool,
|
||||||
# ----------------------------------------
|
debug_max_entries_to_parse: int):
|
||||||
|
"""Prints additional terminal statements to indicate if --debug
|
||||||
|
or --limitParse are in use"""
|
||||||
|
if debug_on:
|
||||||
|
logger.info(
|
||||||
|
f"""{termColors.OKCYAN}
|
||||||
|
----------DEBUG MODE ON----------
|
||||||
|
Detailed print statements activated.
|
||||||
|
{termColors.ENDC}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
if debug_max_entries_to_parse > 0:
|
||||||
|
logger.info(
|
||||||
|
f"""{termColors.OKCYAN}
|
||||||
|
----------LIMITER ON----------
|
||||||
|
Parsing of entries will be limited to
|
||||||
|
{debug_max_entries_to_parse} lines per file.")
|
||||||
|
Detailed print statements activated.
|
||||||
|
{termColors.ENDC}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = """Load data from transition domain tables
|
help = """Load data from transition domain tables
|
||||||
into main domain tables."""
|
into main domain tables. Also create domain invitation
|
||||||
|
entries for every domain we ADD (but not for domains
|
||||||
|
we UPDATE)"""
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument("--debug", action=argparse.BooleanOptionalAction)
|
parser.add_argument("--debug", action=argparse.BooleanOptionalAction)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--limitParse", default=0, help="Sets max number of entries to load"
|
"--limitParse",
|
||||||
|
default=0,
|
||||||
|
help="Sets max number of entries to load, set to 0 to load all entries"
|
||||||
)
|
)
|
||||||
|
|
||||||
def handle( # noqa: C901
|
def handle( # noqa: C901
|
||||||
self,
|
self,
|
||||||
**options,
|
**options,
|
||||||
):
|
):
|
||||||
"""Load the data files and create the DomainInvitations."""
|
"""Parse entries in TransitionDomain table
|
||||||
|
and create (or update) corresponding entries in the
|
||||||
|
Domain and DomainInvitation tables."""
|
||||||
|
|
||||||
# grab command line arguments and store locally...
|
# grab command line arguments and store locally...
|
||||||
debug_on = options.get("debug")
|
debug_on = options.get("debug")
|
||||||
|
@ -58,7 +87,8 @@ class Command(BaseCommand):
|
||||||
self.print_debug_mode_statements(debug_on, debug_max_entries_to_parse)
|
self.print_debug_mode_statements(debug_on, debug_max_entries_to_parse)
|
||||||
|
|
||||||
# domains to ADD
|
# domains to ADD
|
||||||
to_create = []
|
domains_to_create = []
|
||||||
|
domain_invitations_to_create = []
|
||||||
# domains we UPDATED
|
# domains we UPDATED
|
||||||
updated_domain_entries = []
|
updated_domain_entries = []
|
||||||
# domains we SKIPPED
|
# domains we SKIPPED
|
||||||
|
@ -69,24 +99,25 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"""{termColors.OKGREEN}
|
f"""{termColors.OKGREEN}
|
||||||
==========================
|
==========================
|
||||||
Beginning Data Transfer
|
Beginning Data Transfer
|
||||||
==========================
|
==========================
|
||||||
{termColors.ENDC}"""
|
{termColors.ENDC}"""
|
||||||
)
|
)
|
||||||
|
|
||||||
for transition_entry in TransitionDomain.objects.all():
|
for transition_entry in TransitionDomain.objects.all():
|
||||||
transition_domain_name = transition_entry.domain_name
|
transition_domain_name = transition_entry.domain_name
|
||||||
transition_domain_status = transition_entry.status
|
transition_domain_status = transition_entry.status
|
||||||
|
transition_domain_email = transition_entry.username
|
||||||
|
|
||||||
# Check for existing domain entry
|
# Check for existing domain entry
|
||||||
try:
|
try:
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
if debug_on:
|
if debug_on:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"""{termColors.WARNING}
|
f"""{termColors.YELLOW}
|
||||||
Processing Transition Domain: {transition_domain_name}, {transition_domain_status}
|
Processing Transition Domain: {transition_domain_name}, {transition_domain_status}
|
||||||
{termColors.ENDC}"""
|
{termColors.ENDC}""" # noqa
|
||||||
)
|
)
|
||||||
|
|
||||||
# for existing entry, update the status to
|
# for existing entry, update the status to
|
||||||
|
@ -97,9 +128,9 @@ Processing Transition Domain: {transition_domain_name}, {transition_domain_statu
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
if debug_on:
|
if debug_on:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"""{termColors.WARNING}
|
f"""{termColors.YELLOW}
|
||||||
> Found existing domain entry for: {transition_domain_name}, {current_state}
|
> Found existing domain entry for: {transition_domain_name}, {current_state}
|
||||||
{termColors.ENDC}"""
|
{termColors.ENDC}""" # noqa
|
||||||
)
|
)
|
||||||
if transition_domain_status != current_state:
|
if transition_domain_status != current_state:
|
||||||
if (
|
if (
|
||||||
|
@ -114,30 +145,39 @@ Processing Transition Domain: {transition_domain_name}, {transition_domain_statu
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
if debug_on:
|
if debug_on:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"""{termColors.WARNING}
|
f"""{termColors.YELLOW}
|
||||||
>> Updated {transition_domain_name} state from
|
>> Updated {transition_domain_name} state from
|
||||||
'{current_state}' to '{existingEntry.state}{termColors.ENDC}'"""
|
'{current_state}' to '{existingEntry.state}{termColors.ENDC}'
|
||||||
|
(no domain invitation entry added)"""
|
||||||
)
|
)
|
||||||
except Domain.DoesNotExist:
|
except Domain.DoesNotExist:
|
||||||
# no matching entry, make one
|
# no matching entry, make one
|
||||||
newEntry = Domain(
|
newEntry = Domain(
|
||||||
name=transition_domain_name, state=transition_domain_status
|
name=transition_domain_name,
|
||||||
|
state=transition_domain_status
|
||||||
|
)
|
||||||
|
domains_to_create.append(newEntry)
|
||||||
|
|
||||||
|
domain_invitations_to_create.append(
|
||||||
|
DomainInvitation(
|
||||||
|
email=transition_domain_email.lower(),
|
||||||
|
domain=transition_domain_name
|
||||||
|
)
|
||||||
)
|
)
|
||||||
to_create.append(newEntry)
|
|
||||||
|
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
if debug_on:
|
if debug_on:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"{termColors.OKCYAN} Adding entry: {newEntry} {termColors.ENDC}" # noqa
|
f"{termColors.OKCYAN} Adding domain AND domain invitation: {newEntry} {termColors.ENDC}" # noqa
|
||||||
)
|
)
|
||||||
except Domain.MultipleObjectsReturned:
|
except Domain.MultipleObjectsReturned:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"""
|
f"""
|
||||||
{termColors.FAIL}
|
{termColors.FAIL}
|
||||||
!!! ERROR: duplicate entries exist in the
|
!!! ERROR: duplicate entries exist in the
|
||||||
Domain table for domain:
|
Domain table for domain:
|
||||||
{transition_domain_name}
|
{transition_domain_name}
|
||||||
----------TERMINATING----------"""
|
----------TERMINATING----------"""
|
||||||
)
|
)
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -146,10 +186,10 @@ Domain table for domain:
|
||||||
skipped_domain_entries.append(transition_domain_name)
|
skipped_domain_entries.append(transition_domain_name)
|
||||||
logger.info(
|
logger.info(
|
||||||
f"""{termColors.FAIL}
|
f"""{termColors.FAIL}
|
||||||
Unable to change state for {transition_domain_name}
|
Unable to change state for {transition_domain_name}
|
||||||
TRANSITION NOT ALLOWED error message (internal):
|
TRANSITION NOT ALLOWED error message (internal):
|
||||||
{err}
|
{err}
|
||||||
----------SKIPPING----------"""
|
----------SKIPPING----------"""
|
||||||
)
|
)
|
||||||
|
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
|
@ -159,71 +199,53 @@ Unable to change state for {transition_domain_name}
|
||||||
and debug_max_entries_to_parse != 0
|
and debug_max_entries_to_parse != 0
|
||||||
):
|
):
|
||||||
logger.info(
|
logger.info(
|
||||||
f"""{termColors.WARNING}
|
f"""{termColors.YELLOW}
|
||||||
----PARSE LIMIT REACHED. HALTING PARSER.----
|
----PARSE LIMIT REACHED. HALTING PARSER.----
|
||||||
{termColors.ENDC}
|
{termColors.ENDC}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
|
|
||||||
Domain.objects.bulk_create(to_create)
|
Domain.objects.bulk_create(domains_to_create)
|
||||||
|
DomainInvitation.objects.bulk_create(domain_invitations_to_create)
|
||||||
|
|
||||||
total_new_entries = len(to_create)
|
total_new_entries = len(domains_to_create)
|
||||||
total_updated_domain_entries = len(updated_domain_entries)
|
total_updated_domain_entries = len(updated_domain_entries)
|
||||||
|
total_domain_invitation_entries = len(domain_invitations_to_create)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"""{termColors.OKGREEN}
|
f"""{termColors.OKGREEN}
|
||||||
|
============= FINISHED ===============
|
||||||
|
Created {total_new_entries} transition domain entries,
|
||||||
|
updated {total_updated_domain_entries} transition domain entries
|
||||||
|
|
||||||
============= FINISHED ===============
|
Created {total_domain_invitation_entries} domain invitation entries
|
||||||
Created {total_new_entries} transition domain entries,
|
(NOTE: no invitations are SENT in this script)
|
||||||
updated {total_updated_domain_entries} transition domain entries
|
{termColors.ENDC}
|
||||||
{termColors.ENDC}
|
"""
|
||||||
"""
|
|
||||||
)
|
)
|
||||||
if len(skipped_domain_entries) > 0:
|
if len(skipped_domain_entries) > 0:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"""{termColors.FAIL}
|
f"""{termColors.FAIL}
|
||||||
|
============= SKIPPED DOMAINS (ERRORS) ===============
|
||||||
============= SKIPPED DOMAINS (ERRORS) ===============
|
{skipped_domain_entries}
|
||||||
{skipped_domain_entries}
|
{termColors.ENDC}
|
||||||
{termColors.ENDC}
|
"""
|
||||||
"""
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
if debug_on:
|
if debug_on:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"""{termColors.WARNING}
|
f"""{termColors.YELLOW}
|
||||||
|
|
||||||
Created Domains:
|
Created Domains:
|
||||||
{to_create}
|
{domains_to_create}
|
||||||
|
|
||||||
Updated Domains:
|
Updated Domains:
|
||||||
{updated_domain_entries}
|
{updated_domain_entries}
|
||||||
|
|
||||||
{termColors.ENDC}
|
{termColors.ENDC}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
# ----------------------------------------
|
|
||||||
# HELPER FUNCTIONS
|
|
||||||
# ----------------------------------------
|
|
||||||
|
|
||||||
def print_debug_mode_statements(self, debug_on, debug_max_entries_to_parse):
|
|
||||||
if debug_on:
|
|
||||||
logger.info(
|
|
||||||
f"""{termColors.WARNING}
|
|
||||||
----------DEBUG MODE ON----------
|
|
||||||
Detailed print statements activated.
|
|
||||||
{termColors.ENDC}
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
if debug_max_entries_to_parse > 0:
|
|
||||||
logger.info(
|
|
||||||
f"""{termColors.OKCYAN}
|
|
||||||
----------LIMITER ON----------
|
|
||||||
Data transfer will be limited to
|
|
||||||
{debug_max_entries_to_parse} entries.")
|
|
||||||
{termColors.ENDC}
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue