Skip to content

Commit

Permalink
Bug fix to allow filtering by waiver types from django admin console (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sambodeme authored Jul 15, 2024
1 parent f28d196 commit 8f8bb19
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion backend/audit/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
validate_auditee_certification_json,
validate_auditor_certification_json,
)
from django.contrib.admin import SimpleListFilter
from django.utils.translation import gettext_lazy as _


class SACAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -93,6 +95,26 @@ class SubmissionEventAdmin(admin.ModelAdmin):
search_fields = ("sac__report_id", "user__username")


class WaiverTypesFilter(SimpleListFilter):
title = _("Waiver Types")
parameter_name = "waiver_types"

def lookups(self, request, model_admin):
waiver_types = set(
[
waiver_type
for waiver in SacValidationWaiver.objects.all()
for waiver_type in waiver.waiver_types
]
)
return [(waiver_type, waiver_type) for waiver_type in waiver_types]

def queryset(self, request, queryset):
if self.value():
return queryset.filter(waiver_types__contains=[self.value()])
return queryset


class SacValidationWaiverAdmin(admin.ModelAdmin):
form = SacValidationWaiverForm
list_display = (
Expand All @@ -101,7 +123,7 @@ class SacValidationWaiverAdmin(admin.ModelAdmin):
"approver_email",
"requester_email",
)
list_filter = ("timestamp", "waiver_types")
list_filter = ("timestamp", WaiverTypesFilter)
search_fields = (
"report_id__report_id",
"approver_email",
Expand Down

0 comments on commit 8f8bb19

Please sign in to comment.