diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 5b49b6811..b4ddb9448 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -30,7 +30,7 @@ from django.utils.safestring import mark_safe from django.utils.html import escape from django.contrib.auth.forms import UserChangeForm, UsernameField from django_admin_multiple_choice_list_filter.list_filters import MultipleChoiceListFilter -from import_export import resources +from import_export import resources, results from import_export.admin import ImportExportModelAdmin from django.utils.translation import gettext_lazy as _ @@ -2251,6 +2251,46 @@ class PublicContactResource(resources.ModelResource): class Meta: model = models.PublicContact + 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 + 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 + ): + """Override save_instance setting skip_epp_save to True + """ + self.before_save_instance(instance, using_transactions, dry_run) + if self._meta.use_bulk: + if is_create: + self.create_instances.append(instance) + else: + self.update_instances.append(instance) + else: + if not using_transactions and dry_run: + # we don't have transactions and we want to do a dry_run + pass + else: + instance.save(skip_epp_save=True) + self.after_save_instance(instance, using_transactions, dry_run) + + class PublicContactAdmin(ListHeaderAdmin, ImportExportModelAdmin): """Custom PublicContact admin class.""" diff --git a/src/registrar/management/commands/clean_tables.py b/src/registrar/management/commands/clean_tables.py index 2f331d005..0470c0697 100644 --- a/src/registrar/management/commands/clean_tables.py +++ b/src/registrar/management/commands/clean_tables.py @@ -12,7 +12,7 @@ class Command(BaseCommand): """Delete all rows from a list of tables""" table_names = [ "DomainInformation", "DomainRequest", "Domain", "User", "Contact", - "Website", "DraftDomain", "HostIp", "Host" + "Website", "DraftDomain", "HostIp", "Host", "PublicContact" ] for table_name in table_names: diff --git a/src/registrar/management/commands/import_tables.py b/src/registrar/management/commands/import_tables.py index bad94b5a3..6408ef758 100644 --- a/src/registrar/management/commands/import_tables.py +++ b/src/registrar/management/commands/import_tables.py @@ -16,7 +16,7 @@ class Command(BaseCommand): """Extracts CSV files from a zip archive and imports them into the respective tables""" table_names = [ "User", "Contact", "Domain", "Host", "HostIp", "DraftDomain", "Website", - "DomainRequest", "DomainInformation", "UserDomainRole" + "DomainRequest", "DomainInformation", "UserDomainRole", "PublicContact" ] # Ensure the tmp directory exists @@ -54,7 +54,7 @@ class Command(BaseCommand): with open(csv_filename, "r") as csvfile: #dataset = resource_instance.import_data(csvfile.read()) dataset = tablib.Dataset().load(csvfile.read(), format='csv') - result = resource_instance.import_data(dataset, dry_run=False) + result = resource_instance.import_data(dataset, dry_run=False, skip_epp_save=True) if result.has_errors(): logger.error(f"Errors occurred while importing {csv_filename}: {result.row_errors()}")