feat: Add toggle for e-mail notifications

This commit is contained in:
moanos [he/him] 2024-12-17 21:42:10 +01:00
parent d0060ecf5e
commit 4b45b01e2a
2 changed files with 47 additions and 37 deletions

View File

@ -7,44 +7,49 @@
<p><strong>{% translate "Username" %}:</strong> {{ user.username }}</p> <p><strong>{% translate "Username" %}:</strong> {{ user.username }}</p>
<p><strong>{% translate "E-Mail" %}:</strong> {{ user.email }}</p> <p><strong>{% translate "E-Mail" %}:</strong> {{ user.email }}</p>
{% if user.preferred_language %} {% if user.id is request.user.id %}
<p><strong>{% translate "Sprache" %}:</strong> {{ user.preferred_language }}</p> <div class="container-cards">
{% else %} <div class="detail-animal-header"><h1>{% trans 'Einstellungen' %}</h1></div>
<p>{% translate "Keine bevorzugte Sprache gesetzt." %}</p> <form class="card" action="" method="POST">
{% endif %} {% csrf_token %}
{% if user.email_notifications %}
<input class="btn" type="submit" name="toggle_email_notifications"
value="{% translate 'E-Mail Benachrichtigungen deaktivieren' %}">
{% else %}
<input class="btn" type="submit" name="toggle_email_notifications"
value="{% translate 'E-Mail Benachrichtigungen aktivieren' %}">
{% endif %}
</form>
<div class="card">
{% if token %}
<form action="" method="POST">
{% csrf_token %}
<p class="text-muted"><strong>{% translate "API token:" %}</strong> {{ token }}</p>
<input class="btn" type="submit" name="delete_token"
value={% translate "Delete API token" %}>
</form>
{% else %}
<p>{% translate "Kein API-Token vorhanden." %}</p>
<form action="" method="POST">
{% csrf_token %}
<input class="btn" type="submit" name="create_token"
value={% translate "Create API token" %}>
</form>
{% endif %}
</div>
</div>
<div class="container-cards"> <div class="container-comment-form">
{% if user.id is request.user.id %} <h2>{% trans 'Profil verwalten' %}</h2>
<div class="card"> <p>
{% if token %} <a class="btn2" href="{% url 'password_change' %}">{% translate "Change password" %}</a>
<form action="" method="POST"> <a class="btn2" href="{% url 'user-me-export' %}">{% translate "Daten exportieren" %}</a>
{% csrf_token %}
<p class="text-muted"><strong>{% translate "API token:" %}</strong> {{ token }}</p>
<input class="btn" type="submit" name="delete_token"
value={% translate "Delete API token" %}>
</form>
{% else %}
<p>{% translate "Kein API-Token vorhanden." %}</p>
<form action="" method="POST">
{% csrf_token %}
<input class="btn" type="submit" name="create_token"
value={% translate "Create API token" %}>
</form>
{% endif %}
</div>
</div><p>
<div class="container-comment-form">
<h2>{% trans 'Profil verwalten' %}</h2>
<p>
<a class="btn2" href="{% url 'password_change' %}">{% translate "Change password" %}</a>
<a class="btn2" href="{% url 'user-me-export' %}">{% translate "Daten exportieren" %}</a>
</p>
</div>
</p> </p>
<h2>{% translate 'Benachrichtigungen' %}</h2> </div>
{% include "fellchensammlung/lists/list-notifications.html" %} <h2>{% translate 'Benachrichtigungen' %}</h2>
<h2>{% translate 'Meine Vermittlungen' %}</h2> {% include "fellchensammlung/lists/list-notifications.html" %}
{% include "fellchensammlung/lists/list-adoption-notices.html" %} <h2>{% translate 'Meine Vermittlungen' %}</h2>
{% include "fellchensammlung/lists/list-adoption-notices.html" %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -460,6 +460,10 @@ def my_profile(request):
Token.objects.create(user=request.user) Token.objects.create(user=request.user)
elif "delete_token" in request.POST: elif "delete_token" in request.POST:
Token.objects.get(user=request.user).delete() 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") action = request.POST.get("action")
if action == "notification_mark_read": if action == "notification_mark_read":
@ -475,6 +479,7 @@ def my_profile(request):
for notification in notifications: for notification in notifications:
notification.read = True notification.read = True
notification.save() notification.save()
try: try:
token = Token.objects.get(user=request.user) token = Token.objects.get(user=request.user)
except Token.DoesNotExist: except Token.DoesNotExist: