diff --git a/apps/member/models.py b/apps/member/models.py index efd8bf8c10c31ced2f836adb7bc848e1ce3c33c9..ffe50201632d2da00716a9795cd61adc4fde7290 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -131,15 +131,22 @@ class Profile(models.Model): return reverse('user_detail', args=(self.pk,)) def send_email_validation_link(self): - subject = _("Activate your Note Kfet account") - message = loader.render_to_string('registration/mails/email_validation_email.html', + subject = "[Note Kfet]" + _("Activate your Note Kfet account") + message = loader.render_to_string('registration/mails/email_validation_email.txt', { 'user': self.user, 'domain': os.getenv("NOTE_URL", "note.example.com"), 'token': email_validation_token.make_token(self.user), 'uid': urlsafe_base64_encode(force_bytes(self.user.pk)), }) - self.user.email_user(subject, message) + html = loader.render_to_string('registration/mails/email_validation_email.txt', + { + 'user': self.user, + 'domain': os.getenv("NOTE_URL", "note.example.com"), + 'token': email_validation_token.make_token(self.user), + 'uid': urlsafe_base64_encode(force_bytes(self.user.pk)), + }) + self.user.email_user(subject, message, html_message=html) class Club(models.Model): diff --git a/apps/note/models/notes.py b/apps/note/models/notes.py index 998186020053ffdb0c1d56a4704a659f0238995a..9274dff687b537122308df25beeadb80b6e22f2e 100644 --- a/apps/note/models/notes.py +++ b/apps/note/models/notes.py @@ -7,6 +7,7 @@ from django.conf import settings from django.core.exceptions import ValidationError from django.core.validators import RegexValidator from django.db import models +from django.template.loader import render_to_string from django.utils import timezone from django.utils.translation import gettext_lazy as _ from polymorphic.models import PolymorphicModel @@ -67,6 +68,13 @@ class Note(PolymorphicModel): pretty.short_description = _('Note') + @property + def last_negative_duration(self): + if self.balance >= 0 or self.last_negative is None: + return None + delta = timezone.now() - self.last_negative + return "{:d} jours".format(delta.days) + def save(self, *args, **kwargs): """ Save note with it's alias (called in polymorphic children) @@ -128,6 +136,21 @@ class NoteUser(Note): def pretty(self): return _("%(user)s's note") % {'user': str(self.user)} + def save(self, *args, **kwargs): + if self.pk and self.balance < 0: + old_note = NoteUser.objects.get(pk=self.pk) + if old_note.balance >= 0: + # Passage en négatif + self.last_negative = timezone.now() + self.send_mail_negative_balance() + super().save(*args, **kwargs) + + def send_mail_negative_balance(self): + plain_text = render_to_string("note/mails/negative_balance.txt", dict(note=self)) + html = render_to_string("note/mails/negative_balance.html", dict(note=self)) + self.user.email_user("[Note Kfet] Passage en négatif (compte n°{:d})" + .format(self.user.pk), plain_text, html_message=html) + class NoteClub(Note): """ diff --git a/apps/note/models/transactions.py b/apps/note/models/transactions.py index f504d8e12acc2ccc2b18ba36d6506aa301ab8d9c..6eab05ee688df483466f3346f13431f6899a7667 100644 --- a/apps/note/models/transactions.py +++ b/apps/note/models/transactions.py @@ -7,7 +7,7 @@ from django.utils import timezone from django.utils.translation import gettext_lazy as _ from polymorphic.models import PolymorphicModel -from .notes import Note, NoteClub, NoteSpecial +from .notes import Note, NoteClub, NoteSpecial, NoteUser from ..templatetags.pretty_money import pretty_money """ diff --git a/apps/scripts b/apps/scripts index dce51ad26134d396d7cbfca7c63bd2ed391dd969..4b37f8286f493b1a28bd0faa0052ee3967fe543e 160000 --- a/apps/scripts +++ b/apps/scripts @@ -1 +1 @@ -Subproject commit dce51ad26134d396d7cbfca7c63bd2ed391dd969 +Subproject commit 4b37f8286f493b1a28bd0faa0052ee3967fe543e diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po index bec7e72648d640812114597048c95d4a2cce741d..d28ecb34c9f6a7374e7ee6aac962e52e1235e41f 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -2128,33 +2128,33 @@ msgstr "" msgid "Forgotten your password or username?" msgstr "" -#: templates/registration/mails/email_validation_email.html:3 +#: templates/registration/mails/email_validation_email.txt:3 msgid "Hi" msgstr "" -#: templates/registration/mails/email_validation_email.html:5 +#: templates/registration/mails/email_validation_email.txt:5 msgid "" "You recently registered on the Note Kfet. Please click on the link below to " "confirm your registration." msgstr "" -#: templates/registration/mails/email_validation_email.html:9 +#: templates/registration/mails/email_validation_email.txt:9 msgid "" "This link is only valid for a couple of days, after that you will need to " "contact us to validate your email." msgstr "" -#: templates/registration/mails/email_validation_email.html:11 +#: templates/registration/mails/email_validation_email.txt:11 msgid "" "After that, you'll have to wait that someone validates your account before " "you can log in. You will need to pay your membership in the Kfet." msgstr "" -#: templates/registration/mails/email_validation_email.html:13 +#: templates/registration/mails/email_validation_email.txt:13 msgid "Thanks" msgstr "" -#: templates/registration/mails/email_validation_email.html:15 +#: templates/registration/mails/email_validation_email.txt:15 msgid "The Note Kfet team." msgstr "" diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 54c70c714de2679b6d4a975a0773ae4fc47d9e52..9df44fece9040ad2c99ec5259dd4415f76d7c508 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -2197,11 +2197,11 @@ msgstr "" msgid "Forgotten your password or username?" msgstr "Mot de passe ou pseudo oublié ?" -#: templates/registration/mails/email_validation_email.html:3 +#: templates/registration/mails/email_validation_email.txt:3 msgid "Hi" msgstr "Bonjour" -#: templates/registration/mails/email_validation_email.html:5 +#: templates/registration/mails/email_validation_email.txt:5 msgid "" "You recently registered on the Note Kfet. Please click on the link below to " "confirm your registration." @@ -2209,7 +2209,7 @@ msgstr "" "Vous vous êtes inscrits récemment sur la Note Kfet. Merci de cliquer sur le " "lien ci-dessous pour confirmer votre adresse email." -#: templates/registration/mails/email_validation_email.html:9 +#: templates/registration/mails/email_validation_email.txt:9 msgid "" "This link is only valid for a couple of days, after that you will need to " "contact us to validate your email." @@ -2217,7 +2217,7 @@ msgstr "" "Ce lien n'est valide que pendant quelques jours. Après cela, vous devrez " "nous contacter pour valider votre email." -#: templates/registration/mails/email_validation_email.html:11 +#: templates/registration/mails/email_validation_email.txt:11 msgid "" "After that, you'll have to wait that someone validates your account before " "you can log in. You will need to pay your membership in the Kfet." @@ -2225,11 +2225,11 @@ msgstr "" "Après cela, vous devrez attendre que quelqu'un valide votre compte avant de " "pouvoir vous connecter. Vous devrez payer votre adhésion à la Kfet." -#: templates/registration/mails/email_validation_email.html:13 +#: templates/registration/mails/email_validation_email.txt:13 msgid "Thanks" msgstr "Merci" -#: templates/registration/mails/email_validation_email.html:15 +#: templates/registration/mails/email_validation_email.txt:15 msgid "The Note Kfet team." msgstr "L'équipe de la Note Kfet." diff --git a/static/js/transfer.js b/static/js/transfer.js index 5b577066943d999b3958678f377e9808a4431b54..ddaccc2decb1938d250dedfd6755e9be34991424 100644 --- a/static/js/transfer.js +++ b/static/js/transfer.js @@ -333,9 +333,9 @@ $("#btn_transfer").click(function() { "polymorphic_ctype": SPECIAL_TRANSFER_POLYMORPHIC_CTYPE, "resourcetype": "SpecialTransaction", "source": source_id, - "source_alias": sources_notes_display[0].name, + "source_alias": sources_notes_display.length ? sources_notes_display[0].name : null, "destination": dest_id, - "destination_alias": dests_notes_display[0].name, + "destination_alias": dests_notes_display.length ? dests_notes_display[0].name : null, "last_name": $("#last_name").val(), "first_name": $("#first_name").val(), "bank": $("#bank").val() diff --git a/templates/note/mails/negative_balance.html b/templates/note/mails/negative_balance.html new file mode 100644 index 0000000000000000000000000000000000000000..30e38cc871d0d84d4b5d01ebd25286099fc61225 --- /dev/null +++ b/templates/note/mails/negative_balance.html @@ -0,0 +1,44 @@ +{% load pretty_money %} + +<!DOCTYPE html> +<html lang="fr"> +<head> + <meta charset="UTF-8"> + <title>Passage en négatif (compte n°{{ note.user.pk }})</title> +</head> +<body> +<p> + Bonjour {{ note.user.first_name }} {{ note.user.last_name }}, +</p> + +<p> + Ce mail t'a été envoyé parce que le solde de ta Note Kfet {{ note }} est négatif ! +</p> + +<p> + Ton solde actuel est de {{ note.balance|pretty_money }}. +</p> + +<p> + Par ailleurs, le BDE ne sert pas d'alcool aux adhérents dont le solde + est inférieur à 0 € depuis plus de 24h. +</p> + +<p> + Si tu ne comprends pas ton solde, tu peux consulter ton historique + sur <a href="{% url "member:user_detail" pk=note.user.pk %}">ton compte</a>. +</p> + +<p> + Tu peux venir recharger ta note rapidement à la Kfet, ou envoyer un mail à + la trésorerie du BdE (<a href="mailto:tresorerie.bde@lists.crans.org">tresorerie.bde@lists.crans.org</a>) + pour payer par virement bancaire. +</p> + +-- +<p> + Le BDE<br> + Mail généré par la Note Kfet le {% now "j F Y à H:i:s" %} +</p> +</body> +</html> \ No newline at end of file diff --git a/templates/note/mails/negative_balance.txt b/templates/note/mails/negative_balance.txt new file mode 100644 index 0000000000000000000000000000000000000000..b49caf738aaa0ec4bcd74b542829f7e0b50bfa4b --- /dev/null +++ b/templates/note/mails/negative_balance.txt @@ -0,0 +1,23 @@ +{% load pretty_money %} + +Bonjour {{ note.user.first_name }} {{ note.user.last_name }}, + +Ce mail t'a été envoyé parce que le solde de ta Note Kfet +{{ note }} est négatif ! + +Ton solde actuel est de {{ note.balance|pretty_money }}. + +Par ailleurs, le BDE ne sert pas d'alcool aux adhérents dont le solde +est inférieur à 0 € depuis plus de 24h. + +Si tu ne comprends pas ton solde, tu peux consulter ton historique +sur ton compte {% url "member:user_detail" pk=note.user.pk %} + +Tu peux venir recharger ta note rapidement à la Kfet, ou envoyer un mail à +la trésorerie du BdE (tresorerie.bde@lists.crans.org) pour payer par +virement bancaire. + +-- +Le BDE + +Mail généré par la Note Kfet le {% now "j F Y à H:i:s" %} \ No newline at end of file diff --git a/templates/note/mails/negative_notes_report.html b/templates/note/mails/negative_notes_report.html new file mode 100644 index 0000000000000000000000000000000000000000..c895b903f3f9c8b7cf079a02ab83305ff72a0c02 --- /dev/null +++ b/templates/note/mails/negative_notes_report.html @@ -0,0 +1,41 @@ +{% load pretty_money %} + +<!DOCTYPE html> +<html lang="fr"> +<head> + <meta charset="UTF-8"> + <title>[Note Kfet] Liste des négatifs</title> +</head> +<body> +<table> +<thead> +<tr> + <th>Nom</th> + <th>Prénom</th> + <th>Pseudo</th> + <th>Email</th> + <th>Solde</th> + <th>Durée</th> +</tr> +</thead> +<tbody> + {% for note in notes %} + <tr> + <td>{{ note.user.last_name }}</td> + <td>{{ note.user.first_name }}</td> + <td>{{ note.user.username }}</td> + <td>{{ note.user.email }}</td> + <td>{{ note.balance|pretty_money }}</td> + <td>{{ note.last_negative_duration }}</td> + </tr> + {% endfor %} +</tbody> +</table> + +-- +<p> + Le BDE<br> + Mail généré par la Note Kfet le {% now "j F Y à H:i:s" %} +</p> +</body> +</html> \ No newline at end of file diff --git a/templates/note/mails/negative_notes_report.txt b/templates/note/mails/negative_notes_report.txt new file mode 100644 index 0000000000000000000000000000000000000000..b7fa1f23f7f7037bb95374362d495957c34c68aa --- /dev/null +++ b/templates/note/mails/negative_notes_report.txt @@ -0,0 +1,12 @@ +{% load pretty_money %} + + Nom | Prénom | Pseudo | Email | Solde | Durée +---------------------+------------+-----------------+-----------------------------------+----------+----------- +{% for note in notes %} +{{ note.user.last_name }} | {{ note.user.first_name }} | {{ note.user.username }} | {{ note.user.email }} | {{ note.balance|pretty_money }} | {{ note.last_negative_duration }} +{% endfor %} + +-- +Le BDE + +Mail généré par la Note Kfet le {% now "j F Y à H:i:s" %} \ No newline at end of file diff --git a/templates/registration/mails/email_validation_email.html b/templates/registration/mails/email_validation_email.html index 577c1220abdcb9425a806bddfac0c444d89e79df..0d3afc0e0d51b5536b99b36780171a46d9efde58 100644 --- a/templates/registration/mails/email_validation_email.html +++ b/templates/registration/mails/email_validation_email.html @@ -1,15 +1,41 @@ {% load i18n %} -{% trans "Hi" %} {{ user.username }}, +<!DOCTYPE html> +<html lang="fr"> +<head> + <meta charset="UTF-8"> + <title>Passage en négatif (compte n°{{ note.user.pk }})</title> +</head> +<body> -{% trans "You recently registered on the Note Kfet. Please click on the link below to confirm your registration." %} +<p> + {% trans "Hi" %} {{ user.username }}, +</p> -https://{{ domain }}{% url 'registration:email_validation' uidb64=uid token=token %} +<p> + {% trans "You recently registered on the Note Kfet. Please click on the link below to confirm your registration." %} +</p> -{% trans "This link is only valid for a couple of days, after that you will need to contact us to validate your email." %} +<p> + <a href="https://{{ domain }}{% url 'registration:email_validation' uidb64=uid token=token %}"> + https://{{ domain }}{% url 'registration:email_validation' uidb64=uid token=token %} + </a> +</p> -{% trans "After that, you'll have to wait that someone validates your account before you can log in. You will need to pay your membership in the Kfet." %} +<p> + {% trans "This link is only valid for a couple of days, after that you will need to contact us to validate your email." %} +</p> -{% trans "Thanks" %}, +<p> + {% trans "After that, you'll have to wait that someone validates your account before you can log in. You will need to pay your membership in the Kfet." %} +</p> -{% trans "The Note Kfet team." %} +<p> + {% trans "Thanks" %}, +</p> + +-- +<p> + {% trans "The Note Kfet team." %} + Mail généré par la Note Kfet le {% now "j F Y à H:i:s" %} +</p> \ No newline at end of file diff --git a/templates/registration/mails/email_validation_email.txt b/templates/registration/mails/email_validation_email.txt new file mode 100644 index 0000000000000000000000000000000000000000..69f2d642d85b8bfc1808fdf8befb8e6fddba4ff4 --- /dev/null +++ b/templates/registration/mails/email_validation_email.txt @@ -0,0 +1,16 @@ +{% load i18n %} + +{% trans "Hi" %} {{ user.username }}, + +{% trans "You recently registered on the Note Kfet. Please click on the link below to confirm your registration." %} + +https://{{ domain }}{% url 'registration:email_validation' uidb64=uid token=token %} + +{% trans "This link is only valid for a couple of days, after that you will need to contact us to validate your email." %} + +{% trans "After that, you'll have to wait that someone validates your account before you can log in. You will need to pay your membership in the Kfet." %} + +{% trans "Thanks" %}, + +{% trans "The Note Kfet team." %} +Mail généré par la Note Kfet le {% now "j F Y à H:i:s" %} \ No newline at end of file