mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 19:09:22 +02:00
Add initial federal agency model migration
This commit is contained in:
parent
d920c890df
commit
7b5beba813
4 changed files with 56 additions and 31 deletions
|
@ -15,7 +15,7 @@ from django.contrib.contenttypes.models import ContentType
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from dateutil.relativedelta import relativedelta # type: ignore
|
from dateutil.relativedelta import relativedelta # type: ignore
|
||||||
from epplibwrapper.errors import ErrorCode, RegistryError
|
from epplibwrapper.errors import ErrorCode, RegistryError
|
||||||
from registrar.models import Contact, Domain, DomainRequest, DraftDomain, User, Website
|
from registrar.models import Contact, Domain, DomainRequest, DraftDomain, User, Website, FederalAgency
|
||||||
from registrar.utility import csv_export
|
from registrar.utility import csv_export
|
||||||
from registrar.utility.errors import FSMApplicationError, FSMErrorCodes
|
from registrar.utility.errors import FSMApplicationError, FSMErrorCodes
|
||||||
from registrar.views.utility.mixins import OrderableFieldsMixin
|
from registrar.views.utility.mixins import OrderableFieldsMixin
|
||||||
|
@ -1839,6 +1839,7 @@ admin.site.register(models.DomainInvitation, DomainInvitationAdmin)
|
||||||
admin.site.register(models.DomainInformation, DomainInformationAdmin)
|
admin.site.register(models.DomainInformation, DomainInformationAdmin)
|
||||||
admin.site.register(models.Domain, DomainAdmin)
|
admin.site.register(models.Domain, DomainAdmin)
|
||||||
admin.site.register(models.DraftDomain, DraftDomainAdmin)
|
admin.site.register(models.DraftDomain, DraftDomainAdmin)
|
||||||
|
admin.site.register(FederalAgency)
|
||||||
# Host and HostIP removed from django admin because changes in admin
|
# Host and HostIP removed from django admin because changes in admin
|
||||||
# do not propagate to registry and logic not applied
|
# do not propagate to registry and logic not applied
|
||||||
admin.site.register(models.Host, MyHostAdmin)
|
admin.site.register(models.Host, MyHostAdmin)
|
||||||
|
|
26
src/registrar/migrations/0077_federalagency.py
Normal file
26
src/registrar/migrations/0077_federalagency.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# Generated by Django 4.2.10 on 2024-03-19 05:42
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("registrar", "0076_alter_domainrequest_current_websites_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="FederalAgency",
|
||||||
|
fields=[
|
||||||
|
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
|
||||||
|
("created_at", models.DateTimeField(auto_now_add=True)),
|
||||||
|
("updated_at", models.DateTimeField(auto_now=True)),
|
||||||
|
("agency", models.CharField(blank=True, help_text="Federal agency", null=True)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
"verbose_name": "Federal agency",
|
||||||
|
"verbose_name_plural": "Federal agencies",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
|
@ -4,6 +4,7 @@ from .domain_request import DomainRequest
|
||||||
from .domain_information import DomainInformation
|
from .domain_information import DomainInformation
|
||||||
from .domain import Domain
|
from .domain import Domain
|
||||||
from .draft_domain import DraftDomain
|
from .draft_domain import DraftDomain
|
||||||
|
from .federal_agency import FederalAgency
|
||||||
from .host_ip import HostIP
|
from .host_ip import HostIP
|
||||||
from .host import Host
|
from .host import Host
|
||||||
from .domain_invitation import DomainInvitation
|
from .domain_invitation import DomainInvitation
|
||||||
|
@ -22,6 +23,7 @@ __all__ = [
|
||||||
"Domain",
|
"Domain",
|
||||||
"DraftDomain",
|
"DraftDomain",
|
||||||
"DomainInvitation",
|
"DomainInvitation",
|
||||||
|
"FederalAgency",
|
||||||
"HostIP",
|
"HostIP",
|
||||||
"Host",
|
"Host",
|
||||||
"UserDomainRole",
|
"UserDomainRole",
|
||||||
|
@ -39,6 +41,7 @@ auditlog.register(Domain)
|
||||||
auditlog.register(DraftDomain)
|
auditlog.register(DraftDomain)
|
||||||
auditlog.register(DomainInvitation)
|
auditlog.register(DomainInvitation)
|
||||||
auditlog.register(DomainInformation)
|
auditlog.register(DomainInformation)
|
||||||
|
auditlog.register(FederalAgency)
|
||||||
auditlog.register(HostIP)
|
auditlog.register(HostIP)
|
||||||
auditlog.register(Host)
|
auditlog.register(Host)
|
||||||
auditlog.register(UserDomainRole)
|
auditlog.register(UserDomainRole)
|
||||||
|
|
|
@ -1,22 +1,30 @@
|
||||||
from django.contrib.auth.models import Group
|
from .utility.time_stamped_model import TimeStampedModel
|
||||||
|
from django.db import models
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# TODO: Update param model
|
# TODO: Update param model
|
||||||
class FederalAgency(Group):
|
class FederalAgency(TimeStampedModel):
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Federal agency"
|
verbose_name = "Federal agency"
|
||||||
verbose_name_plural = "Federal agencies"
|
verbose_name_plural = "Federal agencies"
|
||||||
|
|
||||||
|
agency = models.CharField(
|
||||||
|
null=True,
|
||||||
|
blank=True,
|
||||||
|
help_text="Federal agency",
|
||||||
|
)
|
||||||
|
|
||||||
# TODO: Update parameters to put in
|
# TODO: Update parameters to put in
|
||||||
def create_federal_agencies(apps, schema_editor):
|
def create_federal_agencies(apps, schema_editor):
|
||||||
"""This method gets run from a data migration."""
|
"""This method gets run from a data migration."""
|
||||||
|
|
||||||
# Hard to pass self to these methods as the calls from migrations
|
# Hard to pass self to these methods as the calls from migrations
|
||||||
# are only expecting apps and schema_editor, so we'll just define
|
# are only expecting apps and schema_editor, so we'll just define
|
||||||
# apps, schema_editor in the local scope instead
|
# apps, schema_editor in the local scope instead
|
||||||
|
|
||||||
AGENCIES = [
|
AGENCIES = [
|
||||||
"Administrative Conference of the United States",
|
"Administrative Conference of the United States",
|
||||||
"Advisory Council on Historic Preservation",
|
"Advisory Council on Historic Preservation",
|
||||||
|
@ -202,30 +210,17 @@ class FederalAgency(Group):
|
||||||
"Woodrow Wilson International Center for Scholars",
|
"Woodrow Wilson International Center for Scholars",
|
||||||
"World War I Centennial Commission",
|
"World War I Centennial Commission",
|
||||||
]
|
]
|
||||||
|
|
||||||
# TODO: Get apps back here
|
FederalAgency = apps.get_model("registrar", "FederalAgency")
|
||||||
FederalAgency = apps.get_model("registrar", "FederalAgency")
|
logger.info("Creating federal agency table.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
federal_agencies_list, _ = FederalAgency.objects.get_or_create(
|
for agency in AGENCIES:
|
||||||
name="cisa_analysts_group",
|
federal_agencies_list, _ = FederalAgency.objects.get_or_create(
|
||||||
)
|
agency=agency,
|
||||||
|
)
|
||||||
federal_agencies_list.federal_agency.clear()
|
logger.debug(agency + " added to record " + federal_agencies_list.agency)
|
||||||
|
federal_agencies_list.save()
|
||||||
# TODO: Why is AGENCIES not loading here?
|
logger.debug("Federal agency added to table " + federal_agencies_list.agency)
|
||||||
for agency in AGENCIES:
|
except Exception as e:
|
||||||
|
logger.error(f"Error creating federal agency: {e}")
|
||||||
# Assign the permissions to the group
|
|
||||||
federal_agencies_list.agency.add(*agency)
|
|
||||||
|
|
||||||
# TODO: Maybe remove?
|
|
||||||
# Convert the permissions QuerySet to a list of codenames
|
|
||||||
agency_list = list(agency.values_list("codename", flat=True))
|
|
||||||
|
|
||||||
logger.debug(agency + " added to group " + federal_agencies_list.name)
|
|
||||||
|
|
||||||
federal_agencies_list.save()
|
|
||||||
logger.debug("Federal agency added to table " + federal_agencies_list.name)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error creating fedearl agency: {e}")
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue