2016-06-30 01:39:07 +00:00
|
|
|
from django.contrib import admin
|
2016-07-08 01:12:28 +00:00
|
|
|
from django.contrib.auth.models import Group
|
|
|
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
2016-07-21 14:58:12 +00:00
|
|
|
from reversion.admin import VersionAdmin
|
2016-06-30 01:39:07 +00:00
|
|
|
|
2016-07-20 01:53:46 +00:00
|
|
|
from .models import User, School, Right, ListRight, Ban, Whitelist, Request
|
2016-07-08 01:12:28 +00:00
|
|
|
from .forms import UserChangeForm, UserCreationForm
|
|
|
|
|
2016-06-30 23:03:28 +00:00
|
|
|
|
|
|
|
class UserAdmin(admin.ModelAdmin):
|
2016-07-08 01:12:28 +00:00
|
|
|
list_display = (
|
|
|
|
'name',
|
|
|
|
'surname',
|
|
|
|
'pseudo',
|
|
|
|
'room',
|
|
|
|
'email',
|
|
|
|
'school',
|
|
|
|
'state'
|
|
|
|
)
|
|
|
|
|
2016-06-30 23:03:28 +00:00
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
class SchoolAdmin(VersionAdmin):
|
2016-06-30 23:03:28 +00:00
|
|
|
list_display = ('name',)
|
|
|
|
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
class ListRightAdmin(VersionAdmin):
|
2016-07-02 00:42:04 +00:00
|
|
|
list_display = ('listright',)
|
|
|
|
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-07-02 00:42:04 +00:00
|
|
|
class RightAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('user', 'right')
|
|
|
|
|
2016-07-20 01:53:46 +00:00
|
|
|
class RequestAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('user', 'type', 'created_at', 'expires_at')
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
class BanAdmin(VersionAdmin):
|
2016-07-02 19:57:31 +00:00
|
|
|
list_display = ('user', 'raison', 'date_start', 'date_end')
|
|
|
|
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
class WhitelistAdmin(VersionAdmin):
|
2016-07-04 18:04:11 +00:00
|
|
|
list_display = ('user', 'raison', 'date_start', 'date_end')
|
|
|
|
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
class UserAdmin(VersionAdmin, BaseUserAdmin):
|
2016-07-08 01:12:28 +00:00
|
|
|
# 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', 'school', 'is_admin')
|
|
|
|
list_filter = ()
|
|
|
|
fieldsets = (
|
|
|
|
(None, {'fields': ('pseudo', 'password')}),
|
|
|
|
('Personal info', {'fields': ('name', 'surname', 'email', 'school')}),
|
|
|
|
('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 = ()
|
|
|
|
|
2016-06-30 23:03:28 +00:00
|
|
|
admin.site.register(User, UserAdmin)
|
|
|
|
admin.site.register(School, SchoolAdmin)
|
2016-07-02 00:42:04 +00:00
|
|
|
admin.site.register(Right, RightAdmin)
|
|
|
|
admin.site.register(ListRight, ListRightAdmin)
|
2016-07-02 19:57:31 +00:00
|
|
|
admin.site.register(Ban, BanAdmin)
|
2016-07-04 18:04:11 +00:00
|
|
|
admin.site.register(Whitelist, WhitelistAdmin)
|
2016-07-20 01:53:46 +00:00
|
|
|
admin.site.register(Request, RequestAdmin)
|
2016-07-08 01:12:28 +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)
|