diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 28e3af4d0..b11afd7b2 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -23,6 +23,7 @@ from registrar.models.user_domain_role import UserDomainRole from waffle.admin import FlagAdmin from waffle.models import Sample, Switch from registrar.models import Contact, Domain, DomainRequest, DraftDomain, User, Website, SeniorOfficial +from registrar.utility.constants import BranchChoices from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes from registrar.views.utility.mixins import OrderableFieldsMixin from django.contrib.admin.views.main import ORDER_VAR @@ -2896,7 +2897,7 @@ class PortfolioAdmin(ListHeaderAdmin): # This is the fieldset display when adding a new model add_fieldsets = [ (None, {"fields": ["organization_name", "creator", "notes"]}), - ("Type of organization", {"fields": ["organization_type", "federal_type"]}), + ("Type of organization", {"fields": ["organization_type"]}), ( "Organization name and mailing address", { @@ -2914,12 +2915,6 @@ class PortfolioAdmin(ListHeaderAdmin): ("Senior official", {"fields": ["senior_official"]}), ] - # NOT all fields are readonly for admin, otherwise we would have - # set this at the permissions level. The exception is 'status' - analyst_readonly_fields = [ - "federal_type", - ] - list_display = ("organization_name", "federal_agency", "creator") search_fields = ["organization_name"] search_help_text = "Search by organization name." @@ -2927,12 +2922,19 @@ class PortfolioAdmin(ListHeaderAdmin): # This is the created_at field "created_on", # Custom fields such as these must be defined as readonly. + "federal_type", "domains", "domain_requests", "suborganizations", "portfolio_type", ] + def federal_type(self, obj: models.portfolio): + """Returns the federal_type field""" + return BranchChoices.get_branch_label(obj.federal_type) if obj.federal_type else "-" + + federal_type.short_description = "Federal type" + def created_on(self, obj: models.Portfolio): """Returns the created_at field, with a different short description""" # Format: Dec 12, 2024 diff --git a/src/registrar/assets/js/get-gov-admin.js b/src/registrar/assets/js/get-gov-admin.js index b6ba82821..3a5af7f6e 100644 --- a/src/registrar/assets/js/get-gov-admin.js +++ b/src/registrar/assets/js/get-gov-admin.js @@ -881,22 +881,6 @@ function initializeWidgetOnList(list, parentId) { .catch(error => console.error("Error fetching senior official: ", error)); } - function updateContactInfo(data) { - if (!contactList) return; - - const titleSpan = contactList.querySelector("#contact_info_title"); - const emailSpan = contactList.querySelector("#contact_info_email"); - const phoneSpan = contactList.querySelector("#contact_info_phone"); - - if (titleSpan) titleSpan.textContent = data.title || ""; - if (emailSpan) { - emailSpan.textContent = data.email || ""; - const clipboardInput = contactList.querySelector(".admin-icon-group input"); - if (clipboardInput) clipboardInput.value = data.email || ""; - } - if (phoneSpan) phoneSpan.textContent = data.phone || ""; - } - function handleStateTerritoryChange(stateTerritory, urbanizationField) { let selectedValue = stateTerritory.value; if (selectedValue === "PR") { @@ -905,4 +889,29 @@ function initializeWidgetOnList(list, parentId) { hideElement(urbanizationField) } } + + function updateContactInfo(data) { + if (!contactList) return; + + const titleSpan = contactList.querySelector("#contact_info_title"); + const emailSpan = contactList.querySelector("#contact_info_email"); + const phoneSpan = contactList.querySelector("#contact_info_phone"); + + if (titleSpan) { + titleSpan.textContent = data.title || ""; + }; + + // Update the email field and the content for the clipboard + if (emailSpan) { + emailSpan.textContent = data.email || ""; + const clipboardInput = contactList.querySelector(".admin-icon-group input"); + if (clipboardInput) { + clipboardInput.value = data.email || ""; + }; + } + + if (phoneSpan) { + phoneSpan.textContent = data.phone || ""; + }; + } })(); diff --git a/src/registrar/migrations/0118_alter_portfolio_options_portfolio_federal_type_and_more.py b/src/registrar/migrations/0118_alter_portfolio_options_alter_portfolio_creator_and_more.py similarity index 79% rename from src/registrar/migrations/0118_alter_portfolio_options_portfolio_federal_type_and_more.py rename to src/registrar/migrations/0118_alter_portfolio_options_alter_portfolio_creator_and_more.py index 693744951..8f84187a2 100644 --- a/src/registrar/migrations/0118_alter_portfolio_options_portfolio_federal_type_and_more.py +++ b/src/registrar/migrations/0118_alter_portfolio_options_alter_portfolio_creator_and_more.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.10 on 2024-08-14 18:50 +# Generated by Django 4.2.10 on 2024-08-15 15:32 from django.conf import settings from django.db import migrations, models @@ -16,16 +16,6 @@ class Migration(migrations.Migration): name="portfolio", options={"ordering": ["organization_name"]}, ), - migrations.AddField( - model_name="portfolio", - name="federal_type", - field=models.CharField( - blank=True, - choices=[("executive", "Executive"), ("judicial", "Judicial"), ("legislative", "Legislative")], - max_length=50, - null=True, - ), - ), migrations.AlterField( model_name="portfolio", name="creator", diff --git a/src/registrar/models/portfolio.py b/src/registrar/models/portfolio.py index 6dcd660e7..77daf9cb1 100644 --- a/src/registrar/models/portfolio.py +++ b/src/registrar/models/portfolio.py @@ -58,13 +58,6 @@ class Portfolio(TimeStampedModel): default=FederalAgency.get_non_federal_agency, ) - federal_type = models.CharField( - max_length=50, - choices=BranchChoices.choices, - null=True, - blank=True, - ) - senior_official = models.ForeignKey( "registrar.SeniorOfficial", on_delete=models.PROTECT, @@ -136,12 +129,19 @@ class Portfolio(TimeStampedModel): def portfolio_type(self): """ Returns a combination of organization_type / federal_type, seperated by ' - '. - If no federal_type is found, we just return the org type.""" - org_type = self.OrganizationChoices.get_org_label(self.organization_type) - if self.organization_type == self.OrganizationChoices.FEDERAL and self.federal_type: - return " - ".join([org_type, self.federal_type]) + If no federal_type is found, we just return the org type. + """ + org_type_label = self.OrganizationChoices.get_org_label(self.organization_type) + agency_type_label = BranchChoices.get_branch_label(self.federal_type) + if self.organization_type == self.OrganizationChoices.FEDERAL and agency_type_label: + return " - ".join([org_type_label, agency_type_label]) else: - return org_type + return org_type_label + + @property + def federal_type(self): + """Returns the federal_type value on the underlying federal_agency field""" + return self.federal_agency.federal_type if self.federal_agency else None # == Getters for domains == # def get_domains(self):