From dc120025e74669dbe890e03ad0246d922cd773ad Mon Sep 17 00:00:00 2001 From: moanos Date: Fri, 2 Aug 2024 21:04:44 +0200 Subject: [PATCH] feat: Allow marking notifications as read --- .../partials/partial-notification.html | 7 ++++++- src/fellchensammlung/views.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/fellchensammlung/templates/fellchensammlung/partials/partial-notification.html b/src/fellchensammlung/templates/fellchensammlung/partials/partial-notification.html index 1f1f0f8..5d47917 100644 --- a/src/fellchensammlung/templates/fellchensammlung/partials/partial-notification.html +++ b/src/fellchensammlung/templates/fellchensammlung/partials/partial-notification.html @@ -4,7 +4,12 @@
{{ notification.title }} {{ notification.created_at }} - +
+ {% csrf_token %} + + + +

{{ notification.text | render_markdown }} diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index cdfdfa0..7c60b9e 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -315,6 +315,20 @@ def report_detail_success(request, report_id): def user_detail(request, user_id): + if request.method == "POST": + action = request.POST.get("action") + if action == "notification_mark_read": + notification_id = request.POST.get("notification_id") + print(notification_id) + notification = BaseNotification.objects.get(pk=notification_id) + notification.read = True + notification.save() + elif action == "notification_mark_all_read": + notifications = BaseNotification.objects.filter(user=request.user, mark_read=False) + for notification in notifications: + notification.read = True + notification.save() + user = User.objects.get(id=user_id) context = {"user": user, "adoption_notices": AdoptionNotice.objects.filter(created_by=user),