From b2f2c7d2953e8b3b7292c96e67043f24e937b448 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Sat, 26 Dec 2020 19:33:08 +0100 Subject: [PATCH] Add data check to ensure that there are no excuses without absences --- aleksis/apps/alsijil/data_checks.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/aleksis/apps/alsijil/data_checks.py b/aleksis/apps/alsijil/data_checks.py index 289de5cc0..2d56f2c67 100644 --- a/aleksis/apps/alsijil/data_checks.py +++ b/aleksis/apps/alsijil/data_checks.py @@ -168,3 +168,32 @@ class PersonalNoteOnHolidaysDataCheck(DataCheck): result = DataCheckResult.objects.get_or_create( check=cls.name, content_type=ct, object_id=note.id ) + + +@DATA_CHECK_REGISTRY.register +class ExcusesWithoutAbsences(DataCheck): + name = "excuses_without_absences" + verbose_name = _("Ensure that there are no excused personal notes without an absence") + problem_name = _("The personal note is marked as excused, but not as absent.") + solve_options = { + DeleteRelatedObjectSolveOption.name: DeleteRelatedObjectSolveOption, + # FIXME OPTION + IgnoreSolveOption.name: IgnoreSolveOption, + } + + @classmethod + def check_data(cls): + from aleksis.core.models import DataCheckResult + + from .models import PersonalNote + + ct = ContentType.objects.get_for_model(PersonalNote) + + personal_notes = PersonalNote.objects.filter(excused=True, + absent=False) + + for note in personal_notes: + logging.info(f"Check personal note {note}") + result = DataCheckResult.objects.get_or_create( + check=cls.name, content_type=ct, object_id=note.id + ) -- GitLab