Commit 8509b309 authored by Dominik George's avatar Dominik George 🍻
Browse files

Merge branch...

Merge branch '404-remove-old-data-check-results-if-the-data-problem-persists-no-longer' into 'master'

Resolve "Remove old data check results if the data problem persists no longer"

Closes #404

See merge request AlekSIS/official/AlekSIS-Core!580
parents 8927daaf ffbd558c
import logging
from django.apps import apps
from django.contrib.contenttypes.models import ContentType
from django.db.models.aggregates import Count
from django.utils.functional import classproperty
......@@ -156,11 +157,19 @@ class DataCheck:
solve_options = { IgnoreSolveOption}
_current_results = []
def check_data(cls):
"""Find all objects with data issues and register them."""
def run_check_data(cls):
"""Wrap ``check_data`` to ensure that post-processing tasks are run."""
def solve(cls, check_result: "DataCheckResult", solve_option: str):
"""Execute a solve option for an object detected by this check.
......@@ -188,11 +197,30 @@ class DataCheck:
from aleksis.core.models import DataCheckResult
ct = ContentType.objects.get_for_model(instance)
result = DataCheckResult.objects.get_or_create(
result, __ = DataCheckResult.objects.get_or_create(, content_type=ct,
# Track all existing problems (for deleting old results)
return result
def delete_old_results(cls):
"""Delete old data check results for problems which exist no longer."""
DataCheckResult = apps.get_model("core", "DataCheckResult")
pks = [ for r in cls._current_results]
old_results = DataCheckResult.objects.filter(
if old_results:"Delete {old_results.count()} old data check results.")
# Reset list with existing problems
cls._current_results = []
class DataCheckRegistry:
"""Create central registry for all data checks in AlekSIS."""
......@@ -213,7 +241,7 @@ def check_data(recorder: ProgressRecorder):
"""Execute all registered data checks and send email if activated."""
for check in recorder.iterate(DataCheckRegistry.data_checks):"Run check: {check.verbose_name}")
if get_site_preferences()["general__data_checks_send_emails"]:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment