Skip to content
Snippets Groups Projects
Commit 6ce723dd authored by Julian's avatar Julian
Browse files

Develop NotUpdatedIconChoicesDataCheckBuilder to dynamically create data...

Develop NotUpdatedIconChoicesDataCheckBuilder to dynamically create data checks for the new icon choices
parent 816150a4
No related branches found
No related tags found
1 merge request!1048Resolve "Replace model icon choices with new icon set"
......@@ -3,8 +3,11 @@ from datetime import timedelta
from django.apps import apps
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.db.models import Model
from django.db.models.aggregates import Count
from django.utils.functional import classproperty
from django.utils.text import slugify
from django.utils.translation import gettext as _
import reversion
......@@ -316,3 +319,32 @@ class BrokenDashboardWidgetDataCheck(DataCheck):
for widget in broken_widgets:
logging.info("Check DashboardWidget %s", widget)
cls.register_result(widget)
def NotUpdatedIconChoicesDataCheckBuilder(app_name: str, model_name: str, field_name: str): # noqa
from django.apps import apps
class NotUpdatedIconChoicesDataCheck(DataCheck):
name = "not_updated_icon_choices_" + slugify(model_name)
verbose_name = _(
"Ensure that there are no database entries for %s with icons from an old icon set." % model_name
)
problem_name = _(
"The %s instance uses an icon which doesn't exist anymore." % model_name)
solve_options = {
IgnoreSolveOption.name: IgnoreSolveOption,
}
@classmethod
def check_data(cls):
model: Model = apps.get_model(app_name, model_name)
for obj in model.objects.all():
try:
model._meta.get_field(field_name).validate(getattr(obj, field_name), obj)
except ValidationError as e:
logging.info(f"Check {model_name} {obj}")
cls.register_result(obj)
NotUpdatedIconChoicesDataCheck.__name__ = model_name + "NotUpdatedIconChoicesDataCheck"
return NotUpdatedIconChoicesDataCheck
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment