mirror of
https://gitlab.crans.org/mediatek/med.git
synced 2025-07-06 06:03:54 +02:00
Show adherent status in admin user list
This commit is contained in:
@ -30,6 +30,24 @@ class ListRightAdmin(VersionAdmin):
|
||||
list_display = ('listright',)
|
||||
|
||||
|
||||
class IsAdherentFilter(admin.SimpleListFilter):
|
||||
title = _('adherent status')
|
||||
parameter_name = 'is_adherent'
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
return (
|
||||
('Yes', _('Yes')),
|
||||
)
|
||||
|
||||
def queryset(self, request, queryset):
|
||||
value = self.value()
|
||||
if value == 'Yes':
|
||||
# Get current membership year and list all members
|
||||
last_adh_year = Adhesion.objects.all().order_by('annee_debut').reverse().first()
|
||||
return last_adh_year.adherent
|
||||
return queryset
|
||||
|
||||
|
||||
class UserAdmin(VersionAdmin, BaseUserAdmin):
|
||||
# Customize admin to add more fields
|
||||
fieldsets = (
|
||||
@ -41,6 +59,20 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
|
||||
'maxemprunt')}),
|
||||
(_('Important dates'), {'fields': ('last_login', 'date_joined')}),
|
||||
)
|
||||
list_display = ('username', 'email', 'first_name', 'last_name',
|
||||
'maxemprunt', 'is_adherent', 'is_staff')
|
||||
list_filter = (IsAdherentFilter, 'is_staff', 'is_superuser', 'is_active',
|
||||
'groups')
|
||||
|
||||
def is_adherent(self, obj):
|
||||
"""
|
||||
Get current membership year and check if user is there
|
||||
"""
|
||||
last_adh_year = Adhesion.objects.all().order_by('annee_debut').reverse().first()
|
||||
return last_adh_year and obj in last_adh_year.adherent.all()
|
||||
|
||||
is_adherent.boolean = True
|
||||
is_adherent.short_description = _('is adherent')
|
||||
|
||||
|
||||
admin.site.register(User, UserAdmin)
|
||||
|
Reference in New Issue
Block a user