mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-31 15:06:32 +02:00
add record counter
This commit is contained in:
parent
e4c2511ef3
commit
c7146601d3
2 changed files with 9 additions and 7 deletions
|
@ -75,9 +75,8 @@ class Command(BaseCommand, PopulateScriptTemplate):
|
||||||
record.street1 = "1110 N. Glebe Rd"
|
record.street1 = "1110 N. Glebe Rd"
|
||||||
record.pc = "22201"
|
record.pc = "22201"
|
||||||
record.email = DefaultEmail.PUBLIC_CONTACT_DEFAULT
|
record.email = DefaultEmail.PUBLIC_CONTACT_DEFAULT
|
||||||
logger.info(f"Updating default values for '{record}'.")
|
|
||||||
record.save()
|
record.save()
|
||||||
logger.info(f"Updated '{record}' in EPP.")
|
logger.info(f"{TerminalColors.OKCYAN}Updated '{record}' in EPP.{TerminalColors.ENDC}")
|
||||||
|
|
||||||
def should_skip_record(self, record) -> bool: # noqa
|
def should_skip_record(self, record) -> bool: # noqa
|
||||||
"""Skips updating a public contact if it contains different default info."""
|
"""Skips updating a public contact if it contains different default info."""
|
||||||
|
@ -86,7 +85,7 @@ class Command(BaseCommand, PopulateScriptTemplate):
|
||||||
f"Skipping legacy verisign contact '{record}'. "
|
f"Skipping legacy verisign contact '{record}'. "
|
||||||
f"The registry_id field has a length less than 16 characters."
|
f"The registry_id field has a length less than 16 characters."
|
||||||
)
|
)
|
||||||
logger.warning(f"{TerminalColors.OKCYAN}{message}{TerminalColors.ENDC}")
|
logger.warning(f"{TerminalColors.YELLOW}{message}{TerminalColors.ENDC}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
for key, expected_values in self.old_and_new_default_contact_values.items():
|
for key, expected_values in self.old_and_new_default_contact_values.items():
|
||||||
|
@ -97,6 +96,6 @@ class Command(BaseCommand, PopulateScriptTemplate):
|
||||||
f"The field '{key}' does not match the default.\n"
|
f"The field '{key}' does not match the default.\n"
|
||||||
f"Details: DB value - {record_field}, expected value(s) - {expected_values}"
|
f"Details: DB value - {record_field}, expected value(s) - {expected_values}"
|
||||||
)
|
)
|
||||||
logger.warning(f"{TerminalColors.OKCYAN}{message}{TerminalColors.ENDC}")
|
logger.warning(f"{TerminalColors.YELLOW}{message}{TerminalColors.ENDC}")
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -87,7 +87,7 @@ class PopulateScriptTemplate(ABC):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def mass_update_records(
|
def mass_update_records(
|
||||||
self, object_class, filter_conditions, fields_to_update, debug=True, verbose=False
|
self, object_class, filter_conditions, fields_to_update, debug=True, verbose=False, show_record_count=False
|
||||||
):
|
):
|
||||||
"""Loops through each valid "object_class" object - specified by filter_conditions - and
|
"""Loops through each valid "object_class" object - specified by filter_conditions - and
|
||||||
updates fields defined by fields_to_update using update_record.
|
updates fields defined by fields_to_update using update_record.
|
||||||
|
@ -117,13 +117,14 @@ class PopulateScriptTemplate(ABC):
|
||||||
|
|
||||||
# apply custom filter
|
# apply custom filter
|
||||||
records = self.custom_filter(records)
|
records = self.custom_filter(records)
|
||||||
|
records_length = len(records)
|
||||||
|
|
||||||
readable_class_name = self.get_class_name(object_class)
|
readable_class_name = self.get_class_name(object_class)
|
||||||
|
|
||||||
# for use in the execution prompt.
|
# for use in the execution prompt.
|
||||||
proposed_changes = (
|
proposed_changes = (
|
||||||
"==Proposed Changes==\n"
|
"==Proposed Changes==\n"
|
||||||
f"Number of {readable_class_name} objects to change: {len(records)}\n"
|
f"Number of {readable_class_name} objects to change: {len(records_length)}\n"
|
||||||
f"These fields will be updated on each record: {fields_to_update}"
|
f"These fields will be updated on each record: {fields_to_update}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -143,9 +144,11 @@ class PopulateScriptTemplate(ABC):
|
||||||
to_update: List[object_class] = []
|
to_update: List[object_class] = []
|
||||||
to_skip: List[object_class] = []
|
to_skip: List[object_class] = []
|
||||||
failed_to_update: List[object_class] = []
|
failed_to_update: List[object_class] = []
|
||||||
for record in records:
|
for i, record in enumerate(records, start=1):
|
||||||
try:
|
try:
|
||||||
if not self.should_skip_record(record):
|
if not self.should_skip_record(record):
|
||||||
|
if show_record_count:
|
||||||
|
logger.info(f"{TerminalColors.BOLD}Record {i}/{records_length}{TerminalColors.ENDC}")
|
||||||
self.update_record(record)
|
self.update_record(record)
|
||||||
to_update.append(record)
|
to_update.append(record)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue