mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 18:56:15 +02:00
Remove portfolio type field
Move portfolio org, rename to organization name, move sections, hide organization name if federal
This commit is contained in:
parent
45479e86c7
commit
ab35657147
7 changed files with 58 additions and 71 deletions
|
@ -2910,15 +2910,14 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
|
|
||||||
change_form_template = "django/admin/portfolio_change_form.html"
|
change_form_template = "django/admin/portfolio_change_form.html"
|
||||||
fieldsets = [
|
fieldsets = [
|
||||||
# created_on is the created_at field, and portfolio_type is f"{organization_type} - {federal_type}"
|
# created_on is the created_at field
|
||||||
(None, {"fields": ["portfolio_type", "organization_name", "creator", "created_on", "notes"]}),
|
(None, {"fields": ["creator", "created_on", "notes"]}),
|
||||||
("Portfolio members", {"fields": ["display_admins", "display_members"]}),
|
|
||||||
("Portfolio domains", {"fields": ["domains", "domain_requests"]}),
|
|
||||||
("Type of organization", {"fields": ["organization_type", "federal_type"]}),
|
("Type of organization", {"fields": ["organization_type", "federal_type"]}),
|
||||||
(
|
(
|
||||||
"Organization name and mailing address",
|
"Organization name and mailing address",
|
||||||
{
|
{
|
||||||
"fields": [
|
"fields": [
|
||||||
|
"organization_name",
|
||||||
"federal_agency",
|
"federal_agency",
|
||||||
"state_territory",
|
"state_territory",
|
||||||
"address_line1",
|
"address_line1",
|
||||||
|
@ -2929,6 +2928,8 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
("Portfolio members", {"fields": ["display_admins", "display_members"]}),
|
||||||
|
("Portfolio domains", {"fields": ["domains", "domain_requests"]}),
|
||||||
("Suborganizations", {"fields": ["suborganizations"]}),
|
("Suborganizations", {"fields": ["suborganizations"]}),
|
||||||
("Senior official", {"fields": ["senior_official"]}),
|
("Senior official", {"fields": ["senior_official"]}),
|
||||||
]
|
]
|
||||||
|
@ -2960,6 +2961,10 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
readonly_fields = [
|
readonly_fields = [
|
||||||
# This is the created_at field
|
# This is the created_at field
|
||||||
"created_on",
|
"created_on",
|
||||||
|
# Django admin doesn't allow methods to be directly listed in fieldsets. We can
|
||||||
|
# display the custom methods display_admins amd display_members in the admin form if
|
||||||
|
# they are readonly.
|
||||||
|
"federal_type",
|
||||||
"domains",
|
"domains",
|
||||||
"domain_requests",
|
"domain_requests",
|
||||||
"suborganizations",
|
"suborganizations",
|
||||||
|
|
|
@ -860,11 +860,10 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
let organizationType = document.getElementById("id_organization_type");
|
let organizationType = document.getElementById("id_organization_type");
|
||||||
let readonlyOrganizationType = document.querySelector(".field-organization_type .readonly");
|
let readonlyOrganizationType = document.querySelector(".field-organization_type .readonly");
|
||||||
|
|
||||||
let federalType = document.getElementById("id_federal_type")
|
if ($federalAgency && (organizationType || readonlyOrganizationType)) {
|
||||||
if ($federalAgency && (organizationType || readonlyOrganizationType) && federalType) {
|
|
||||||
// Attach the change event listener
|
// Attach the change event listener
|
||||||
$federalAgency.on("change", function() {
|
$federalAgency.on("change", function() {
|
||||||
handleFederalAgencyChange($federalAgency, organizationType, readonlyOrganizationType, federalType);
|
handleFederalAgencyChange($federalAgency, organizationType, readonlyOrganizationType);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -880,9 +879,28 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
handleStateTerritoryChange(stateTerritory, urbanizationField);
|
handleStateTerritoryChange(stateTerritory, urbanizationField);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle hiding the organization name field when the organization_type is federal.
|
||||||
|
// Run this first one page load, then secondly on a change event.
|
||||||
|
let organizationNameContainer = document.querySelector(".field-organization_name")
|
||||||
|
handleOrganizationTypeChange(organizationType, organizationNameContainer);
|
||||||
|
organizationType.addEventListener("change", function() {
|
||||||
|
handleOrganizationTypeChange(organizationType, organizationNameContainer);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleFederalAgencyChange(federalAgency, organizationType, readonlyOrganizationType, federalType) {
|
function handleOrganizationTypeChange(organizationType, organizationNameContainer) {
|
||||||
|
if (organizationType && organizationNameContainer) {
|
||||||
|
let selectedValue = organizationType.value;
|
||||||
|
if (selectedValue === "federal") {
|
||||||
|
hideElement(organizationNameContainer);
|
||||||
|
} else {
|
||||||
|
showElement(organizationNameContainer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleFederalAgencyChange(federalAgency, organizationType, readonlyOrganizationType) {
|
||||||
// Don't do anything on page load
|
// Don't do anything on page load
|
||||||
if (isInitialPageLoad) {
|
if (isInitialPageLoad) {
|
||||||
isInitialPageLoad = false;
|
isInitialPageLoad = false;
|
||||||
|
@ -923,12 +941,10 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
organizationTypeValue = organizationType ? organizationType.value : readonlyOrganizationType.innerText.toLowerCase();
|
|
||||||
|
|
||||||
// Determine if any changes are necessary to the display of portfolio type or federal type
|
// Determine if any changes are necessary to the display of portfolio type or federal type
|
||||||
// based on changes to the Federal Agency
|
// based on changes to the Federal Agency
|
||||||
let federalPortfolioApi = document.getElementById("federal_and_portfolio_types_from_agency_json_url").value;
|
let federalPortfolioApi = document.getElementById("federal_and_portfolio_types_from_agency_json_url").value;
|
||||||
fetch(`${federalPortfolioApi}?organization_type=${organizationTypeValue}&agency_name=${selectedText}`)
|
fetch(`${federalPortfolioApi}?&agency_name=${selectedText}`)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
const statusCode = response.status;
|
const statusCode = response.status;
|
||||||
return response.json().then(data => ({ statusCode, data }));
|
return response.json().then(data => ({ statusCode, data }));
|
||||||
|
@ -938,12 +954,7 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
console.error("Error in AJAX call: " + data.error);
|
console.error("Error in AJAX call: " + data.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data.federal_type && selectedText !== "Non-Federal Agency") {
|
updateReadOnly(data.federal_type, '.field-federal_type');
|
||||||
federalType.value = data.federal_type.toLowerCase();
|
|
||||||
}else {
|
|
||||||
federalType.value = "";
|
|
||||||
}
|
|
||||||
updateReadOnly(data.portfolio_type, '.field-portfolio_type');
|
|
||||||
})
|
})
|
||||||
.catch(error => console.error("Error fetching federal and portfolio types: ", error));
|
.catch(error => console.error("Error fetching federal and portfolio types: ", error));
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ def create_groups(apps, schema_editor) -> Any:
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
dependencies = [
|
dependencies = [
|
||||||
("registrar", "0129_portfolio_federal_type"),
|
("registrar", "0128_alter_domaininformation_state_territory_and_more"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
|
@ -1,24 +0,0 @@
|
||||||
# Generated by Django 4.2.10 on 2024-09-23 15:29
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("registrar", "0128_alter_domaininformation_state_territory_and_more"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name="portfolio",
|
|
||||||
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,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 4.2.10 on 2024-09-25 14:28
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("registrar", "0129_create_groups_v17"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="portfolio",
|
||||||
|
name="organization_name",
|
||||||
|
field=models.CharField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -34,7 +34,6 @@ class Portfolio(TimeStampedModel):
|
||||||
organization_name = models.CharField(
|
organization_name = models.CharField(
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
verbose_name="Portfolio organization",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
organization_type = models.CharField(
|
organization_type = models.CharField(
|
||||||
|
@ -58,14 +57,6 @@ class Portfolio(TimeStampedModel):
|
||||||
default=FederalAgency.get_non_federal_agency,
|
default=FederalAgency.get_non_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.)",
|
|
||||||
)
|
|
||||||
|
|
||||||
senior_official = models.ForeignKey(
|
senior_official = models.ForeignKey(
|
||||||
"registrar.SeniorOfficial",
|
"registrar.SeniorOfficial",
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
|
@ -131,28 +122,16 @@ class Portfolio(TimeStampedModel):
|
||||||
if self.state_territory != self.StateTerritoryChoices.PUERTO_RICO and self.urbanization:
|
if self.state_territory != self.StateTerritoryChoices.PUERTO_RICO and self.urbanization:
|
||||||
self.urbanization = None
|
self.urbanization = None
|
||||||
|
|
||||||
# Set the federal type field if it doesn't exist already
|
|
||||||
if self.federal_type is None and self.federal_agency and self.federal_agency.federal_type:
|
|
||||||
self.federal_type = self.federal_agency.federal_type if self.federal_agency else None
|
|
||||||
|
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def portfolio_type(self):
|
def federal_type(self):
|
||||||
"""
|
"""Returns the federal_type value on the underlying federal_agency field"""
|
||||||
Returns a combination of organization_type / federal_type, seperated by ' - '.
|
return self.get_federal_type(self.federal_agency)
|
||||||
If no federal_type is found, we just return the org type.
|
|
||||||
"""
|
|
||||||
return self.get_portfolio_type(self.organization_type, self.federal_type)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_portfolio_type(cls, organization_type, federal_type):
|
def get_federal_type(cls, federal_agency):
|
||||||
org_type_label = cls.OrganizationChoices.get_org_label(organization_type)
|
return federal_agency.federal_type if federal_agency else None
|
||||||
agency_type_label = BranchChoices.get_branch_label(federal_type)
|
|
||||||
if organization_type == cls.OrganizationChoices.FEDERAL and agency_type_label:
|
|
||||||
return " - ".join([org_type_label, agency_type_label])
|
|
||||||
else:
|
|
||||||
return org_type_label
|
|
||||||
|
|
||||||
# == Getters for domains == #
|
# == Getters for domains == #
|
||||||
def get_domains(self):
|
def get_domains(self):
|
||||||
|
|
|
@ -55,11 +55,9 @@ def get_federal_and_portfolio_types_from_federal_agency_json(request):
|
||||||
portfolio_type = None
|
portfolio_type = None
|
||||||
|
|
||||||
agency_name = request.GET.get("agency_name")
|
agency_name = request.GET.get("agency_name")
|
||||||
organization_type = request.GET.get("organization_type")
|
|
||||||
agency = FederalAgency.objects.filter(agency=agency_name).first()
|
agency = FederalAgency.objects.filter(agency=agency_name).first()
|
||||||
if agency:
|
if agency:
|
||||||
federal_type = agency.federal_type
|
federal_type = Portfolio.get_federal_type(agency)
|
||||||
portfolio_type = Portfolio.get_portfolio_type(organization_type, federal_type)
|
|
||||||
federal_type = BranchChoices.get_branch_label(federal_type) if federal_type else "-"
|
federal_type = BranchChoices.get_branch_label(federal_type) if federal_type else "-"
|
||||||
|
|
||||||
response_data = {
|
response_data = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue