mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 10:59:21 +02:00
Merge pull request #2246 from cisagov/dk/2194-import-export
Issues #2194, #2204: added command scripts clean_tables, export_tables and import_tables
This commit is contained in:
commit
7f55b6dc6d
6 changed files with 693 additions and 19 deletions
|
@ -2245,9 +2245,46 @@ class DraftDomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
return response
|
||||
|
||||
|
||||
class PublicContactAdmin(ListHeaderAdmin):
|
||||
class PublicContactResource(resources.ModelResource):
|
||||
"""defines how each field in the referenced model should be mapped to the corresponding fields in the
|
||||
import/export file"""
|
||||
|
||||
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)
|
||||
elif 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."""
|
||||
|
||||
resource_classes = [PublicContactResource]
|
||||
|
||||
change_form_template = "django/admin/email_clipboard_change_form.html"
|
||||
autocomplete_fields = ["domain"]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue