From d49b0d2f58f0b6146fb5987e723bb3db84577c19 Mon Sep 17 00:00:00 2001 From: Mads Jensen Date: Sat, 24 Feb 2018 14:33:13 +0100 Subject: [PATCH] Use AppConfig.ready to check for sorl.thumbnail in images plugin. --- src/wiki/plugins/images/apps.py | 6 ++++++ src/wiki/plugins/images/checks.py | 13 +++++++++++++ src/wiki/plugins/images/models.py | 6 ------ 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 src/wiki/plugins/images/checks.py diff --git a/src/wiki/plugins/images/apps.py b/src/wiki/plugins/images/apps.py index cf4b4af6..c17597f4 100644 --- a/src/wiki/plugins/images/apps.py +++ b/src/wiki/plugins/images/apps.py @@ -1,8 +1,14 @@ from django.apps import AppConfig from django.utils.translation import gettext_lazy as _ +from django.core.checks import register + +from . import checks class ImagesConfig(AppConfig): name = 'wiki.plugins.images' verbose_name = _("Wiki images") label = 'wiki_images' + + def ready(self): + register(checks.check_for_required_installed_apps, checks.Tags.required_installed_apps) diff --git a/src/wiki/plugins/images/checks.py b/src/wiki/plugins/images/checks.py new file mode 100644 index 00000000..774eda17 --- /dev/null +++ b/src/wiki/plugins/images/checks.py @@ -0,0 +1,13 @@ +from django.apps import apps +from django.core.checks import Error + + +class Tags: + required_installed_apps = "required_installed_apps" + + +def check_for_required_installed_apps(app_configs, **kwargs): + errors = [] + if not apps.is_installed("sorl.thumbnail"): + errors.append(Error('needs sorl.thumbnail in INSTALLED_APPS', id='wiki_images.E001')) + return errors diff --git a/src/wiki/plugins/images/models.py b/src/wiki/plugins/images/models.py index 227adb6b..a594eb02 100644 --- a/src/wiki/plugins/images/models.py +++ b/src/wiki/plugins/images/models.py @@ -1,8 +1,6 @@ import os.path -from django.apps import apps from django.conf import settings as django_settings -from django.core.exceptions import ImproperlyConfigured from django.db import models from django.db.models import signals from django.utils.translation import gettext, gettext_lazy as _ @@ -10,10 +8,6 @@ from wiki.models.pluginbase import RevisionPlugin, RevisionPluginRevision from . import settings -if not apps.is_installed("sorl.thumbnail"): - raise ImproperlyConfigured( - 'wiki.plugins.images: needs sorl.thumbnail in INSTALLED_APPS') - def upload_path(instance, filename): # Has to match original extension filename -- 2.45.2