mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 19:09:22 +02:00
included DraftDomain, Websites and Host
This commit is contained in:
parent
8b1d692457
commit
ab5b0be466
2 changed files with 38 additions and 14 deletions
|
@ -20,6 +20,9 @@ need to be exported:
|
||||||
* DomainRequest
|
* DomainRequest
|
||||||
* DomainInformation
|
* DomainInformation
|
||||||
* DomainUserRole
|
* DomainUserRole
|
||||||
|
* DraftDomain
|
||||||
|
* Websites
|
||||||
|
* Host
|
||||||
|
|
||||||
### Import
|
### Import
|
||||||
|
|
||||||
|
@ -37,9 +40,6 @@ Delete all rows from tables in the following order through django admin:
|
||||||
* Domain
|
* Domain
|
||||||
* User (all but the current user)
|
* User (all but the current user)
|
||||||
* Contact
|
* Contact
|
||||||
|
|
||||||
It may not be necessary, but advisable to also remove rows from these tables:
|
|
||||||
|
|
||||||
* Websites
|
* Websites
|
||||||
* DraftDomain
|
* DraftDomain
|
||||||
* Host
|
* Host
|
||||||
|
@ -49,8 +49,11 @@ It may not be necessary, but advisable to also remove rows from these tables:
|
||||||
Once target environment is prepared, files can be imported in the following
|
Once target environment is prepared, files can be imported in the following
|
||||||
order:
|
order:
|
||||||
|
|
||||||
* User
|
* User (After importing User table, you need to delete all rows from Contact table before importing Contacts)
|
||||||
* Contact
|
* Contact
|
||||||
|
* Host
|
||||||
|
* DraftDomain
|
||||||
|
* Websites
|
||||||
* Domain
|
* Domain
|
||||||
* DomainRequest
|
* DomainRequest
|
||||||
* DomainInformation
|
* DomainInformation
|
||||||
|
|
|
@ -54,18 +54,15 @@ class FsmModelResource(resources.ModelResource):
|
||||||
from data in the row."""
|
from data in the row."""
|
||||||
|
|
||||||
# Get fields which are fsm fields
|
# Get fields which are fsm fields
|
||||||
fsm_fields = []
|
fsm_fields = {}
|
||||||
|
|
||||||
for f in self._meta.model._meta.fields:
|
for f in self._meta.model._meta.fields:
|
||||||
if isinstance(f, FSMField):
|
if isinstance(f, FSMField):
|
||||||
if row and f.name in row:
|
if row and f.name in row:
|
||||||
fsm_fields.append((f.name, row[f.name]))
|
fsm_fields[f.name] = row[f.name]
|
||||||
|
|
||||||
# Convert fsm_fields fields_and_values to kwargs
|
# Initialize model instance with fsm_fields
|
||||||
kwargs = dict(fsm_fields)
|
return self._meta.model(**fsm_fields)
|
||||||
|
|
||||||
# Initialize model instance with kwargs
|
|
||||||
return self._meta.model(**kwargs)
|
|
||||||
|
|
||||||
def import_field(self, field, obj, data, is_m2m=False, **kwargs):
|
def import_field(self, field, obj, data, is_m2m=False, **kwargs):
|
||||||
"""Overrides the import_field method of ModelResource. If the
|
"""Overrides the import_field method of ModelResource. If the
|
||||||
|
@ -760,9 +757,17 @@ class HostIPInline(admin.StackedInline):
|
||||||
model = models.HostIP
|
model = models.HostIP
|
||||||
|
|
||||||
|
|
||||||
class MyHostAdmin(AuditedAdmin):
|
class HostResource(resources.ModelResource):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = models.Host
|
||||||
|
|
||||||
|
|
||||||
|
class MyHostAdmin(AuditedAdmin, ImportExportModelAdmin):
|
||||||
"""Custom host admin class to use our inlines."""
|
"""Custom host admin class to use our inlines."""
|
||||||
|
|
||||||
|
resource_classes = [HostResource]
|
||||||
|
|
||||||
search_fields = ["name", "domain__name"]
|
search_fields = ["name", "domain__name"]
|
||||||
search_help_text = "Search by domain or host name."
|
search_help_text = "Search by domain or host name."
|
||||||
inlines = [HostIPInline]
|
inlines = [HostIPInline]
|
||||||
|
@ -899,9 +904,17 @@ class ContactAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
return super().change_view(request, object_id, form_url, extra_context=extra_context)
|
return super().change_view(request, object_id, form_url, extra_context=extra_context)
|
||||||
|
|
||||||
|
|
||||||
class WebsiteAdmin(ListHeaderAdmin):
|
class WebsiteResource(resources.ModelResource):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = models.Website
|
||||||
|
|
||||||
|
|
||||||
|
class WebsiteAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
"""Custom website admin class."""
|
"""Custom website admin class."""
|
||||||
|
|
||||||
|
resource_classes = [WebsiteResource]
|
||||||
|
|
||||||
# Search
|
# Search
|
||||||
search_fields = [
|
search_fields = [
|
||||||
"website",
|
"website",
|
||||||
|
@ -2139,9 +2152,17 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
return super().has_change_permission(request, obj)
|
return super().has_change_permission(request, obj)
|
||||||
|
|
||||||
|
|
||||||
class DraftDomainAdmin(ListHeaderAdmin):
|
class DraftDomainResource(resources.ModelResource):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = models.DraftDomain
|
||||||
|
|
||||||
|
|
||||||
|
class DraftDomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
"""Custom draft domain admin class."""
|
"""Custom draft domain admin class."""
|
||||||
|
|
||||||
|
resource_classes = [DraftDomainResource]
|
||||||
|
|
||||||
search_fields = ["name"]
|
search_fields = ["name"]
|
||||||
search_help_text = "Search by draft domain name."
|
search_help_text = "Search by draft domain name."
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue