mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-21 03:49:22 +02:00
updated portfolio changeform view in admin
This commit is contained in:
parent
e59d4738e3
commit
6286ae96be
1 changed files with 21 additions and 12 deletions
|
@ -2279,7 +2279,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
portfolio_id = request.GET.get('portfolio')
|
portfolio_id = request.GET.get('portfolio')
|
||||||
if portfolio_id:
|
if portfolio_id:
|
||||||
# Further filter the queryset by the portfolio
|
# Further filter the queryset by the portfolio
|
||||||
qs = qs.filter(DomainRequest_info__portfolio=portfolio_id)
|
qs = qs.filter(portfolio=portfolio_id)
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
def get_changelist(self, request, **kwargs):
|
def get_changelist(self, request, **kwargs):
|
||||||
|
@ -2942,7 +2942,7 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
# "classes": ("collapse", "closed"),
|
# "classes": ("collapse", "closed"),
|
||||||
# "fields": ["administrators", "members"]}
|
# "fields": ["administrators", "members"]}
|
||||||
# ),
|
# ),
|
||||||
("Portfolio domains", {"classes": ("collapse", "closed"), "fields": ["domains", "domain_requests"]}),
|
("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",
|
||||||
|
@ -3024,18 +3024,27 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
suborganizations.short_description = "Suborganizations" # type: ignore
|
suborganizations.short_description = "Suborganizations" # type: ignore
|
||||||
|
|
||||||
def domains(self, obj: models.Portfolio):
|
def domains(self, obj: models.Portfolio):
|
||||||
"""Returns a list of links for each related domain"""
|
"""Returns the count of domains with a link to view them in the admin."""
|
||||||
queryset = obj.get_domains()
|
domain_count = obj.get_domains().count() # Count the related domains
|
||||||
return self.get_field_links_as_list(
|
if domain_count > 0:
|
||||||
queryset, "domaininformation", link_info_attribute="get_state_display_of_domain"
|
# Construct the URL to the admin page, filtered by portfolio
|
||||||
)
|
url = reverse("admin:registrar_domain_changelist") + f"?portfolio={obj.id}"
|
||||||
|
label = "Domain" if domain_count == 1 else "Domains"
|
||||||
|
# Create a clickable link with the domain count
|
||||||
|
return format_html('<a href="{}">{} {}</a>', url, domain_count, label)
|
||||||
|
return "No Domains"
|
||||||
|
|
||||||
domains.short_description = "Domains" # type: ignore
|
domains.short_description = "Domains" # type: ignore
|
||||||
|
|
||||||
def domain_requests(self, obj: models.Portfolio):
|
def domain_requests(self, obj: models.Portfolio):
|
||||||
"""Returns a list of links for each related domain request"""
|
"""Returns the count of domain requests with a link to view them in the admin."""
|
||||||
queryset = obj.get_domain_requests()
|
domain_request_count = obj.get_domain_requests().count() # Count the related domain requests
|
||||||
return self.get_field_links_as_list(queryset, "domainrequest", link_info_attribute="get_status_display")
|
if domain_request_count > 0:
|
||||||
|
# Construct the URL to the admin page, filtered by portfolio
|
||||||
|
url = reverse("admin:registrar_domainrequest_changelist") + f"?portfolio={obj.id}"
|
||||||
|
# Create a clickable link with the domain request count
|
||||||
|
return format_html('<a href="{}">{} Domain Requests</a>', url, domain_request_count)
|
||||||
|
return "No Domain Requests"
|
||||||
|
|
||||||
domain_requests.short_description = "Domain requests" # type: ignore
|
domain_requests.short_description = "Domain requests" # type: ignore
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue