mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-30 14:36:32 +02:00
use save instead of set
This commit is contained in:
parent
0fa9ad1546
commit
ec97f28442
2 changed files with 9 additions and 7 deletions
|
@ -32,8 +32,7 @@ class Command(BaseCommand, PopulateScriptTemplate):
|
|||
}
|
||||
old_emails = [email for email in DefaultEmail if email != DefaultEmail.PUBLIC_CONTACT_DEFAULT]
|
||||
filter_condition = {"email__in": old_emails}
|
||||
fields_to_update = ["name", "street1", "pc", "email"]
|
||||
self.mass_update_records(PublicContact, filter_condition, fields_to_update)
|
||||
self.mass_update_records(PublicContact, filter_condition, [], skip_bulk_update=True)
|
||||
|
||||
def update_record(self, record: PublicContact):
|
||||
"""Defines how we update the verification_type field"""
|
||||
|
@ -42,9 +41,7 @@ class Command(BaseCommand, PopulateScriptTemplate):
|
|||
record.pc = "22201"
|
||||
record.email = DefaultEmail.PUBLIC_CONTACT_DEFAULT
|
||||
TerminalHelper.colorful_logger("INFO", "OKCYAN", f"Updating default values for '{record}'.")
|
||||
TerminalHelper.colorful_logger("INFO", "MAGENTA", f"Attempting to update record in EPP...")
|
||||
# Since this function raises an error, this update will revert on both the model and here
|
||||
Domain._set_singleton_contact(record, expectedType=record.contact_type)
|
||||
record.save()
|
||||
TerminalHelper.colorful_logger("INFO", "OKCYAN", f"Updated record in EPP.")
|
||||
|
||||
def should_skip_record(self, record) -> bool: # noqa
|
||||
|
|
|
@ -86,7 +86,7 @@ class PopulateScriptTemplate(ABC):
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def mass_update_records(self, object_class, filter_conditions, fields_to_update, debug=True, verbose=False):
|
||||
def mass_update_records(self, object_class, filter_conditions, fields_to_update, debug=True, verbose=False, skip_bulk_update=False):
|
||||
"""Loops through each valid "object_class" object - specified by filter_conditions - and
|
||||
updates fields defined by fields_to_update using update_record.
|
||||
|
||||
|
@ -105,6 +105,10 @@ class PopulateScriptTemplate(ABC):
|
|||
|
||||
verbose: Whether to print a detailed run summary *before* run confirmation.
|
||||
Default: False.
|
||||
|
||||
skip_bulk_update: Whether to avoid doing a bulk update or not.
|
||||
This setting assumes that you are doing a save in the update_record class.
|
||||
IMPORANT: this setting invalidates 'fields_to_update'.
|
||||
|
||||
Raises:
|
||||
NotImplementedError: If you do not define update_record before using this function.
|
||||
|
@ -155,7 +159,8 @@ class PopulateScriptTemplate(ABC):
|
|||
logger.error(fail_message)
|
||||
|
||||
# Do a bulk update on the desired field
|
||||
ScriptDataHelper.bulk_update_fields(object_class, to_update, fields_to_update)
|
||||
if not skip_bulk_update:
|
||||
ScriptDataHelper.bulk_update_fields(object_class, to_update, fields_to_update)
|
||||
|
||||
# Log what happened
|
||||
TerminalHelper.log_script_run_summary(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue