mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 10:59:21 +02:00
custom code for PublicContact to not communicate with Registry on import
This commit is contained in:
parent
7c50b5fc2a
commit
9f973938a3
3 changed files with 44 additions and 4 deletions
|
@ -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."""
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue