2015-03-17 19:03:51 +01:00
|
|
|
from django.contrib import admin
|
|
|
|
from django.contrib.auth.models import User, Group
|
|
|
|
from gestion.models import ErnestoUser
|
|
|
|
from django.contrib.auth.admin import UserAdmin
|
2015-04-13 18:56:43 +02:00
|
|
|
from calendrier.models import Event
|
2015-03-17 19:03:51 +01:00
|
|
|
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2015-03-17 19:03:51 +01:00
|
|
|
class UserProfileInline(admin.StackedInline):
|
|
|
|
model = ErnestoUser
|
2016-07-14 01:58:52 +02:00
|
|
|
|
|
|
|
|
2015-03-17 19:03:51 +01:00
|
|
|
def ProfileInfo(field, short_description, boolean=False):
|
|
|
|
def getter(self):
|
|
|
|
try:
|
|
|
|
return getattr(self.profile, field)
|
|
|
|
except ErnestoUser.DoesNotExist:
|
|
|
|
return ""
|
|
|
|
getter.short_description = short_description
|
|
|
|
getter.boolean = boolean
|
|
|
|
return getter
|
|
|
|
|
|
|
|
User.profile_phone = ProfileInfo("phone", "Telephone")
|
|
|
|
User.profile_instru = ProfileInfo("instru", "Instrument joué")
|
|
|
|
User.profile_is_ern = ProfileInfo("is_ernesto", "Ernestophoniste")
|
|
|
|
User.profile_is_chef = ProfileInfo("is_chef", "Chef Fanfare")
|
2016-06-21 00:33:32 +02:00
|
|
|
User.profile_get_mails = ProfileInfo("mails", "Recevoir les mails")
|
2015-03-17 19:03:51 +01:00
|
|
|
|
2016-07-14 01:58:52 +02:00
|
|
|
|
2015-03-17 19:03:51 +01:00
|
|
|
class UserProfileAdmin(UserAdmin):
|
2016-07-14 01:58:52 +02:00
|
|
|
list_display = ('username', 'first_name', 'last_name', 'email',
|
|
|
|
'profile_phone', 'profile_instru', 'profile_is_ern',
|
|
|
|
'profile_is_chef',)
|
2015-03-17 19:03:51 +01:00
|
|
|
list_display_links = ('username', 'email', 'first_name', 'last_name',)
|
|
|
|
list_filter = ('profile__instru',)
|
|
|
|
ordering = ('username',)
|
2016-07-14 01:58:52 +02:00
|
|
|
search_fields = ('username', 'first_name', 'last_name', 'profile__phone',
|
|
|
|
'profile__instru',)
|
|
|
|
inlines = [UserProfileInline, ]
|
|
|
|
fieldsets = (('Général', {'fields': ('username', 'password', 'first_name',
|
|
|
|
'last_name', )}),
|
|
|
|
('Permissions', {'fields': ('is_active', 'is_staff',
|
|
|
|
'is_superuser')}))
|
2015-03-28 18:54:48 +01:00
|
|
|
|
2015-03-17 19:03:51 +01:00
|
|
|
|
|
|
|
admin.site.unregister(User)
|
|
|
|
admin.site.unregister(Group)
|
|
|
|
admin.site.register(User, UserProfileAdmin)
|
2015-04-13 18:56:43 +02:00
|
|
|
admin.site.register(Event)
|
2015-03-17 19:03:51 +01:00
|
|
|
# Register your models here.
|