linter fixes

This commit is contained in:
matthewswspence 2024-08-27 15:25:44 -05:00
parent f6e10b6585
commit febd9566ce
No known key found for this signature in database
GPG key ID: FB458202A7852BA4
2 changed files with 14 additions and 14 deletions

View file

@ -4,14 +4,16 @@ from django.db.models.manager import BaseManager
from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalColors from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalColors
from registrar.models import Domain, TransitionDomain from registrar.models import Domain, TransitionDomain
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class Command(BaseCommand, PopulateScriptTemplate): class Command(BaseCommand, PopulateScriptTemplate):
help = "Loops through each domain object and populates the last_status_update and first_submitted_date" help = "Loops through each domain object and populates the last_status_update and first_submitted_date"
def handle(self, **kwargs): def handle(self, **kwargs):
"""Loops through each valid Domain object and updates it's first_ready value if it is out of sync""" """Loops through each valid Domain object and updates it's first_ready value if it is out of sync"""
filter_conditions={"state__in":[Domain.State.READY, Domain.State.ON_HOLD, Domain.State.DELETED, Domain.State.UNKNOWN]} filter_conditions = {"state__in": [Domain.State.READY, Domain.State.ON_HOLD, Domain.State.DELETED]}
self.mass_update_records(Domain, filter_conditions, ["first_ready"], verbose=True) self.mass_update_records(Domain, filter_conditions, ["first_ready"], verbose=True)
def update_record(self, record: Domain): def update_record(self, record: Domain):
@ -22,13 +24,13 @@ class Command(BaseCommand, PopulateScriptTemplate):
logger.info( logger.info(
f"{TerminalColors.OKCYAN}Updating {record} => first_ready: " f"{record.first_ready}{TerminalColors.ENDC}" f"{TerminalColors.OKCYAN}Updating {record} => first_ready: " f"{record.first_ready}{TerminalColors.ENDC}"
) )
# check if a transition domain object for this domain name exists, # check if a transition domain object for this domain name exists,
# or if so whether its first_ready value matches its created_at date # or if so whether its first_ready value matches its created_at date
def custom_filter(self, records: BaseManager[Domain]) -> BaseManager[Domain]: def custom_filter(self, records: BaseManager[Domain]) -> BaseManager[Domain]:
to_include_pks = [] to_include_pks = []
for record in records: for record in records:
if TransitionDomain.objects.filter(domain_name=record.name).exists() and record.first_ready != record.created_at.date(): if TransitionDomain.objects.filter(domain_name=record.name).exists() and record.first_ready != record.created_at.date(): #noqa
to_include_pks.append(record.pk) to_include_pks.append(record.pk)
return records.filter(pk__in=to_include_pks) return records.filter(pk__in=to_include_pks)

View file

@ -99,7 +99,7 @@ class PopulateScriptTemplate(ABC):
fields_to_update: List of strings specifying which fields to update. fields_to_update: List of strings specifying which fields to update.
(e.g. ["first_ready_date", "last_submitted_date"]) (e.g. ["first_ready_date", "last_submitted_date"])
debug: Whether to log script run summary in debug mode. debug: Whether to log script run summary in debug mode.
Default: True. Default: True.
verbose: Whether to print a detailed run summary *before* run confirmation. verbose: Whether to print a detailed run summary *before* run confirmation.
@ -118,13 +118,13 @@ class PopulateScriptTemplate(ABC):
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=f"""==Proposed Changes== proposed_changes = f"""==Proposed Changes==
Number of {readable_class_name} objects to change: {len(records)} Number of {readable_class_name} objects to change: {len(records)}
These fields will be updated on each record: {fields_to_update} These fields will be updated on each record: {fields_to_update}
""" """
if verbose: if verbose:
proposed_changes=f"""{proposed_changes} proposed_changes = f"""{proposed_changes}
These records will be updated: {list(records.all())} These records will be updated: {list(records.all())}
""" """
@ -181,14 +181,12 @@ class PopulateScriptTemplate(ABC):
*will* be included in the run but will be skipped (and logged as such).""" *will* be included in the run but will be skipped (and logged as such)."""
# By default - don't skip # By default - don't skip
return False return False
def custom_filter(self, records: BaseManager[Model]) -> BaseManager[Model]: def custom_filter(self, records: BaseManager[Model]) -> BaseManager[Model]:
"""Override to define filters that can't be represented by django queryset field lookups. """Override to define filters that can't be represented by django queryset field lookups.
Applied to individual records *after* filter_conditions. True means """ Applied to individual records *after* filter_conditions. True means """
return records return records
class TerminalHelper: class TerminalHelper:
@staticmethod @staticmethod
def log_script_run_summary( def log_script_run_summary(