From 79ad58997a3ca1f0d34e87dae15bd14cb23cd50d Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Sat, 10 Aug 2019 16:22:04 +0200 Subject: [PATCH] Fix adherents name --- theme/templates/admin/index.html | 2 +- users/admin.py | 20 ++++++++++---------- users/locale/fr/LC_MESSAGES/django.po | 6 +++--- users/models.py | 6 +++--- users/views.py | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/theme/templates/admin/index.html b/theme/templates/admin/index.html index 54fbf34..c087651 100644 --- a/theme/templates/admin/index.html +++ b/theme/templates/admin/index.html @@ -78,7 +78,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
  • {% trans 'maximum borrowed' %} : {{ user.maxemprunt }}
  • {% trans 'membership for current year' %} : - {% if user.is_adherent %} + {% if user.is_member %} {% trans 'yes' %} {% else %} {% trans 'no' %} diff --git a/users/admin.py b/users/admin.py index 50caf22..95059ea 100644 --- a/users/admin.py +++ b/users/admin.py @@ -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( '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) diff --git a/users/locale/fr/LC_MESSAGES/django.po b/users/locale/fr/LC_MESSAGES/django.po index 7d21508..aa6e761 100644 --- a/users/locale/fr/LC_MESSAGES/django.po +++ b/users/locale/fr/LC_MESSAGES/django.po @@ -3,7 +3,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-08-10 16:12+0200\n" +"POT-Creation-Date: 2019-08-10 16:20+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -14,7 +14,7 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n > 1);\n" #: admin.py:32 -msgid "adherent status" +msgid "membership status" msgstr "statut adhérent" #: admin.py:37 @@ -46,7 +46,7 @@ msgid "Adhere" msgstr "Adhérer" #: admin.py:114 -msgid "is adherent" +msgid "is member" msgstr "statut adhérent" #: apps.py:15 diff --git a/users/models.py b/users/models.py index a6cb6e4..95e916f 100644 --- a/users/models.py +++ b/users/models.py @@ -44,10 +44,10 @@ class User(AbstractUser): REQUIRED_FIELDS = ['first_name', 'last_name', 'email'] @property - def is_adherent(self): - last_adh_year = Adhesion.objects.all().order_by( + def is_member(self): + last_year = Adhesion.objects.all().order_by( 'starting_in').reverse().first() - return last_adh_year and self in last_adh_year.adherent.all() + return last_year and self in last_year.members.all() class Clef(models.Model): diff --git a/users/views.py b/users/views.py index f1e0aab..e32fe51 100644 --- a/users/views.py +++ b/users/views.py @@ -55,7 +55,7 @@ def adherer(request, userid): return redirect("admin:users_user_changelist") with transaction.atomic(), reversion.create_revision(): reversion.set_user(request.user) - adh_year.adherent.add(users) + adh_year.members.add(users) adh_year.save() reversion.set_comment("Adhesion de %s" % users) messages.success(request, "Adhesion effectuee")