mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-28 13:36:30 +02:00
initial changes
This commit is contained in:
parent
570340a172
commit
aeb496ceae
2 changed files with 30 additions and 7 deletions
|
@ -5,6 +5,7 @@ from django import forms
|
||||||
from django.db.models import Value, CharField, Q
|
from django.db.models import Value, CharField, Q
|
||||||
from django.db.models.functions import Concat, Coalesce
|
from django.db.models.functions import Concat, Coalesce
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
|
from registrar.models.federal_agency import FederalAgency
|
||||||
from registrar.utility.admin_helpers import (
|
from registrar.utility.admin_helpers import (
|
||||||
get_action_needed_reason_default_email,
|
get_action_needed_reason_default_email,
|
||||||
get_rejection_reason_default_email,
|
get_rejection_reason_default_email,
|
||||||
|
@ -3192,6 +3193,9 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
return self.add_fieldsets
|
return self.add_fieldsets
|
||||||
return super().get_fieldsets(request, obj)
|
return super().get_fieldsets(request, obj)
|
||||||
|
|
||||||
|
# TODO - I think the solution to this may just be to set this as editable.
|
||||||
|
# Then in the underlying page override, we need a fake readonly display that
|
||||||
|
# is toggled on or off.
|
||||||
def get_readonly_fields(self, request, obj=None):
|
def get_readonly_fields(self, request, obj=None):
|
||||||
"""Set the read-only state on form elements.
|
"""Set the read-only state on form elements.
|
||||||
We have 2 conditions that determine which fields are read-only:
|
We have 2 conditions that determine which fields are read-only:
|
||||||
|
@ -3206,6 +3210,14 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
# straightforward and the readonly_fields list can control their behavior
|
# straightforward and the readonly_fields list can control their behavior
|
||||||
readonly_fields.extend([field.name for field in self.model._meta.fields])
|
readonly_fields.extend([field.name for field in self.model._meta.fields])
|
||||||
|
|
||||||
|
# Make senior_official readonly for federal organizations
|
||||||
|
if obj and obj.organization_type == obj.OrganizationChoices.FEDERAL:
|
||||||
|
if "senior_official" not in readonly_fields:
|
||||||
|
readonly_fields.append("senior_official")
|
||||||
|
elif "senior_official" in readonly_fields:
|
||||||
|
# Remove senior_official from readonly_fields if org is non-federal
|
||||||
|
readonly_fields.remove("senior_official")
|
||||||
|
|
||||||
if request.user.has_perm("registrar.full_access_permission"):
|
if request.user.has_perm("registrar.full_access_permission"):
|
||||||
return readonly_fields
|
return readonly_fields
|
||||||
|
|
||||||
|
@ -3228,7 +3240,7 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
extra_context["domain_requests"] = obj.get_domain_requests(order_by=["requested_domain__name"])
|
extra_context["domain_requests"] = obj.get_domain_requests(order_by=["requested_domain__name"])
|
||||||
return super().change_view(request, object_id, form_url, extra_context)
|
return super().change_view(request, object_id, form_url, extra_context)
|
||||||
|
|
||||||
def save_model(self, request, obj, form, change):
|
def save_model(self, request, obj: Portfolio, form, change):
|
||||||
|
|
||||||
if hasattr(obj, "creator") is False:
|
if hasattr(obj, "creator") is False:
|
||||||
# ---- update creator ----
|
# ---- update creator ----
|
||||||
|
@ -3243,12 +3255,20 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
if is_federal and obj.organization_name is None:
|
if is_federal and obj.organization_name is None:
|
||||||
obj.organization_name = obj.federal_agency.agency
|
obj.organization_name = obj.federal_agency.agency
|
||||||
|
|
||||||
# Remove this line when senior_official is no longer readonly in /admin.
|
# TODO - this should be handled almost entirely in javascript
|
||||||
if obj.federal_agency:
|
# Handle the federal agency and senior official fields
|
||||||
if obj.federal_agency.so_federal_agency.exists():
|
if obj.organization_type == obj.OrganizationChoices.FEDERAL:
|
||||||
obj.senior_official = obj.federal_agency.so_federal_agency.first()
|
if obj.federal_agency:
|
||||||
else:
|
if obj.federal_agency.so_federal_agency.exists():
|
||||||
obj.senior_official = None
|
obj.senior_official = obj.federal_agency.so_federal_agency.first()
|
||||||
|
else:
|
||||||
|
obj.senior_official = None
|
||||||
|
else:
|
||||||
|
if obj.federal_agency and obj.federal_agency.agency != "Non-Federal Agency":
|
||||||
|
if obj.federal_agency.so_federal_agency.first() == obj.senior_official:
|
||||||
|
obj.senior_official = None
|
||||||
|
obj.federal_agency = FederalAgency.objects.filter(agency="Non-Federal Agency").first()
|
||||||
|
|
||||||
|
|
||||||
super().save_model(request, obj, form, change)
|
super().save_model(request, obj, form, change)
|
||||||
|
|
||||||
|
|
|
@ -927,6 +927,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
|
||||||
// This is the additional information that exists beneath the SO element.
|
// This is the additional information that exists beneath the SO element.
|
||||||
var contactList = document.querySelector(".field-senior_official .dja-address-contact-list");
|
var contactList = document.querySelector(".field-senior_official .dja-address-contact-list");
|
||||||
|
const federalAgencyContainer = document.querySelector(".field-federal_agency");
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
|
||||||
let isPortfolioPage = document.getElementById("portfolio_form");
|
let isPortfolioPage = document.getElementById("portfolio_form");
|
||||||
|
@ -975,11 +976,13 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
let selectedValue = organizationType.value;
|
let selectedValue = organizationType.value;
|
||||||
if (selectedValue === "federal") {
|
if (selectedValue === "federal") {
|
||||||
hideElement(organizationNameContainer);
|
hideElement(organizationNameContainer);
|
||||||
|
showElement(federalAgencyContainer);
|
||||||
if (federalType) {
|
if (federalType) {
|
||||||
showElement(federalType);
|
showElement(federalType);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showElement(organizationNameContainer);
|
showElement(organizationNameContainer);
|
||||||
|
hideElement(federalAgencyContainer);
|
||||||
if (federalType) {
|
if (federalType) {
|
||||||
hideElement(federalType);
|
hideElement(federalType);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue