mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-04 00:42:16 +02:00
Switch to ABC
This commit is contained in:
parent
9e6cddb02e
commit
9d1f87ce78
2 changed files with 7 additions and 5 deletions
|
@ -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):
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue