Show adherent status in admin user list
This commit is contained in:
parent
781b2087a3
commit
d711cd69e1
|
@ -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)
|
||||
|
|
|
@ -3,7 +3,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-08-08 12:10+0200\n"
|
||||
"POT-Creation-Date: 2019-08-08 13:02+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -13,18 +13,30 @@ msgstr ""
|
|||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||
|
||||
#: admin.py:37
|
||||
#: admin.py:34
|
||||
msgid "adherent status"
|
||||
msgstr "statut adhérent"
|
||||
|
||||
#: admin.py:39
|
||||
msgid "Yes"
|
||||
msgstr ""
|
||||
|
||||
#: admin.py:55
|
||||
msgid "Personal info"
|
||||
msgstr ""
|
||||
|
||||
#: admin.py:39
|
||||
#: admin.py:57
|
||||
msgid "Permissions"
|
||||
msgstr ""
|
||||
|
||||
#: admin.py:42
|
||||
#: admin.py:60
|
||||
msgid "Important dates"
|
||||
msgstr ""
|
||||
|
||||
#: admin.py:75
|
||||
msgid "is adherent"
|
||||
msgstr "statut adhérent"
|
||||
|
||||
#: models.py:18
|
||||
msgid "phone number"
|
||||
msgstr "numéro de téléphone"
|
||||
|
|
Loading…
Reference in New Issue