admin.py 3.1 KB
Newer Older
lhark's avatar
lhark committed
1
from django.contrib import admin
2 3
from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
4
from reversion.admin import VersionAdmin
lhark's avatar
lhark committed
5

6
from .models import User, School, Right, ListRight, ListShell, Ban, Whitelist, Request, LdapUser, LdapUserGroup
7 8
from .forms import UserChangeForm, UserCreationForm

9 10

class UserAdmin(admin.ModelAdmin):
11 12 13 14 15 16 17
    list_display = (
        'name',
        'surname',
        'pseudo',
        'room',
        'email',
        'school',
18
        'shell',
19 20
        'state'
    )
21
    search_fields = ('name','surname','pseudo','room')
22

23

24 25 26 27 28 29 30 31
class LdapUserAdmin(admin.ModelAdmin):
    list_display = ('name','uidNumber','loginShell')
    search_fields = ('name',)

class LdapUserGroupAdmin(admin.ModelAdmin):
    list_display = ('name','members','gid')
    search_fields = ('name',)

32
class SchoolAdmin(VersionAdmin):
33 34
    list_display = ('name',)

35
class ListRightAdmin(VersionAdmin):
36 37
    list_display = ('listright',)

38 39
class ListShellAdmin(VersionAdmin):
    list_display = ('shell',)
40

41 42 43
class RightAdmin(admin.ModelAdmin):
    list_display = ('user', 'right')

44 45
class RequestAdmin(admin.ModelAdmin):
    list_display = ('user', 'type', 'created_at', 'expires_at')
46

47
class BanAdmin(VersionAdmin):
chirac's avatar
chirac committed
48 49
    list_display = ('user', 'raison', 'date_start', 'date_end')

50

51
class WhitelistAdmin(VersionAdmin):
chirac's avatar
chirac committed
52 53
    list_display = ('user', 'raison', 'date_start', 'date_end')

54

55
class UserAdmin(VersionAdmin, BaseUserAdmin):
56 57 58 59 60 61 62
    # 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.
63
    list_display = ('pseudo', 'name', 'surname', 'email', 'school', 'is_admin', 'shell')
64 65 66
    list_filter = ()
    fieldsets = (
        (None, {'fields': ('pseudo', 'password')}),
67
        ('Personal info', {'fields': ('name', 'surname', 'email', 'school','shell')}),
68 69 70 71 72 73 74 75 76 77 78 79 80 81
        ('Permissions', {'fields': ('is_admin', )}),
    )
    # 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', 'school', 'is_admin', 'password1', 'password2')}
        ),
    )
    search_fields = ('pseudo',)
    ordering = ('pseudo',)
    filter_horizontal = ()

82
admin.site.register(User, UserAdmin)
83 84
admin.site.register(LdapUser, LdapUserAdmin)
admin.site.register(LdapUserGroup, LdapUserGroupAdmin)
85
admin.site.register(School, SchoolAdmin)
86 87
admin.site.register(Right, RightAdmin)
admin.site.register(ListRight, ListRightAdmin)
88
admin.site.register(ListShell, ListShellAdmin)
chirac's avatar
chirac committed
89
admin.site.register(Ban, BanAdmin)
chirac's avatar
chirac committed
90
admin.site.register(Whitelist, WhitelistAdmin)
91
admin.site.register(Request, RequestAdmin)
92 93 94 95 96 97
# 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)