mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-28 05:26:28 +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.functions import Concat, Coalesce
|
||||
from django.http import HttpResponseRedirect
|
||||
from registrar.models.federal_agency import FederalAgency
|
||||
from registrar.utility.admin_helpers import (
|
||||
get_action_needed_reason_default_email,
|
||||
get_rejection_reason_default_email,
|
||||
|
@ -3192,6 +3193,9 @@ class PortfolioAdmin(ListHeaderAdmin):
|
|||
return self.add_fieldsets
|
||||
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):
|
||||
"""Set the read-only state on form elements.
|
||||
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
|
||||
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"):
|
||||
return readonly_fields
|
||||
|
||||
|
@ -3228,7 +3240,7 @@ class PortfolioAdmin(ListHeaderAdmin):
|
|||
extra_context["domain_requests"] = obj.get_domain_requests(order_by=["requested_domain__name"])
|
||||
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:
|
||||
# ---- update creator ----
|
||||
|
@ -3243,12 +3255,20 @@ class PortfolioAdmin(ListHeaderAdmin):
|
|||
if is_federal and obj.organization_name is None:
|
||||
obj.organization_name = obj.federal_agency.agency
|
||||
|
||||
# Remove this line when senior_official is no longer readonly in /admin.
|
||||
if obj.federal_agency:
|
||||
if obj.federal_agency.so_federal_agency.exists():
|
||||
obj.senior_official = obj.federal_agency.so_federal_agency.first()
|
||||
else:
|
||||
obj.senior_official = None
|
||||
# TODO - this should be handled almost entirely in javascript
|
||||
# Handle the federal agency and senior official fields
|
||||
if obj.organization_type == obj.OrganizationChoices.FEDERAL:
|
||||
if obj.federal_agency:
|
||||
if obj.federal_agency.so_federal_agency.exists():
|
||||
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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue