1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2025-07-06 20:54:01 +02:00

Fix adherents name

This commit is contained in:
Alexandre Iooss
2019-08-10 16:22:04 +02:00
parent 2ce5e122a4
commit 79ad58997a
5 changed files with 18 additions and 18 deletions

View File

@ -28,9 +28,9 @@ class AdhesionAdmin(VersionAdmin):
autocomplete_fields = ('members',)
class IsAdherentFilter(admin.SimpleListFilter):
title = _('adherent status')
parameter_name = 'is_adherent'
class IsMemberFilter(admin.SimpleListFilter):
title = _('membership status')
parameter_name = 'is_member'
def lookups(self, request, model_admin):
return (
@ -43,7 +43,7 @@ class IsAdherentFilter(admin.SimpleListFilter):
# Get current membership year and list all members
last_adh_year = Adhesion.objects.all().order_by('starting_in') \
.reverse().first()
return last_adh_year.adherent
return last_adh_year.members
return queryset
@ -59,8 +59,8 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
(_('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',
'maxemprunt', 'is_member', 'is_staff')
list_filter = (IsMemberFilter, 'is_staff', 'is_superuser', 'is_active',
'groups')
# Customize required initial fields
@ -91,13 +91,13 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
else:
messages.error(request, _("The email is invalid."))
def is_adherent(self, obj):
def is_member(self, obj):
"""
Get current membership year and check if user is there
"""
last_adh_year = Adhesion.objects.all().order_by('starting_in') \
.reverse().first()
is_member = last_adh_year and obj in last_adh_year.adherent.all()
is_member = last_adh_year and obj in last_adh_year.members.all()
if is_member:
return format_html(
'<img src="/static/admin/img/icon-yes.svg" alt="True">'
@ -111,8 +111,8 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
_('Adhere')
)
is_adherent.short_description = _('is adherent')
is_adherent.allow_tags = True
is_member.short_description = _('is member')
is_member.allow_tags = True
admin_site.register(User, UserAdmin)