Skip to content

Commit

Permalink
Merge pull request #2292 from cisagov/rh/2253-fed-type
Browse files Browse the repository at this point in the history
ISSUE #2253: federal_type to Federal Agency model
  • Loading branch information
therealslimhsiehdy authored Jun 11, 2024
2 parents 3308d76 + fa263db commit 6108705
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/registrar/forms/domain_request_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from registrar.models import Contact, DomainRequest, DraftDomain, Domain, FederalAgency
from registrar.templatetags.url_helpers import public_site_url
from registrar.utility.enums import ValidationReturnType
from registrar.utility.constants import BranchChoices

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -67,7 +68,7 @@ def clean(self):

class OrganizationFederalForm(RegistrarForm):
federal_type = forms.ChoiceField(
choices=DomainRequest.BranchChoices.choices,
choices=BranchChoices.choices,
widget=forms.RadioSelect,
error_messages={"required": ("Select the part of the federal government your organization is in.")},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from registrar.models.domain_information import DomainInformation
from registrar.models.user import User
from registrar.models.federal_agency import FederalAgency
from registrar.utility.constants import BranchChoices

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -819,7 +820,7 @@ def handle(
invitation.save()

valid_org_choices = [(name, value) for name, value in DomainRequest.OrganizationChoices.choices]
valid_fed_choices = [value for name, value in DomainRequest.BranchChoices.choices]
valid_fed_choices = [value for name, value in BranchChoices.choices]
valid_agency_choices = FederalAgency.objects.all()
# ======================================================
# ================= DOMAIN INFORMATION =================
Expand Down
24 changes: 24 additions & 0 deletions src/registrar/migrations/0099_federalagency_federal_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.10 on 2024-06-11 15:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("registrar", "0098_alter_domainrequest_status"),
]

operations = [
migrations.AddField(
model_name="federalagency",
name="federal_type",
field=models.CharField(
blank=True,
choices=[("executive", "Executive"), ("judicial", "Judicial"), ("legislative", "Legislative")],
help_text="Federal agency type (executive, judicial, legislative, etc.)",
max_length=20,
null=True,
),
),
]
4 changes: 2 additions & 2 deletions src/registrar/models/domain_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from registrar.models.utility.domain_helper import DomainHelper
from registrar.models.utility.generic_helper import CreateOrUpdateOrganizationTypeHelper
from registrar.utility.constants import BranchChoices

from .domain_request import DomainRequest
from .utility.time_stamped_model import TimeStampedModel

Expand Down Expand Up @@ -37,8 +39,6 @@ class Meta:
# use the short names in Django admin
OrganizationChoices = DomainRequest.OrganizationChoices

BranchChoices = DomainRequest.BranchChoices

federal_agency = models.ForeignKey(
"registrar.FederalAgency",
on_delete=models.PROTECT,
Expand Down
6 changes: 1 addition & 5 deletions src/registrar/models/domain_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from registrar.models.federal_agency import FederalAgency
from registrar.models.utility.generic_helper import CreateOrUpdateOrganizationTypeHelper
from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes
from registrar.utility.constants import BranchChoices

from .utility.time_stamped_model import TimeStampedModel
from ..utility.email import send_templated_email, EmailSendingError
Expand Down Expand Up @@ -234,11 +235,6 @@ class OrganizationChoicesVerbose(models.TextChoices):
"School district: a school district that is not part of a local government",
)

class BranchChoices(models.TextChoices):
EXECUTIVE = "executive", "Executive"
JUDICIAL = "judicial", "Judicial"
LEGISLATIVE = "legislative", "Legislative"

class RejectionReasons(models.TextChoices):
DOMAIN_PURPOSE = "purpose_not_met", "Purpose requirements not met"
REQUESTOR = "requestor_not_eligible", "Requestor not eligible to make request"
Expand Down
9 changes: 9 additions & 0 deletions src/registrar/models/federal_agency.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .utility.time_stamped_model import TimeStampedModel
from django.db import models
import logging
from registrar.utility.constants import BranchChoices

logger = logging.getLogger(__name__)

Expand All @@ -16,6 +17,14 @@ class Meta:
help_text="Federal agency",
)

federal_type = models.CharField(
max_length=20,
choices=BranchChoices.choices,
null=True,
blank=True,
help_text="Federal agency type (executive, judicial, legislative, etc.)",
)

def __str__(self) -> str:
return f"{self.agency}"

Expand Down
6 changes: 4 additions & 2 deletions src/registrar/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import boto3_mocking
from registrar.models.transition_domain import TransitionDomain
from registrar.models.verified_by_staff import VerifiedByStaff # type: ignore
from registrar.utility.constants import BranchChoices

from .common import MockSESClient, less_console_noise, completed_domain_request, set_domain_request_investigators
from django_fsm import TransitionNotAllowed

Expand Down Expand Up @@ -124,7 +126,7 @@ def test_full_create(self):
creator=user,
investigator=user,
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
federal_type=DomainRequest.BranchChoices.EXECUTIVE,
federal_type=BranchChoices.EXECUTIVE,
is_election_board=False,
organization_name="Test",
address_line1="100 Main St.",
Expand Down Expand Up @@ -152,7 +154,7 @@ def test_domain_info(self):
information = DomainInformation.objects.create(
creator=user,
generic_org_type=DomainInformation.OrganizationChoices.FEDERAL,
federal_type=DomainInformation.BranchChoices.EXECUTIVE,
federal_type=BranchChoices.EXECUTIVE,
is_election_board=False,
organization_name="Test",
address_line1="100 Main St.",
Expand Down
7 changes: 7 additions & 0 deletions src/registrar/utility/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.db import models


class BranchChoices(models.TextChoices):
EXECUTIVE = "executive", "Executive"
JUDICIAL = "judicial", "Judicial"
LEGISLATIVE = "legislative", "Legislative"

0 comments on commit 6108705

Please sign in to comment.