Skip to content
Snippets Groups Projects

Resolve "Add task for checking plausibility of data"

Merged Jonathan Weth requested to merge 91-add-task-for-checking-plausibility-of-data into master
Compare and Show latest version
1 file
+ 71
20
Compare changes
  • Side-by-side
  • Inline
@@ -32,6 +32,18 @@ class SetGroupsWithCurrentGroupsSolveOption(SolveOption):
check_result.delete()
class ResetPersonalNoteSolveOption(SolveOption):
name = "reset_personal_note"
verbose_name = _("Reset personal note to defaults")
@classmethod
def solve(cls, check_result: "DataCheckResult"):
note = check_result.related_object
note.reset_values()
note.save()
check_result.delete()
@DATA_CHECK_REGISTRY.register
class NoPersonalNotesInCancelledLessonsDataCheck(DataCheck):
name = "no_personal_notes_in_cancelled_lessons"
@@ -44,12 +56,8 @@ class NoPersonalNotesInCancelledLessonsDataCheck(DataCheck):
@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(
lesson_period__substitutions__cancelled=True,
lesson_period__substitutions__week=F("week"),
@@ -58,10 +66,7 @@ class NoPersonalNotesInCancelledLessonsDataCheck(DataCheck):
for note in personal_notes:
logging.info(f"Check personal note {note}")
sub = note.lesson_period.get_substitution(CalendarWeek(week=note.week, year=note.year))
result = DataCheckResult.objects.get_or_create(
check=cls.name, content_type=ct, object_id=note.id
)
cls.register_result(note)
@DATA_CHECK_REGISTRY.register
@@ -77,19 +82,13 @@ class NoGroupsOfPersonsSetInPersonalNotesDataCheck(DataCheck):
@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(groups_of_person__isnull=True)
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
)
cls.register_result(note)
@DATA_CHECK_REGISTRY.register
@@ -110,11 +109,9 @@ class LessonDocumentationOnHolidaysDataCheck(DataCheck):
@classmethod
def check_data(cls):
from aleksis.apps.chronos.models import Holiday
from aleksis.core.models import DataCheckResult
from .models import LessonDocumentation
ct = ContentType.objects.get_for_model(LessonDocumentation)
holidays = list(Holiday.objects.all())
documentations = LessonDocumentation.objects.filter(
@@ -126,6 +123,60 @@ class LessonDocumentationOnHolidaysDataCheck(DataCheck):
day = week_weekday_to_date(doc.calendar_week, doc.lesson_period.period.weekday)
if len(list(filter(lambda h: h.date_start <= day <= h.date_end, holidays))) > 0:
logging.info(" ... on holidays")
result = DataCheckResult.objects.get_or_create(
check=cls.name, content_type=ct, object_id=doc.id
)
cls.register_result(doc)
@DATA_CHECK_REGISTRY.register
class PersonalNoteOnHolidaysDataCheck(DataCheck):
"""Checks for personal note objects on holidays.
This ignores empty personal notes as they are created by default.
"""
name = "personal_note_on_holidays"
verbose_name = _("Ensure that there are no filled out personal notes on holidays")
problem_name = _("The personal note is on holidays.")
solve_options = {
DeleteRelatedObjectSolveOption.name: DeleteRelatedObjectSolveOption,
IgnoreSolveOption.name: IgnoreSolveOption,
}
@classmethod
def check_data(cls):
from aleksis.apps.chronos.models import Holiday
from .models import PersonalNote
holidays = list(Holiday.objects.all())
personal_notes = PersonalNote.objects.filter(
~Q(remarks="") | Q(absent=True) | ~Q(late=0) | Q(extra_marks__isnull=False)
)
for note in personal_notes:
logging.info(f"Check personal note {note}")
day = week_weekday_to_date(note.calendar_week, note.lesson_period.period.weekday)
if len(list(filter(lambda h: h.date_start <= day <= h.date_end, holidays))) > 0:
logging.info(" ... on holidays")
cls.register_result(note)
@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 = {
ResetPersonalNoteSolveOption.name: ResetPersonalNoteSolveOption,
IgnoreSolveOption.name: IgnoreSolveOption,
}
@classmethod
def check_data(cls):
from .models import PersonalNote
personal_notes = PersonalNote.objects.filter(excused=True, absent=False)
for note in personal_notes:
logging.info(f"Check personal note {note}")
cls.register_result(note)
Loading