From 4b45b01e2af41775aa7385ba84e4bab83f7c46d4 Mon Sep 17 00:00:00 2001 From: moanos Date: Tue, 17 Dec 2024 21:42:10 +0100 Subject: [PATCH] feat: Add toggle for e-mail notifications --- .../fellchensammlung/details/detail-user.html | 79 ++++++++++--------- src/fellchensammlung/views.py | 5 ++ 2 files changed, 47 insertions(+), 37 deletions(-) diff --git a/src/fellchensammlung/templates/fellchensammlung/details/detail-user.html b/src/fellchensammlung/templates/fellchensammlung/details/detail-user.html index 418cd79..0de2658 100644 --- a/src/fellchensammlung/templates/fellchensammlung/details/detail-user.html +++ b/src/fellchensammlung/templates/fellchensammlung/details/detail-user.html @@ -7,44 +7,49 @@

{% translate "Username" %}: {{ user.username }}

{% translate "E-Mail" %}: {{ user.email }}

- {% if user.preferred_language %} -

{% translate "Sprache" %}: {{ user.preferred_language }}

- {% else %} -

{% translate "Keine bevorzugte Sprache gesetzt." %}

- {% endif %} + {% if user.id is request.user.id %} +
+

{% trans 'Einstellungen' %}

+
+ {% csrf_token %} + {% if user.email_notifications %} + + {% else %} + + {% endif %} +
+
+ {% if token %} +
+ {% csrf_token %} +

{% translate "API token:" %} {{ token }}

+ +
+ {% else %} +

{% translate "Kein API-Token vorhanden." %}

+
+ {% csrf_token %} + +
+ {% endif %} +
+
-
- {% if user.id is request.user.id %} -
- {% if token %} -
- {% csrf_token %} -

{% translate "API token:" %} {{ token }}

- -
- {% else %} -

{% translate "Kein API-Token vorhanden." %}

-
- {% csrf_token %} - -
- {% endif %} -
-

-

-

{% trans 'Profil verwalten' %}

-

- {% translate "Change password" %} - {% translate "Daten exportieren" %} -

-
+
+

{% trans 'Profil verwalten' %}

+

+ {% translate "Change password" %} + {% translate "Daten exportieren" %}

-

{% translate 'Benachrichtigungen' %}

- {% include "fellchensammlung/lists/list-notifications.html" %} -

{% translate 'Meine Vermittlungen' %}

- {% include "fellchensammlung/lists/list-adoption-notices.html" %} +
+

{% translate 'Benachrichtigungen' %}

+ {% include "fellchensammlung/lists/list-notifications.html" %} +

{% translate 'Meine Vermittlungen' %}

+ {% include "fellchensammlung/lists/list-adoption-notices.html" %} - {% endif %} + {% endif %} {% endblock %} \ No newline at end of file diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index cceb93a..5a8d6b1 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -460,6 +460,10 @@ def my_profile(request): Token.objects.create(user=request.user) elif "delete_token" in request.POST: Token.objects.get(user=request.user).delete() + elif "toggle_email_notifications" in request.POST: + user = request.user + user.email_notifications = not user.email_notifications + user.save() action = request.POST.get("action") if action == "notification_mark_read": @@ -475,6 +479,7 @@ def my_profile(request): for notification in notifications: notification.read = True notification.save() + try: token = Token.objects.get(user=request.user) except Token.DoesNotExist: