From 7b730e2a0f470beab27aebd5c4dfff768b7d123d Mon Sep 17 00:00:00 2001 From: YodYaya Date: Fri, 11 Mar 2022 16:07:56 +0100 Subject: [PATCH] Email envoi --- FlOpEDT/base/queries.py | 8 +++--- FlOpEDT/base/templates/base/notification.html | 26 ++++++++++++++----- FlOpEDT/base/views.py | 7 +++-- ...32_notificationspreferences_is_notified.py | 18 +++++++++++++ .../migrations/__0032_auto_20220311_1334.py | 18 +++++++++++++ .../migrations/___0032_auto_20220311_1057.py | 18 +++++++++++++ FlOpEDT/people/models.py | 1 + 7 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 FlOpEDT/people/migrations/0032_notificationspreferences_is_notified.py create mode 100644 FlOpEDT/people/migrations/__0032_auto_20220311_1334.py create mode 100644 FlOpEDT/people/migrations/___0032_auto_20220311_1057.py diff --git a/FlOpEDT/base/queries.py b/FlOpEDT/base/queries.py index ae5bfa1ad..d6d40c8fc 100644 --- a/FlOpEDT/base/queries.py +++ b/FlOpEDT/base/queries.py @@ -344,12 +344,12 @@ def get_working_days(dept): def get_notification_preference(user): if user is not None: try: - return user.notifications_preference.nb_of_notified_weeks + return user.notifications_preference.is_notified except NotificationsPreferences.DoesNotExist: if user.is_tutor: - return 4 + return True elif user.is_student: - return 0 + return True else: pass - return 0 + return False diff --git a/FlOpEDT/base/templates/base/notification.html b/FlOpEDT/base/templates/base/notification.html index 581d23d53..3bc319d27 100644 --- a/FlOpEDT/base/templates/base/notification.html +++ b/FlOpEDT/base/templates/base/notification.html @@ -21,20 +21,32 @@ {% load i18n %} - +
Notifications
{% csrf_token %} -

{% trans "I wish to be notified of changes for the" %} - - {%trans "next weeks." %}
- {% trans "(0 if no notification, 1 for the next 7 days, etc.)" %} +

{% trans "I would like to be notified of changes concerning the" %} + + {% trans "2 next days." %}
+
+ + + + +

-
+
+ + diff --git a/FlOpEDT/base/views.py b/FlOpEDT/base/views.py index dda26ff66..d6dde4312 100644 --- a/FlOpEDT/base/views.py +++ b/FlOpEDT/base/views.py @@ -382,8 +382,11 @@ def user_notifications_pref_changes(req, username=None, *args, **kwargs): u = User.objects.get(username=username) n, created = NotificationsPreferences.objects.get_or_create(user=u) data = req.POST - user_notifications_pref = int(data['user_notifications_pref']) - n.nb_of_notified_weeks = user_notifications_pref + + if 'user_notifications_pref' in data: + n.is_notified = True + else: + n.is_notified = False n.save() return redirect('base:preferences', req.department) diff --git a/FlOpEDT/people/migrations/0032_notificationspreferences_is_notified.py b/FlOpEDT/people/migrations/0032_notificationspreferences_is_notified.py new file mode 100644 index 000000000..097b9052e --- /dev/null +++ b/FlOpEDT/people/migrations/0032_notificationspreferences_is_notified.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.14 on 2022-03-11 13:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0031_auto_20220214_2231'), + ] + + operations = [ + migrations.AddField( + model_name='notificationspreferences', + name='is_notified', + field=models.BooleanField(default=True), + ), + ] diff --git a/FlOpEDT/people/migrations/__0032_auto_20220311_1334.py b/FlOpEDT/people/migrations/__0032_auto_20220311_1334.py new file mode 100644 index 000000000..d12730504 --- /dev/null +++ b/FlOpEDT/people/migrations/__0032_auto_20220311_1334.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.14 on 2022-03-11 13:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0031_auto_20220214_2231'), + ] + + operations = [ + migrations.AlterField( + model_name='notificationspreferences', + name='nb_of_notified_weeks', + field=models.BooleanField(default=True), + ), + ] diff --git a/FlOpEDT/people/migrations/___0032_auto_20220311_1057.py b/FlOpEDT/people/migrations/___0032_auto_20220311_1057.py new file mode 100644 index 000000000..b822edbfe --- /dev/null +++ b/FlOpEDT/people/migrations/___0032_auto_20220311_1057.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.14 on 2022-03-11 10:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0031_auto_20220214_2231'), + ] + + operations = [ + migrations.AlterField( + model_name='notificationspreferences', + name='nb_of_notified_weeks', + field=models.BooleanField(default=True), + ), + ] diff --git a/FlOpEDT/people/models.py b/FlOpEDT/people/models.py index 7beb91130..e92fc7f59 100644 --- a/FlOpEDT/people/models.py +++ b/FlOpEDT/people/models.py @@ -283,6 +283,7 @@ class NotificationsPreferences(models.Model): on_delete=models.CASCADE, related_name='notifications_preference') nb_of_notified_weeks = models.PositiveSmallIntegerField(default=0) + is_notified = models.BooleanField(default=False) class UserPreferredLinks(models.Model): -- GitLab