From 9c91d14003a5a4f8f5754435e3c8ab9d82396994 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Sat, 26 Dec 2020 19:44:47 +0100 Subject: [PATCH] Simplify registering of data check results by adding a dedicated method --- aleksis/core/data_checks.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/aleksis/core/data_checks.py b/aleksis/core/data_checks.py index d73163ac8..bf823ccc9 100644 --- a/aleksis/core/data_checks.py +++ b/aleksis/core/data_checks.py @@ -1,5 +1,6 @@ import logging +from django.contrib.contenttypes.models import ContentType from django.db.models.aggregates import Count from django.utils.translation import gettext as _ @@ -44,6 +45,16 @@ class DataCheck: with reversion.create_revision(): cls.solve_options[solve_option].solve(check_result) + @classmethod + def register_result(cls, instance) -> "DataCheckResult": + from aleksis.core.models import DataCheckResult + + ct = ContentType.objects.get_for_model(instance) + result = DataCheckResult.objects.get_or_create( + check=cls.name, content_type=ct, object_id=instance.id + ) + return result + class DataCheckRegistry: def __init__(self): -- GitLab