From ae174208be5754c2c6fe3a6dad7d0ae1503f0693 Mon Sep 17 00:00:00 2001 From: Matti Eiden Date: Fri, 24 May 2024 10:48:04 +0300 Subject: [PATCH 1/2] fix: improve ModelAdmins for ADGroupMapping and ADGroup Adds new columns, sorting, searching, filtering and default ordering. Refs: RAT-173 --- helusers/admin.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/helusers/admin.py b/helusers/admin.py index 03e7a13..7074071 100644 --- a/helusers/admin.py +++ b/helusers/admin.py @@ -1,15 +1,53 @@ from django.conf import settings from django.contrib import admin +from django.utils.translation import gettext_lazy as _ from .models import ADGroup, ADGroupMapping, OIDCBackChannelLogoutEvent @admin.register(ADGroupMapping) class ADGroupMappingAdmin(admin.ModelAdmin): - pass - - -admin.site.register(ADGroup) + list_display = [ + "get_str", + "get_ad_group_name", + "get_ad_group_display_name", + "group", + ] + list_filter = ("group",) + search_fields = ( + "group__name", + "ad_group__name", + "ad_group__display_name", + ) + + ordering = ("ad_group__display_name", "group") + + @admin.display(description="Mapping") + def get_str(self, obj): + return str(obj) + + @admin.display(description=_("AD group name"), ordering="ad_group__name") + def get_ad_group_name(self, obj): + return obj.ad_group.name + + @admin.display( + description=_("AD group display name"), ordering="ad_group__display_name" + ) + def get_ad_group_display_name(self, obj): + return obj.ad_group.display_name + + +@admin.register(ADGroup) +class ADGroupAdmin(admin.ModelAdmin): + list_display = [ + "display_name", + "name", + ] + search_fields = ( + "display_name", + "name", + ) + ordering = ("display_name", "name") if getattr(settings, "HELUSERS_BACK_CHANNEL_LOGOUT_ENABLED", False): From fd9888a6b75be0b539530ed5d25505558be5b410 Mon Sep 17 00:00:00 2001 From: Matti Eiden Date: Fri, 31 May 2024 21:04:00 +0300 Subject: [PATCH 2/2] fix: make admin description translatable Co-authored-by: Tuomas Haapala --- helusers/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helusers/admin.py b/helusers/admin.py index 7074071..c7f07f3 100644 --- a/helusers/admin.py +++ b/helusers/admin.py @@ -22,7 +22,7 @@ class ADGroupMappingAdmin(admin.ModelAdmin): ordering = ("ad_group__display_name", "group") - @admin.display(description="Mapping") + @admin.display(description=_("Mapping")) def get_str(self, obj): return str(obj)