From eae835dfb661fa0fa3dace592de4dd00d16fa01f Mon Sep 17 00:00:00 2001 From: Hanne Moa Date: Thu, 14 Nov 2024 08:10:22 +0100 Subject: [PATCH] stop --- src/argus_htmx/checks.py | 2 +- src/argus_htmx/themes/utils.py | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/argus_htmx/checks.py b/src/argus_htmx/checks.py index e5ed5a62..b483d01c 100644 --- a/src/argus_htmx/checks.py +++ b/src/argus_htmx/checks.py @@ -9,7 +9,7 @@ def check_for_valid_themes_list(app_configs, **kwargs): errors = [] themes = [] try: - themes = get_theme_names() + themes = get_theme_names(quiet=False) except ImproperlyConfigured as e: errors.append( Error( diff --git a/src/argus_htmx/themes/utils.py b/src/argus_htmx/themes/utils.py index 5be8fef8..59127778 100644 --- a/src/argus_htmx/themes/utils.py +++ b/src/argus_htmx/themes/utils.py @@ -1,9 +1,10 @@ -from importlib.resources import files +import logging from pathlib import Path from re import findall from django.conf import settings from django.core.exceptions import ImproperlyConfigured +from django.contrib.staticfiles.finders import find from argus_htmx import settings as fallbacks @@ -14,6 +15,9 @@ ] +LOG = logging.getLogger(__name__) + + def get_themes_from_setting(): themes_setting = getattr(settings, "DAISYUI_THEMES", fallbacks.DAISYUI_THEMES) theme_names = [] @@ -30,23 +34,28 @@ def get_stylesheet_path(): def get_themes_from_css(): - THEME_NAME_RE = "(?P\w+)" + THEME_NAME_RE = "(?P[-_]\w+)" DATA_THEME_RE = f"\[data-theme={THEME_NAME_RE}\]" - static_url = Path(settings.STATIC_URL).relative_to("/") - stylesheet_path = static_url / get_stylesheet_path() - styles_css = files("argus_htmx").joinpath(stylesheet_path).read_text() + absolute_stylesheet_path = Path(find(get_stylesheet_path())) + styles_css = absolute_stylesheet_path.read_text() return findall(DATA_THEME_RE, styles_css) -def get_theme_names(): +def get_theme_names(quiet=True): + ERROR_MSG = "Themes in settings are out of sync with themes installed" + themes_from_setting = set(get_themes_from_setting()) themes_from_css = set(get_themes_from_css()) - installed_themes = themes_from_setting | themes_from_css + installed_themes = themes_from_setting & themes_from_css + all_themes = themes_from_setting & themes_from_css if all_themes != installed_themes: - raise ImproperlyConfigured("Themes in settings is out of sync with themes installed") + LOG.warning(ERROR_MSG) + if not quiet: + raise ImproperlyConfigured(ERROR_MSG) + return installed_themes