diff --git a/src/registrar/management/commands/transfer_federal_agency_type.py b/src/registrar/management/commands/transfer_federal_agency_type.py index c1816aeb9..b3ec5da5e 100644 --- a/src/registrar/management/commands/transfer_federal_agency_type.py +++ b/src/registrar/management/commands/transfer_federal_agency_type.py @@ -7,10 +7,12 @@ from registrar.models import FederalAgency, DomainRequest logger = logging.getLogger(__name__) -# This command uses the PopulateScriptTemplate. -# This template handles logging and bulk updating for you, for repetitive scripts that update a few fields. -# It is the ultimate lazy mans shorthand. Don't use this for anything terribly complicated. class Command(BaseCommand, PopulateScriptTemplate): + """ + This command uses the PopulateScriptTemplate. + This template handles logging and bulk updating for you, for repetitive scripts that update a few fields. + It is the ultimate lazy mans shorthand. Don't use this for anything terribly complicated. + """ help = "Loops through each valid User object and updates its verification_type value" prompt_title = "Do you wish to update all Federal Agencies?" display_run_summary_items_as_str = True diff --git a/src/registrar/management/commands/utility/terminal_helper.py b/src/registrar/management/commands/utility/terminal_helper.py index 22054ac7b..eedc09aae 100644 --- a/src/registrar/management/commands/utility/terminal_helper.py +++ b/src/registrar/management/commands/utility/terminal_helper.py @@ -82,15 +82,15 @@ class PopulateScriptTemplate(ABC): """Defines how we update each field. Must be defined before using mass_update_records.""" raise NotImplementedError - def mass_update_records(self, sender, filter_conditions, fields_to_update, debug=True): - """Loops through each valid "sender" object - specified by filter_conditions - and + def mass_update_records(self, object_class, filter_conditions, fields_to_update, debug=True): + """Loops through each valid "object_class" object - specified by filter_conditions - and updates fields defined by fields_to_update using update_record. You must define update_record before you can use this function. """ - records = sender.objects.filter(**filter_conditions) - readable_class_name = self.get_class_name(sender) + records = object_class.objects.filter(**filter_conditions) + readable_class_name = self.get_class_name(object_class) # Code execution will stop here if the user prompts "N" TerminalHelper.prompt_for_execution( @@ -104,9 +104,9 @@ class PopulateScriptTemplate(ABC): ) logger.info("Updating...") - to_update: List[sender] = [] - to_skip: List[sender] = [] - failed_to_update: List[sender] = [] + to_update: List[object_class] = [] + to_skip: List[object_class] = [] + failed_to_update: List[object_class] = [] for record in records: try: if not self.should_skip_record(record): @@ -121,7 +121,7 @@ class PopulateScriptTemplate(ABC): logger.error(fail_message) # Do a bulk update on the desired field - ScriptDataHelper.bulk_update_fields(sender, to_update, fields_to_update) + ScriptDataHelper.bulk_update_fields(object_class, to_update, fields_to_update) # Log what happened TerminalHelper.log_script_run_summary( @@ -144,7 +144,7 @@ class PopulateScriptTemplate(ABC): return f"{TerminalColors.FAIL}" f"Failed to update {record}" f"{TerminalColors.ENDC}" def should_skip_record(self, record) -> bool: # noqa - """Defines the condition in which we should skip updating a record.""" + """Defines the condition in which we should skip updating a record. Override as needed.""" # By default - don't skip return False