mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-27 21:16:28 +02:00
changes
This commit is contained in:
parent
6e788d1c79
commit
a80071598d
3 changed files with 72 additions and 13 deletions
|
@ -1640,6 +1640,70 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
def lookups(self, request, model_admin):
|
||||
return DomainRequest.DomainRequestStatus.choices
|
||||
|
||||
class GenericOrgFilter(admin.SimpleListFilter):
|
||||
"""Custom Generic Organization filter that accomodates portfolio feature.
|
||||
If we have a portfolio, use the portfolio's organization. If not, use the
|
||||
organization in the Domain Information object."""
|
||||
|
||||
title = "generic organization"
|
||||
parameter_name = "converted_generic_orgs"
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
converted_generic_orgs = set()
|
||||
|
||||
for domain_request in DomainRequest.objects.all():
|
||||
converted_generic_org = domain_request.converted_generic_org_type
|
||||
if converted_generic_org:
|
||||
converted_generic_orgs.add(converted_generic_org)
|
||||
|
||||
return sorted((org, org) for org in converted_generic_orgs)
|
||||
|
||||
# Filter queryset
|
||||
def queryset(self, request, queryset):
|
||||
if self.value(): # Check if a generic org is selected in the filter
|
||||
return queryset.filter(
|
||||
# Filter based on the generic org value returned by converted_generic_org_type
|
||||
id__in=[
|
||||
domain_request.id
|
||||
for domain_request in queryset
|
||||
if domain_request.converted_generic_org_type
|
||||
and domain_request.converted_generic_org_type == self.value()
|
||||
]
|
||||
)
|
||||
return queryset
|
||||
|
||||
class FederalTypeFilter(admin.SimpleListFilter):
|
||||
"""Custom Federal Type filter that accomodates portfolio feature.
|
||||
If we have a portfolio, use the portfolio's federal type. If not, use the
|
||||
organization in the Domain Request object."""
|
||||
|
||||
title = "federal Type"
|
||||
parameter_name = "converted_federal_types"
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
converted_federal_types = set()
|
||||
|
||||
for domain_request in DomainRequest.objects.all():
|
||||
converted_federal_type = domain_request.converted_federal_type
|
||||
if converted_federal_type:
|
||||
converted_federal_types.add(converted_federal_type)
|
||||
|
||||
return sorted((type, type) for type in converted_federal_types)
|
||||
|
||||
# Filter queryset
|
||||
def queryset(self, request, queryset):
|
||||
if self.value(): # Check if federal Type is selected in the filter
|
||||
return queryset.filter(
|
||||
# Filter based on the federal type returned by converted_federal_type
|
||||
id__in=[
|
||||
domain_request.id
|
||||
for domain_request in queryset
|
||||
if domain_request.converted_federal_type
|
||||
and domain_request.converted_federal_type == self.value()
|
||||
]
|
||||
)
|
||||
return queryset
|
||||
|
||||
class InvestigatorFilter(admin.SimpleListFilter):
|
||||
"""Custom investigator filter that only displays users with the manager role"""
|
||||
|
||||
|
@ -1700,11 +1764,6 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
if self.value() == "0":
|
||||
return queryset.filter(Q(is_election_board=False) | Q(is_election_board=None))
|
||||
|
||||
class FederalTypeFilter(admin.SimpleListFilter):
|
||||
"Define a custom filter for federal type"
|
||||
title = 'Federal Type'
|
||||
parameter_name = 'converted_federal_type'
|
||||
|
||||
@admin.display(description=_("Generic Org Type"))
|
||||
def converted_generic_org_type(self, obj):
|
||||
return obj.converted_generic_org_type
|
||||
|
@ -1767,8 +1826,8 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
# Filters
|
||||
list_filter = (
|
||||
StatusListFilter,
|
||||
"generic_org_type",
|
||||
"federal_type",
|
||||
GenericOrgFilter,
|
||||
FederalTypeFilter,
|
||||
ElectionOfficeFilter,
|
||||
"rejection_reason",
|
||||
InvestigatorFilter,
|
||||
|
@ -1881,7 +1940,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
|
||||
# Read only that we'll leverage for CISA Analysts
|
||||
analyst_readonly_fields = [
|
||||
"converted_federal_agency",
|
||||
"federal_agency",
|
||||
"creator",
|
||||
"about_your_organization",
|
||||
"requested_domain",
|
||||
|
|
|
@ -576,7 +576,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
response = self.client.get("/admin/registrar/domainrequest/?generic_org_type__exact=federal")
|
||||
# There are 2 template references to Federal (4) and two in the results data
|
||||
# of the request
|
||||
self.assertContains(response, "Federal", count=52)
|
||||
self.assertContains(response, "Federal", count=51)
|
||||
# This may be a bit more robust
|
||||
self.assertContains(response, '<td class="field-converted_generic_org_type">federal</td>', count=1)
|
||||
# Now let's make sure the long description does not exist
|
||||
|
@ -1696,7 +1696,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
"alternative_domains",
|
||||
"is_election_board",
|
||||
"status_history",
|
||||
"converted_federal_agency",
|
||||
"federal_agency",
|
||||
"creator",
|
||||
"about_your_organization",
|
||||
"requested_domain",
|
||||
|
@ -1935,8 +1935,8 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
readonly_fields = self.admin.get_list_filter(request)
|
||||
expected_fields = (
|
||||
DomainRequestAdmin.StatusListFilter,
|
||||
"generic_org_type",
|
||||
"federal_type",
|
||||
DomainRequestAdmin.GenericOrgFilter,
|
||||
DomainRequestAdmin.FederalTypeFilter,
|
||||
DomainRequestAdmin.ElectionOfficeFilter,
|
||||
"rejection_reason",
|
||||
DomainRequestAdmin.InvestigatorFilter,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue