Switch to ABC

This commit is contained in:
zandercymatics 2024-04-25 15:46:49 -06:00
parent 9e6cddb02e
commit 9d1f87ce78
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 7 additions and 5 deletions

View file

@ -1,13 +1,13 @@
import logging
from typing import List
from django.core.management import BaseCommand
from registrar.management.commands.utility.terminal_helper import ScriptTemplate, TerminalColors
from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalColors
from registrar.models import User
logger = logging.getLogger(__name__)
class Command(ScriptTemplate):
class Command(BaseCommand, PopulateScriptTemplate):
help = "Loops through each valid User object and updates its verification_type value"
def handle(self, **kwargs):

View file

@ -1,5 +1,6 @@
import logging
import sys
from abc import ABC, abstractmethod
from django.core.paginator import Paginator
from typing import List
from django.core.management import BaseCommand
@ -59,9 +60,9 @@ class ScriptDataHelper:
model_class.objects.bulk_update(page.object_list, fields_to_update)
class ScriptTemplate(BaseCommand):
class PopulateScriptTemplate(ABC):
"""
Contains common script actions for our scripts which can be prefilled as templates.
Contains an ABC for generic populate scripts
"""
def mass_populate_field(self, sender, filter_conditions, fields_to_update):
@ -102,9 +103,10 @@ class ScriptTemplate(BaseCommand):
# Log what happened
TerminalHelper.log_script_run_summary(to_update, failed_to_update, skipped=[], debug=True)
@abstractmethod
def populate_field(self, field_to_update):
"""Defines how we update each field. Must be defined before using mass_populate_field."""
raise NotImplementedError("This method should be implemented by the child class.")
pass
class TerminalHelper: