script cleanup

This commit is contained in:
zandercymatics 2025-03-17 13:21:01 -06:00
parent 20bde7df39
commit e4c2511ef3
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 12 additions and 14 deletions

View file

@ -4152,7 +4152,7 @@ class PublicContactAdmin(ListHeaderAdmin, ImportExportModelAdmin):
change_form_template = "django/admin/email_clipboard_change_form.html"
autocomplete_fields = ["domain"]
list_display = ("registry_id", "contact_type", "domain", "name")
search_fields = ["registry_id", "domain", "name"]
search_fields = ["registry_id", "domain__name", "name"]
search_help_text = "Search by registry id, domain, or name."
def changeform_view(self, request, object_id=None, form_url="", extra_context=None):

View file

@ -1,7 +1,7 @@
import logging
import argparse
from django.core.management import BaseCommand
from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalHelper
from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalColors, TerminalHelper
from registrar.models import PublicContact
from django.db import transaction
from registrar.models.utility.generic_helper import normalize_string
@ -32,8 +32,6 @@ class Command(BaseCommand, PopulateScriptTemplate):
),
)
# print to file setting!
def handle(self, **kwargs):
"""Loops through each valid User object and updates its verification_type value"""
overwrite_updated_contacts = kwargs.get("overwrite_updated_contacts")
@ -63,16 +61,13 @@ class Command(BaseCommand, PopulateScriptTemplate):
filter_condition = {"email__in": default_emails}
else:
filter_condition = {"email__in": default_emails, "domain__name": target_domain}
# This is decorative since we are skipping bulk update
fields_to_update = ["name", "street1", "pc", "email"]
self.mass_update_records(PublicContact, filter_condition, fields_to_update)
def bulk_update_fields(self, object_class, to_update, fields_to_update):
with transaction.atomic():
super().bulk_update_fields(object_class, to_update, fields_to_update)
TerminalHelper.colorful_logger("INFO", "MAGENTA", f"Updating records in EPP...")
for record in to_update:
record.add_to_domain_in_epp()
TerminalHelper.colorful_logger("INFO", "OKCYAN", f"Updated '{record}' in EPP.")
def bulk_update_fields(self, *args, **kwargs):
"""Skip bulk update since we need to manually save each field"""
return None
def update_record(self, record: PublicContact):
"""Defines how we update the verification_type field"""
@ -80,7 +75,9 @@ class Command(BaseCommand, PopulateScriptTemplate):
record.street1 = "1110 N. Glebe Rd"
record.pc = "22201"
record.email = DefaultEmail.PUBLIC_CONTACT_DEFAULT
TerminalHelper.colorful_logger("INFO", "OKCYAN", f"Updating default values for '{record}'.")
logger.info(f"Updating default values for '{record}'.")
record.save()
logger.info(f"Updated '{record}' in EPP.")
def should_skip_record(self, record) -> bool: # noqa
"""Skips updating a public contact if it contains different default info."""
@ -89,7 +86,7 @@ class Command(BaseCommand, PopulateScriptTemplate):
f"Skipping legacy verisign contact '{record}'. "
f"The registry_id field has a length less than 16 characters."
)
TerminalHelper.colorful_logger("WARNING", "YELLOW", message)
logger.warning(f"{TerminalColors.OKCYAN}{message}{TerminalColors.ENDC}")
return True
for key, expected_values in self.old_and_new_default_contact_values.items():
@ -100,6 +97,6 @@ class Command(BaseCommand, PopulateScriptTemplate):
f"The field '{key}' does not match the default.\n"
f"Details: DB value - {record_field}, expected value(s) - {expected_values}"
)
TerminalHelper.colorful_logger("WARNING", "YELLOW", message)
logger.warning(f"{TerminalColors.OKCYAN}{message}{TerminalColors.ENDC}")
return True
return False

View file

@ -170,6 +170,7 @@ class PopulateScriptTemplate(ABC):
)
def bulk_update_fields(self, object_class, to_update, fields_to_update):
"""Bulk updates the given fields"""
ScriptDataHelper.bulk_update_fields(object_class, to_update, fields_to_update)
def get_class_name(self, sender) -> str: