Skip to content

Commit

Permalink
fix: admin service idp filter and wrong param names
Browse files Browse the repository at this point in the history
Ref HP-2169
  • Loading branch information
voneiden committed Mar 7, 2024
1 parent 689e4d7 commit 1e64d9b
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions services/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from guardian.admin import GuardedModelAdmin
from parler.admin import TranslatableAdmin

from .enums import ServiceIdp
from .models import AllowedDataField, Service, ServiceClientId, ServiceConnection


Expand All @@ -17,7 +18,7 @@ class ServiceClientIdInline(admin.StackedInline):

class AllowedDataFieldsFilter(admin.SimpleListFilter):
title = _("allowed data fields")
parameter_name = "empty"
parameter_name = "allowed_data_fields"

def lookups(self, request, model_admin):
names = (
Expand All @@ -38,6 +39,24 @@ def queryset(self, request, queryset):
return queryset


class IdpFilter(admin.SimpleListFilter):
title = _("IDP")
parameter_name = "idp"

def lookups(self, request, model_admin):
return [
("empty", _("Empty")),
] + [(value, label) for value, label in ServiceIdp.choices()]

def queryset(self, request, queryset):
value = self.value()
if value == "empty":
return queryset.filter(idp__isnull=True)
elif value:
return queryset.filter(idp__contains=[self.value()])
return queryset


@admin.register(Service)
class ServiceAdmin(TranslatableAdmin, GuardedModelAdmin):
list_display = (
Expand All @@ -47,7 +66,7 @@ class ServiceAdmin(TranslatableAdmin, GuardedModelAdmin):
"idp",
"_gdpr",
)
list_filter = (AllowedDataFieldsFilter, "idp")
list_filter = (AllowedDataFieldsFilter, IdpFilter)
search_fields = (
"name",
"translations__title",
Expand Down

0 comments on commit 1e64d9b

Please sign in to comment.