Commit d78c7809 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Change user admin

parent 724123a9
......@@ -3,6 +3,8 @@ from django.contrib.admin import SimpleListFilter
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserCreationForm
from ..auth.v1.models import OIDCConfig
from ..models import User
......@@ -19,6 +21,21 @@ class TypeFilter(SimpleListFilter):
return queryset
class IdPFilter(SimpleListFilter):
title = 'IdP'
parameter_name = 'idp'
# returns sorted list of pairs
def lookups(self, request, model_admin):
queryset = OIDCConfig.objects.order_by('name')
return [(idp.id, idp.name) for idp in queryset]
def queryset(self, request, queryset):
if self.value():
return queryset.filter(idp=OIDCConfig.objects.get(id=self.value()))
return queryset
# from https://docs.djangoproject.com/en/2.2/topics/auth/customizing/#custom-users-and-the-built-in-auth-forms
class CustomUserCreationForm(UserCreationForm):
......@@ -30,12 +47,14 @@ class CustomUserCreationForm(UserCreationForm):
class CustomUserAdmin(UserAdmin):
list_filter = (TypeFilter,)
list_display = ('username', 'user_type', 'email', 'idp', 'is_staff', 'is_superuser')
list_filter = (TypeFilter, IdPFilter,)
add_form = CustomUserCreationForm
fieldsets = UserAdmin.fieldsets + (
(None, {'fields': ('user_type',)}),
)
add_fieldsets = UserAdmin.add_fieldsets + (
(None, {'fields': ('user_type',)}),
fieldsets = (
(None, {'fields': ('username', 'password', 'user_type',)}),
('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser',)}),
('Important dates', {'fields': ('last_login', 'date_joined')}),
)
add_fieldsets = ((None, {'fields': ('user_type',)}),) + UserAdmin.add_fieldsets
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment