mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-29 07:43:32 +02:00
added FederalAgency, updated for using bulk
This commit is contained in:
parent
1921d99eab
commit
97ee855de6
5 changed files with 30 additions and 6 deletions
|
@ -32,6 +32,7 @@ For reference, the zip file will contain the following tables in csv form:
|
|||
* DomainInformation
|
||||
* DomainUserRole
|
||||
* DraftDomain
|
||||
* FederalAgency
|
||||
* Websites
|
||||
* Host
|
||||
* HostIP
|
||||
|
@ -76,13 +77,14 @@ For reference, this deletes all rows from the following tables:
|
|||
* DomainInformation
|
||||
* DomainRequest
|
||||
* Domain
|
||||
* User (all but the current user)
|
||||
* User
|
||||
* Contact
|
||||
* Websites
|
||||
* DraftDomain
|
||||
* HostIP
|
||||
* Host
|
||||
* PublicContact
|
||||
* FederalAgency
|
||||
|
||||
#### Importing into Target Environment
|
||||
|
||||
|
@ -115,7 +117,7 @@ cf ssh {target-app}
|
|||
example cleaning getgov-backup:
|
||||
cf ssh getgov-backup
|
||||
/tmp/lifecycle/backup
|
||||
./manage.py import_tables --skipEppSave=False
|
||||
./manage.py import_tables --no-skipEppSave
|
||||
|
||||
For reference, this imports tables in the following order:
|
||||
|
||||
|
@ -126,6 +128,7 @@ For reference, this imports tables in the following order:
|
|||
* HostIP
|
||||
* DraftDomain
|
||||
* Websites
|
||||
* FederalAgency
|
||||
* DomainRequest
|
||||
* DomainInformation
|
||||
* UserDomainRole
|
||||
|
|
|
@ -2370,6 +2370,9 @@ class PublicContactResource(resources.ModelResource):
|
|||
|
||||
class Meta:
|
||||
model = models.PublicContact
|
||||
use_bulk = True
|
||||
batch_size = 1000
|
||||
force_init_instance = True
|
||||
|
||||
def __init__(self):
|
||||
"""Sets global variables for code tidyness"""
|
||||
|
@ -2472,11 +2475,20 @@ class VerifiedByStaffAdmin(ListHeaderAdmin):
|
|||
super().save_model(request, obj, form, change)
|
||||
|
||||
|
||||
class FederalAgencyAdmin(ListHeaderAdmin):
|
||||
class FederalAgencyResource(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.FederalAgency
|
||||
|
||||
|
||||
class FederalAgencyAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||
list_display = ["agency"]
|
||||
search_fields = ["agency"]
|
||||
search_help_text = "Search by agency name."
|
||||
ordering = ["agency"]
|
||||
resource_classes = [FederalAgencyResource]
|
||||
|
||||
|
||||
class UserGroupAdmin(AuditedAdmin):
|
||||
|
|
|
@ -28,6 +28,7 @@ class Command(BaseCommand):
|
|||
* DomainInformation
|
||||
* DomainRequest
|
||||
* DraftDomain
|
||||
* FederalAgency
|
||||
* Host
|
||||
* HostIp
|
||||
* PublicContact
|
||||
|
@ -40,14 +41,15 @@ class Command(BaseCommand):
|
|||
table_names = [
|
||||
"DomainInformation",
|
||||
"DomainRequest",
|
||||
"FederalAgency",
|
||||
"PublicContact",
|
||||
"HostIp",
|
||||
"Host",
|
||||
"Domain",
|
||||
"User",
|
||||
"Contact",
|
||||
"Website",
|
||||
"DraftDomain",
|
||||
"HostIp",
|
||||
"Host",
|
||||
]
|
||||
|
||||
for table_name in table_names:
|
||||
|
|
|
@ -18,6 +18,7 @@ class Command(BaseCommand):
|
|||
"Domain",
|
||||
"DomainRequest",
|
||||
"DomainInformation",
|
||||
"FederalAgency",
|
||||
"UserDomainRole",
|
||||
"DraftDomain",
|
||||
"Website",
|
||||
|
|
|
@ -36,6 +36,7 @@ class Command(BaseCommand):
|
|||
"HostIp",
|
||||
"DraftDomain",
|
||||
"Website",
|
||||
"FederalAgency",
|
||||
"DomainRequest",
|
||||
"DomainInformation",
|
||||
"UserDomainRole",
|
||||
|
@ -83,7 +84,12 @@ class Command(BaseCommand):
|
|||
result = resource_instance.import_data(dataset, dry_run=False, skip_epp_save=self.skip_epp_save)
|
||||
|
||||
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}:")
|
||||
for row_error in result.row_errors():
|
||||
row_index = row_error[0]
|
||||
errors = row_error[1]
|
||||
for error in errors:
|
||||
logger.error(f"Row {row_index} - {error.error} - {error.row}")
|
||||
else:
|
||||
logger.info(f"Successfully imported {csv_filename} into {table_name}")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue