Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit

Permalink
stop
Browse files Browse the repository at this point in the history
  • Loading branch information
hmpf committed Nov 14, 2024
1 parent 33ea323 commit eae835d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/argus_htmx/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
25 changes: 17 additions & 8 deletions src/argus_htmx/themes/utils.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -14,6 +15,9 @@
]


LOG = logging.getLogger(__name__)


def get_themes_from_setting():
themes_setting = getattr(settings, "DAISYUI_THEMES", fallbacks.DAISYUI_THEMES)
theme_names = []
Expand All @@ -30,23 +34,28 @@ def get_stylesheet_path():


def get_themes_from_css():
THEME_NAME_RE = "(?P<theme>\w+)"
THEME_NAME_RE = "(?P<theme>[-_]\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


Expand Down

0 comments on commit eae835d

Please sign in to comment.