From e5e758f9d9411f8d452ef18d15c5bb818c3de7e3 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 7 Oct 2020 11:46:43 +0200 Subject: [PATCH] Display banners when a user is no more a BDE or Kfet member --- apps/member/templatetags/__init__.py | 0 apps/member/templatetags/memberinfo.py | 22 ++++++++++++++++++++++ locale/de/LC_MESSAGES/django.po | 16 +++++++++++++--- locale/es/LC_MESSAGES/django.po | 16 +++++++++++++--- locale/fr/LC_MESSAGES/django.po | 20 +++++++++++++++++--- note_kfet/templates/base.html | 25 ++++++++++++++++++------- 6 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 apps/member/templatetags/__init__.py create mode 100644 apps/member/templatetags/memberinfo.py diff --git a/apps/member/templatetags/__init__.py b/apps/member/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/member/templatetags/memberinfo.py b/apps/member/templatetags/memberinfo.py new file mode 100644 index 00000000..d2b4986a --- /dev/null +++ b/apps/member/templatetags/memberinfo.py @@ -0,0 +1,22 @@ +# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay +# SPDX-License-Identifier: GPL-3.0-or-later + +from datetime import date + +from django import template +from django.contrib.auth.models import User + +from ..models import Club, Membership + + +def is_member(user, club): + if isinstance(user, str): + club = User.objects.get(username=user) + if isinstance(club, str): + club = Club.objects.get(name=club) + return Membership.objects\ + .filter(user=user, club=club, date_start__lte=date.today(), date_end__gte=date.today()).exists() + + +register = template.Library() +register.filter("is_member", is_member) diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po index f464ca99..90f99283 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-10-07 10:55+0200\n" +"POT-Creation-Date: 2020-10-07 11:42+0200\n" "PO-Revision-Date: 2020-09-13 12:39+0200\n" "Last-Translator: elkmaennchen \n" "Language-Team: \n" @@ -3058,13 +3058,23 @@ msgstr "Anmelden" #: note_kfet/templates/base.html:156 msgid "" +"You are not a BDE member anymore. Please renew your membership if you want " +"to use the note." +msgstr "" + +#: note_kfet/templates/base.html:160 +msgid "You are not a Kfet member, so you can't use your note account." +msgstr "" + +#: note_kfet/templates/base.html:166 +msgid "" "Your e-mail address is not validated. Please check your mail inbox and click " "on the validation link." msgstr "" "Ihre E-Mail-Adresse ist nicht validiert. Bitte überprüfen Sie Ihren " "Posteingang und klicken Sie auf den Validierungslink." -#: note_kfet/templates/base.html:161 +#: note_kfet/templates/base.html:171 msgid "" "You declared that you opened a bank account in the Société générale. The " "bank did not validate the creation of the account to the BDE, so the " @@ -3073,7 +3083,7 @@ msgid "" "you go to the end of the account creation." msgstr "" -#: note_kfet/templates/base.html:184 +#: note_kfet/templates/base.html:194 msgid "Contact us" msgstr "Kontakt" diff --git a/locale/es/LC_MESSAGES/django.po b/locale/es/LC_MESSAGES/django.po index 0ad5c21b..2b3b47a5 100644 --- a/locale/es/LC_MESSAGES/django.po +++ b/locale/es/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-10-07 10:55+0200\n" +"POT-Creation-Date: 2020-10-07 11:42+0200\n" "PO-Revision-Date: 2020-09-19 14:56+0200\n" "Last-Translator: elkmaennchen \n" "Language-Team: \n" @@ -3040,13 +3040,23 @@ msgstr "Conectarse" #: note_kfet/templates/base.html:156 msgid "" +"You are not a BDE member anymore. Please renew your membership if you want " +"to use the note." +msgstr "" + +#: note_kfet/templates/base.html:160 +msgid "You are not a Kfet member, so you can't use your note account." +msgstr "" + +#: note_kfet/templates/base.html:166 +msgid "" "Your e-mail address is not validated. Please check your mail inbox and click " "on the validation link." msgstr "" "Su correo electrónico no fue validado. Por favor mire en sus correos y haga " "clic en el enlace de validación." -#: note_kfet/templates/base.html:161 +#: note_kfet/templates/base.html:171 msgid "" "You declared that you opened a bank account in the Société générale. The " "bank did not validate the creation of the account to the BDE, so the " @@ -3055,7 +3065,7 @@ msgid "" "you go to the end of the account creation." msgstr "" -#: note_kfet/templates/base.html:184 +#: note_kfet/templates/base.html:194 msgid "Contact us" msgstr "Contactarnos" diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 9ed194a7..5b36834c 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-10-07 10:55+0200\n" +"POT-Creation-Date: 2020-10-07 11:42+0200\n" "PO-Revision-Date: 2020-09-13 12:36+0200\n" "Last-Translator: elkmaennchen \n" "Language-Team: \n" @@ -3057,13 +3057,27 @@ msgstr "Se connecter" #: note_kfet/templates/base.html:156 msgid "" +"You are not a BDE member anymore. Please renew your membership if you want " +"to use the note." +msgstr "" +"Vous n'êtes plus adhérent BDE. Merci de réadhérer si vous voulez profiter de " +"la note." + +#: note_kfet/templates/base.html:160 +msgid "You are not a Kfet member, so you can't use your note account." +msgstr "" +"Vous n'êtes pas adhérent Kfet, vous ne pouvez par conséquent pas utiliser " +"votre compte note." + +#: note_kfet/templates/base.html:166 +msgid "" "Your e-mail address is not validated. Please check your mail inbox and click " "on the validation link." msgstr "" "Votre adresse e-mail n'est pas validée. Merci de vérifier votre boîte mail " "et de cliquer sur le lien de validation." -#: note_kfet/templates/base.html:161 +#: note_kfet/templates/base.html:171 msgid "" "You declared that you opened a bank account in the Société générale. The " "bank did not validate the creation of the account to the BDE, so the " @@ -3078,7 +3092,7 @@ msgstr "" "durer quelques jours. Merci de vous assurer de bien aller au bout de vos " "démarches." -#: note_kfet/templates/base.html:184 +#: note_kfet/templates/base.html:194 msgid "Contact us" msgstr "Nous contacter" diff --git a/note_kfet/templates/base.html b/note_kfet/templates/base.html index 1e740012..71e19f83 100644 --- a/note_kfet/templates/base.html +++ b/note_kfet/templates/base.html @@ -1,4 +1,4 @@ -{% load static i18n pretty_money static getenv perms %} +{% load static i18n pretty_money static getenv perms memberinfo %} {% comment %} SPDX-License-Identifier: GPL-3.0-or-later {% endcomment %} @@ -64,8 +64,7 @@ SPDX-License-Identifier: GPL-3.0-or-later {% trans 'Consumptions' %} {% endif %} - {# FIXME Find a better solution to check if a user has the right to see the transfer page #} - {% if "note.alias"|model_list_length >= 2 %} + {% if user.is_authenticated and user|is_member:"Kfet" %}