admin.py 3.15 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
class LdapUserAdmin(admin.ModelAdmin):
    list_display = ('name','uidNumber','loginShell')
26
    exclude = ('user_password','sambat_nt_password')
27 28 29 30 31 32
    search_fields = ('name',)

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

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

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

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

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

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

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

51

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

55

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

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