mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 03:58:39 +02:00
updated filters and results list header
This commit is contained in:
parent
9b86a154d0
commit
262acee1cd
3 changed files with 63 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.db.models import Q
|
||||||
from django.db.models.functions import Concat
|
from django.db.models.functions import Concat
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
|
@ -22,6 +23,7 @@ from auditlog.admin import LogEntryAdmin # type: ignore
|
||||||
from django_fsm import TransitionNotAllowed # type: ignore
|
from django_fsm import TransitionNotAllowed # type: ignore
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -762,6 +764,24 @@ class DomainApplicationAdmin(ListHeaderAdmin):
|
||||||
else:
|
else:
|
||||||
return queryset.filter(investigator__id__exact=self.value())
|
return queryset.filter(investigator__id__exact=self.value())
|
||||||
|
|
||||||
|
class ElectionOfficeFilter(admin.SimpleListFilter):
|
||||||
|
"""Define a custom filter for is_election_board"""
|
||||||
|
|
||||||
|
title = _("election office")
|
||||||
|
parameter_name = "is_election_board"
|
||||||
|
|
||||||
|
def lookups(self, request, model_admin):
|
||||||
|
return (
|
||||||
|
("1", _("Yes")),
|
||||||
|
("0", _("No")),
|
||||||
|
)
|
||||||
|
|
||||||
|
def queryset(self, request, queryset):
|
||||||
|
if self.value() == "1":
|
||||||
|
return queryset.filter(is_election_board=True)
|
||||||
|
if self.value() == "0":
|
||||||
|
return queryset.filter(Q(is_election_board=False) | Q(is_election_board=None))
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
list_display = [
|
list_display = [
|
||||||
"requested_domain",
|
"requested_domain",
|
||||||
|
@ -785,13 +805,13 @@ class DomainApplicationAdmin(ListHeaderAdmin):
|
||||||
]
|
]
|
||||||
|
|
||||||
def custom_election_board(self, obj):
|
def custom_election_board(self, obj):
|
||||||
return obj.is_election_board if obj.is_election_board else False
|
return "Yes" if obj.is_election_board else "No"
|
||||||
|
|
||||||
custom_election_board.admin_order_field = "is_election_board" # type: ignore
|
custom_election_board.admin_order_field = "is_election_board" # type: ignore
|
||||||
custom_election_board.short_description = "Election office" # type: ignore
|
custom_election_board.short_description = "Election office" # type: ignore
|
||||||
|
|
||||||
# Filters
|
# Filters
|
||||||
list_filter = ("status", "organization_type", "is_election_board", "federal_type", InvestigatorFilter)
|
list_filter = ("status", "organization_type", "federal_type", ElectionOfficeFilter, InvestigatorFilter)
|
||||||
|
|
||||||
# Search
|
# Search
|
||||||
search_fields = [
|
search_fields = [
|
||||||
|
@ -1044,6 +1064,25 @@ class DomainInformationInline(admin.StackedInline):
|
||||||
class DomainAdmin(ListHeaderAdmin):
|
class DomainAdmin(ListHeaderAdmin):
|
||||||
"""Custom domain admin class to add extra buttons."""
|
"""Custom domain admin class to add extra buttons."""
|
||||||
|
|
||||||
|
class ElectionOfficeFilter(admin.SimpleListFilter):
|
||||||
|
"""Define a custom filter for is_election_board"""
|
||||||
|
|
||||||
|
title = _("election office")
|
||||||
|
parameter_name = "is_election_board"
|
||||||
|
|
||||||
|
def lookups(self, request, model_admin):
|
||||||
|
return (
|
||||||
|
("1", _("Yes")),
|
||||||
|
("0", _("No")),
|
||||||
|
)
|
||||||
|
|
||||||
|
def queryset(self, request, queryset):
|
||||||
|
logger.debug(self.value())
|
||||||
|
if self.value() == "1":
|
||||||
|
return queryset.filter(domain_info__is_election_board=True)
|
||||||
|
if self.value() == "0":
|
||||||
|
return queryset.filter(Q(domain_info__is_election_board=False) | Q(domain_info__is_election_board=None))
|
||||||
|
|
||||||
inlines = [DomainInformationInline]
|
inlines = [DomainInformationInline]
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
|
@ -1053,7 +1092,7 @@ class DomainAdmin(ListHeaderAdmin):
|
||||||
"federal_type",
|
"federal_type",
|
||||||
"federal_agency",
|
"federal_agency",
|
||||||
"organization_name",
|
"organization_name",
|
||||||
"is_election_board",
|
"custom_election_board",
|
||||||
"city",
|
"city",
|
||||||
"state_territory",
|
"state_territory",
|
||||||
"state",
|
"state",
|
||||||
|
@ -1094,11 +1133,11 @@ class DomainAdmin(ListHeaderAdmin):
|
||||||
|
|
||||||
organization_name.admin_order_field = "domain_info__organization_name" # type: ignore
|
organization_name.admin_order_field = "domain_info__organization_name" # type: ignore
|
||||||
|
|
||||||
def is_election_board(self, obj):
|
def custom_election_board(self, obj):
|
||||||
return obj.domain_info.is_election_board if obj.domain_info else False
|
return "Yes" if obj.domain_info.is_election_board else "No"
|
||||||
|
|
||||||
is_election_board.admin_order_field = "domain_info__is_election_board" # type: ignore
|
custom_election_board.admin_order_field = "domain_info__is_election_board" # type: ignore
|
||||||
is_election_board.short_description = "Election office" # type: ignore
|
custom_election_board.short_description = "Election office" # type: ignore
|
||||||
|
|
||||||
def city(self, obj):
|
def city(self, obj):
|
||||||
return obj.domain_info.city if obj.domain_info else None
|
return obj.domain_info.city if obj.domain_info else None
|
||||||
|
@ -1111,7 +1150,7 @@ class DomainAdmin(ListHeaderAdmin):
|
||||||
state_territory.admin_order_field = "domain_info__state_territory" # type: ignore
|
state_territory.admin_order_field = "domain_info__state_territory" # type: ignore
|
||||||
|
|
||||||
# Filters
|
# Filters
|
||||||
list_filter = ["domain_info__organization_type", "state", "domain_info__is_election_board", "domain_info__federal_type"]
|
list_filter = ["domain_info__organization_type", "state", "domain_info__federal_type", ElectionOfficeFilter]
|
||||||
|
|
||||||
search_fields = ["name"]
|
search_fields = ["name"]
|
||||||
search_help_text = "Search by domain name."
|
search_help_text = "Search by domain name."
|
||||||
|
|
|
@ -15,7 +15,15 @@
|
||||||
{% if filters %}
|
{% if filters %}
|
||||||
filtered by
|
filtered by
|
||||||
{% for filter_param in filters %}
|
{% for filter_param in filters %}
|
||||||
{{ filter_param.parameter_name }} = {{ filter_param.parameter_value }}
|
{% if filter_param.parameter_name == 'is_election_board' %}
|
||||||
|
{%if filter_param.parameter_value == '0' %}
|
||||||
|
election office = No
|
||||||
|
{% else %}
|
||||||
|
election office = Yes
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
{{ filter_param.parameter_name }} = {{ filter_param.parameter_value }}
|
||||||
|
{% endif %}
|
||||||
{% if not forloop.last %}, {% endif %}
|
{% if not forloop.last %}, {% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -847,7 +847,13 @@ class TestDomainApplicationAdmin(MockEppLib):
|
||||||
|
|
||||||
# Grab the current list of table filters
|
# Grab the current list of table filters
|
||||||
readonly_fields = self.admin.get_list_filter(request)
|
readonly_fields = self.admin.get_list_filter(request)
|
||||||
expected_fields = ("status", "organization_type", DomainApplicationAdmin.InvestigatorFilter)
|
expected_fields = (
|
||||||
|
"status",
|
||||||
|
"organization_type",
|
||||||
|
"federal_type",
|
||||||
|
DomainApplicationAdmin.ElectionOfficeFilter,
|
||||||
|
DomainApplicationAdmin.InvestigatorFilter,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(readonly_fields, expected_fields)
|
self.assertEqual(readonly_fields, expected_fields)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue