From 4812fc8c772a9e999084a748d59e2bab62c1a446 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Sun, 1 Aug 2021 15:24:49 +0200
Subject: [PATCH] Fix actions for personal notes table to work only with
 correct items

---
 CHANGELOG.rst                   |  2 ++
 aleksis/apps/alsijil/actions.py | 13 +++++++++----
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 056214ada..b1348da88 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -14,6 +14,8 @@ Fixed
 
 * The lesson documentations tab was displayed on overviews for persons who are not teachers.
 * Teachers weren't able to edit personal notes of their students in the person overview.
+* The actions to mark absences as excused in the personal notes table also marked personal notes as excused which are not absences.
+* The delete action in the personal notes table really deleted the items instead of just resetting them to default values.
 
 `2.0rc3`_ - 2021-07-20
 ----------------------
diff --git a/aleksis/apps/alsijil/actions.py b/aleksis/apps/alsijil/actions.py
index 5e7da3a32..2d42d6134 100644
--- a/aleksis/apps/alsijil/actions.py
+++ b/aleksis/apps/alsijil/actions.py
@@ -7,18 +7,19 @@ from django.template.loader import get_template
 from django.urls import reverse
 from django.utils.translation import gettext_lazy as _
 
+from aleksis.apps.alsijil.models import PersonalNote
 from aleksis.core.models import Notification
 
 
 def mark_as_excused(modeladmin, request, queryset):
-    queryset.update(excused=True, excuse_type=None)
+    queryset.filter(absent=True).update(excused=True, excuse_type=None)
 
 
 mark_as_excused.short_description = _("Mark as excused")
 
 
 def mark_as_unexcused(modeladmin, request, queryset):
-    queryset.update(excused=False, excuse_type=None)
+    queryset.filter(absent=True).update(excused=False, excuse_type=None)
 
 
 mark_as_unexcused.short_description = _("Mark as unexcused")
@@ -26,7 +27,7 @@ mark_as_unexcused.short_description = _("Mark as unexcused")
 
 def mark_as_excuse_type_generator(excuse_type) -> Callable:
     def mark_as_excuse_type(modeladmin, request, queryset):
-        queryset.update(excused=True, excuse_type=excuse_type)
+        queryset.filter(absent=True).update(excused=True, excuse_type=excuse_type)
 
     mark_as_excuse_type.short_description = _(f"Mark as {excuse_type.name}")
     mark_as_excuse_type.__name__ = f"mark_as_excuse_type_{excuse_type.short_name}"
@@ -35,7 +36,11 @@ def mark_as_excuse_type_generator(excuse_type) -> Callable:
 
 
 def delete_personal_note(modeladmin, request, queryset):
-    queryset.delete()
+    notes = []
+    for personal_note in queryset:
+        personal_note.reset_values()
+        notes.append(personal_note)
+    PersonalNote.objects.bulk_update(notes)
 
 
 delete_personal_note.short_description = _("Delete")
-- 
GitLab