mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-10 21:23:32 +02:00
added skipEppSave command line option, may change option in future commit
This commit is contained in:
parent
f60fcc658e
commit
77e5c918e7
2 changed files with 46 additions and 11 deletions
|
@ -2252,18 +2252,46 @@ class PublicContactResource(resources.ModelResource):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.PublicContact
|
model = models.PublicContact
|
||||||
|
|
||||||
def import_row(self, row, instance_loader, using_transactions=True, dry_run=False, raise_errors=None, **kwargs):
|
def __init__(self):
|
||||||
"""Override kwargs skip_epp_save and set to True"""
|
"""Sets global variables for code tidyness"""
|
||||||
kwargs["skip_epp_save"] = True
|
super().__init__()
|
||||||
return super().import_row(
|
self.skip_epp_save=False
|
||||||
row,
|
|
||||||
instance_loader,
|
def import_data(
|
||||||
using_transactions=using_transactions,
|
self,
|
||||||
dry_run=dry_run,
|
dataset,
|
||||||
raise_errors=raise_errors,
|
dry_run=False,
|
||||||
|
raise_errors=False,
|
||||||
|
use_transactions=None,
|
||||||
|
collect_failed_rows=False,
|
||||||
|
rollback_on_validation_errors=False,
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
|
"""Override import_data to set self.skip_epp_save if in kwargs"""
|
||||||
|
self.skip_epp_save = kwargs.get('skip_epp_save', False)
|
||||||
|
return super().import_data(
|
||||||
|
dataset,
|
||||||
|
dry_run,
|
||||||
|
raise_errors,
|
||||||
|
use_transactions,
|
||||||
|
collect_failed_rows,
|
||||||
|
rollback_on_validation_errors,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# def import_row(self, row, instance_loader, using_transactions=True, dry_run=False, raise_errors=None, **kwargs):
|
||||||
|
# """Override kwargs skip_epp_save and set to True"""
|
||||||
|
# kwargs["skip_epp_save"] = True
|
||||||
|
# super().import_data()
|
||||||
|
# return super().import_row(
|
||||||
|
# row,
|
||||||
|
# instance_loader,
|
||||||
|
# using_transactions=using_transactions,
|
||||||
|
# dry_run=dry_run,
|
||||||
|
# raise_errors=raise_errors,
|
||||||
|
# **kwargs,
|
||||||
|
# )
|
||||||
|
|
||||||
def save_instance(self, instance, is_create, using_transactions=True, dry_run=False):
|
def save_instance(self, instance, is_create, using_transactions=True, dry_run=False):
|
||||||
"""Override save_instance setting skip_epp_save to True"""
|
"""Override save_instance setting skip_epp_save to True"""
|
||||||
self.before_save_instance(instance, using_transactions, dry_run)
|
self.before_save_instance(instance, using_transactions, dry_run)
|
||||||
|
@ -2276,7 +2304,7 @@ class PublicContactResource(resources.ModelResource):
|
||||||
# we don't have transactions and we want to do a dry_run
|
# we don't have transactions and we want to do a dry_run
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
instance.save(skip_epp_save=True)
|
instance.save(skip_epp_save=self.skip_epp_save)
|
||||||
self.after_save_instance(instance, using_transactions, dry_run)
|
self.after_save_instance(instance, using_transactions, dry_run)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import pyzipper
|
import pyzipper
|
||||||
|
@ -14,6 +15,10 @@ logger = logging.getLogger(__name__)
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = "Imports tables from a zip file, exported_tables.zip, containing CSV files in the tmp directory."
|
help = "Imports tables from a zip file, exported_tables.zip, containing CSV files in the tmp directory."
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
"""Add command line arguments."""
|
||||||
|
parser.add_argument('--skipEppSave', default=True, action=argparse.BooleanOptionalAction)
|
||||||
|
|
||||||
def handle(self, **options):
|
def handle(self, **options):
|
||||||
"""Extracts CSV files from a zip archive and imports them into the respective tables"""
|
"""Extracts CSV files from a zip archive and imports them into the respective tables"""
|
||||||
|
|
||||||
|
@ -21,6 +26,8 @@ class Command(BaseCommand):
|
||||||
logger.error("import_tables cannot be run in production")
|
logger.error("import_tables cannot be run in production")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.skip_epp_save = options.get("skipEppSave")
|
||||||
|
|
||||||
table_names = [
|
table_names = [
|
||||||
"User",
|
"User",
|
||||||
"Contact",
|
"Contact",
|
||||||
|
@ -73,7 +80,7 @@ class Command(BaseCommand):
|
||||||
resource_instance = resourceclass()
|
resource_instance = resourceclass()
|
||||||
with open(csv_filename, "r") as csvfile:
|
with open(csv_filename, "r") as csvfile:
|
||||||
dataset = tablib.Dataset().load(csvfile.read(), format="csv")
|
dataset = tablib.Dataset().load(csvfile.read(), format="csv")
|
||||||
result = resource_instance.import_data(dataset, dry_run=False, skip_epp_save=True)
|
result = resource_instance.import_data(dataset, dry_run=False, skip_epp_save=self.skip_epp_save)
|
||||||
|
|
||||||
if result.has_errors():
|
if result.has_errors():
|
||||||
logger.error(f"Errors occurred while importing {csv_filename}: {result.row_errors()}")
|
logger.error(f"Errors occurred while importing {csv_filename}: {result.row_errors()}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue