2019-08-02 12:57:53 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
|
|
|
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2017-06-11 23:34:13 +00:00
|
|
|
|
|
|
|
from django.contrib import admin
|
|
|
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
2019-08-02 12:57:53 +00:00
|
|
|
from django.contrib.auth.models import Group
|
2017-06-11 23:34:13 +00:00
|
|
|
from reversion.admin import VersionAdmin
|
|
|
|
|
|
|
|
from .forms import UserChangeForm, UserCreationForm
|
2019-08-02 12:57:53 +00:00
|
|
|
from .models import User, Right, Adhesion, ListRight, Clef, Request
|
2017-06-11 23:34:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserAdmin(admin.ModelAdmin):
|
|
|
|
list_display = (
|
|
|
|
'name',
|
|
|
|
'surname',
|
|
|
|
'pseudo',
|
|
|
|
'email',
|
2019-08-02 19:14:16 +00:00
|
|
|
'is_active'
|
2017-06-11 23:34:13 +00:00
|
|
|
)
|
2019-08-02 12:57:53 +00:00
|
|
|
search_fields = ('name', 'surname', 'pseudo')
|
|
|
|
|
2017-06-11 23:34:13 +00:00
|
|
|
|
|
|
|
class RequestAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('user', 'type', 'created_at', 'expires_at')
|
|
|
|
|
2019-08-02 12:57:53 +00:00
|
|
|
|
2017-06-30 01:25:07 +00:00
|
|
|
class RightAdmin(VersionAdmin):
|
|
|
|
list_display = ('user', 'right')
|
|
|
|
|
2019-08-02 12:57:53 +00:00
|
|
|
|
2017-07-03 18:06:21 +00:00
|
|
|
class ClefAdmin(VersionAdmin):
|
|
|
|
list_display = ('proprio', 'nom')
|
|
|
|
|
2019-08-02 12:57:53 +00:00
|
|
|
|
2017-07-04 22:47:05 +00:00
|
|
|
class AdhesionAdmin(VersionAdmin):
|
|
|
|
list_display = ('annee_debut', 'annee_fin')
|
|
|
|
|
2019-08-02 12:57:53 +00:00
|
|
|
|
2017-06-30 01:25:07 +00:00
|
|
|
class ListRightAdmin(VersionAdmin):
|
|
|
|
list_display = ('listright',)
|
2017-06-11 23:34:13 +00:00
|
|
|
|
2019-08-02 12:57:53 +00:00
|
|
|
|
2017-06-11 23:34:13 +00:00
|
|
|
class UserAdmin(VersionAdmin, BaseUserAdmin):
|
|
|
|
# The forms to add and change user instances
|
|
|
|
form = UserChangeForm
|
|
|
|
add_form = UserCreationForm
|
|
|
|
|
|
|
|
# The fields to be used in displaying the User model.
|
|
|
|
# These override the definitions on the base UserAdmin
|
|
|
|
# that reference specific fields on auth.User.
|
|
|
|
list_display = ('pseudo', 'name', 'surname', 'email', 'is_admin')
|
|
|
|
list_filter = ()
|
|
|
|
fieldsets = (
|
|
|
|
(None, {'fields': ('pseudo', 'password')}),
|
|
|
|
('Personal info', {'fields': ('name', 'surname', 'email')}),
|
2019-08-02 12:57:53 +00:00
|
|
|
('Permissions', {'fields': ('is_admin',)}),
|
2017-06-11 23:34:13 +00:00
|
|
|
)
|
|
|
|
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
|
|
|
|
# overrides get_fieldsets to use this attribute when creating a user.
|
|
|
|
add_fieldsets = (
|
|
|
|
(None, {
|
|
|
|
'classes': ('wide',),
|
|
|
|
'fields': ('pseudo', 'name', 'surname', 'email', 'is_admin', 'password1', 'password2')}
|
2019-08-02 12:57:53 +00:00
|
|
|
),
|
2017-06-11 23:34:13 +00:00
|
|
|
)
|
|
|
|
search_fields = ('pseudo',)
|
|
|
|
ordering = ('pseudo',)
|
|
|
|
filter_horizontal = ()
|
|
|
|
|
2019-08-02 12:57:53 +00:00
|
|
|
|
2017-06-11 23:34:13 +00:00
|
|
|
admin.site.register(User, UserAdmin)
|
|
|
|
admin.site.register(Request, RequestAdmin)
|
2017-06-30 01:25:07 +00:00
|
|
|
admin.site.register(ListRight, ListRightAdmin)
|
|
|
|
admin.site.register(Right, RightAdmin)
|
2017-07-04 22:47:05 +00:00
|
|
|
admin.site.register(Adhesion, AdhesionAdmin)
|
2017-07-03 18:06:21 +00:00
|
|
|
admin.site.register(Clef, ClefAdmin)
|
2017-06-11 23:34:13 +00:00
|
|
|
# Now register the new UserAdmin...
|
|
|
|
admin.site.unregister(User)
|
|
|
|
admin.site.register(User, UserAdmin)
|
|
|
|
# ... and, since we're not using Django's built-in permissions,
|
|
|
|
# unregister the Group model from admin.
|
|
|
|
admin.site.unregister(Group)
|