diff --git a/apps/member/models.py b/apps/member/models.py index efd8bf8c..ffe50201 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 99818602..9274dff6 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 f504d8e1..6eab05ee 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 dce51ad2..4b37f828 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 bec7e726..d28ecb34 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 54c70c71..9df44fec 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 5b577066..ddaccc2d 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 00000000..30e38cc8 --- /dev/null +++ b/templates/note/mails/negative_balance.html @@ -0,0 +1,44 @@ +{% load pretty_money %} + + + + + + Passage en négatif (compte n°{{ note.user.pk }}) + + +

+ 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. +

+ +

+ 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_balance.txt b/templates/note/mails/negative_balance.txt new file mode 100644 index 00000000..b49caf73 --- /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 00000000..c895b903 --- /dev/null +++ b/templates/note/mails/negative_notes_report.html @@ -0,0 +1,41 @@ +{% load pretty_money %} + + + + + + [Note Kfet] Liste des négatifs + + + + + + + + + + + + + + + {% for note in notes %} + + + + + + + + + {% endfor %} + +
NomPrénomPseudoEmailSoldeDurée
{{ note.user.last_name }}{{ note.user.first_name }}{{ note.user.username }}{{ note.user.email }}{{ note.balance|pretty_money }}{{ note.last_negative_duration }}
+ +-- +

+ 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.txt b/templates/note/mails/negative_notes_report.txt new file mode 100644 index 00000000..b7fa1f23 --- /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 577c1220..0d3afc0e 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 }}, + + + + + Passage en négatif (compte n°{{ note.user.pk }}) + + -{% trans "You recently registered on the Note Kfet. Please click on the link below to confirm your registration." %} +

+ {% trans "Hi" %} {{ user.username }}, +

-https://{{ domain }}{% url 'registration:email_validation' uidb64=uid token=token %} +

+ {% trans "You recently registered on the Note Kfet. Please click on the link below to confirm your registration." %} +

-{% trans "This link is only valid for a couple of days, after that you will need to contact us to validate your email." %} +

+ + https://{{ domain }}{% url 'registration:email_validation' uidb64=uid token=token %} + +

-{% 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 "This link is only valid for a couple of days, after that you will need to contact us to validate your email." %} +

-{% trans "Thanks" %}, +

+ {% 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 "The Note Kfet team." %} +

+ {% 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 diff --git a/templates/registration/mails/email_validation_email.txt b/templates/registration/mails/email_validation_email.txt new file mode 100644 index 00000000..69f2d642 --- /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