ernestophone.ens.fr/gestion/admin.py
Martin Pépin 69b0b13ad3 Nettoyage
- PEP8
- Fichiers inutilisés
2016-07-14 01:58:52 +02:00

49 lines
1.8 KiB
Python

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
from calendrier.models import Event
class UserProfileInline(admin.StackedInline):
model = ErnestoUser
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")
User.profile_get_mails = ProfileInfo("mails", "Recevoir les mails")
class UserProfileAdmin(UserAdmin):
list_display = ('username', 'first_name', 'last_name', 'email',
'profile_phone', 'profile_instru', 'profile_is_ern',
'profile_is_chef',)
list_display_links = ('username', 'email', 'first_name', 'last_name',)
list_filter = ('profile__instru',)
ordering = ('username',)
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')}))
admin.site.unregister(User)
admin.site.unregister(Group)
admin.site.register(User, UserProfileAdmin)
admin.site.register(Event)
# Register your models here.