mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 19:09:22 +02:00
added multiple-choice-list-filter; set default filter selection; modified changelist template
This commit is contained in:
parent
9b9f1a5230
commit
018a2c353e
7 changed files with 187 additions and 134 deletions
|
@ -27,6 +27,7 @@ from django_fsm import TransitionNotAllowed # type: ignore
|
|||
from django.utils.safestring import mark_safe
|
||||
from django.utils.html import escape
|
||||
from django.contrib.auth.forms import UserChangeForm, UsernameField
|
||||
from django_admin_multiple_choice_list_filter.list_filters import MultipleChoiceListFilter
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
@ -959,6 +960,15 @@ class DomainRequestAdmin(ListHeaderAdmin):
|
|||
|
||||
form = DomainRequestAdminForm
|
||||
|
||||
class StatusListFilter(MultipleChoiceListFilter):
|
||||
"""Custom status filter which is a multiple choice filter"""
|
||||
|
||||
title = "Status"
|
||||
parameter_name = "status__in"
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
return DomainRequest.DomainRequestStatus.choices
|
||||
|
||||
class InvestigatorFilter(admin.SimpleListFilter):
|
||||
"""Custom investigator filter that only displays users with the manager role"""
|
||||
|
||||
|
@ -1051,7 +1061,7 @@ class DomainRequestAdmin(ListHeaderAdmin):
|
|||
|
||||
# Filters
|
||||
list_filter = (
|
||||
"status",
|
||||
StatusListFilter,
|
||||
"generic_org_type",
|
||||
"federal_type",
|
||||
ElectionOfficeFilter,
|
||||
|
@ -1313,6 +1323,23 @@ class DomainRequestAdmin(ListHeaderAdmin):
|
|||
"Cannot edit a domain request with a restricted creator.",
|
||||
)
|
||||
|
||||
def changelist_view(self, request, extra_context=None):
|
||||
"""
|
||||
Override changelist_view to set the selected value of status filter.
|
||||
"""
|
||||
# use http_referer in order to distinguish between request as a link from another page
|
||||
# and request as a removal of all filters
|
||||
http_referer = request.META.get("HTTP_REFERER", "")
|
||||
# if there are no query parameters in the request
|
||||
# and the request is the initial request for this view
|
||||
if not bool(request.GET) and request.path not in http_referer:
|
||||
# modify the GET of the request to set the selected filter
|
||||
modified_get = request.GET.copy()
|
||||
modified_get["status__in"] = "submitted"
|
||||
request.GET = modified_get
|
||||
response = super().changelist_view(request, extra_context=extra_context)
|
||||
return response
|
||||
|
||||
def change_view(self, request, object_id, form_url="", extra_context=None):
|
||||
obj = self.get_object(request, object_id)
|
||||
self.display_restricted_warning(request, obj)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue