From 4ba2241228159bc482e04a49d8d916e20c0cf0a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Mon, 16 Sep 2024 21:27:46 +0200 Subject: [PATCH] default theme setting --- src/c3nav/settings.py | 1 + src/c3nav/site/context_processors.py | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/c3nav/settings.py b/src/c3nav/settings.py index b5997f4e..1cea21d7 100644 --- a/src/c3nav/settings.py +++ b/src/c3nav/settings.py @@ -597,6 +597,7 @@ RANDOM_PRIMARY_COLOR_LIST = [hex_from_oklch(PRIMARY_COLOR_RANDOMISATION['lightne PRIMARY_COLOR_RANDOMISATION['chroma'], x) for x in range(0, 360)] +DEFAULT_THEME = config.getint('c3nav', 'default_theme', fallback=0) BASE_THEME = { 'is_dark': config.getboolean('theme', 'is_dark', fallback=False), 'randomize_primary_color': config.getboolean('theme', 'randomize_primary_color', fallback=False), diff --git a/src/c3nav/site/context_processors.py b/src/c3nav/site/context_processors.py index 5a15eab4..ef195940 100644 --- a/src/c3nav/site/context_processors.py +++ b/src/c3nav/site/context_processors.py @@ -42,13 +42,12 @@ def theme(request): themes = css_themes_all() else: themes = css_themes_public() - active_theme_id = request.session.get('theme', 0) - if active_theme_id in themes: - active_theme = themes[active_theme_id] - else: - active_theme_id = 0 - active_theme = themes[0] - request.session['theme'] = active_theme_id + default_theme_id = settings.DEFAULT_THEME if settings.DEFAULT_THEME in themes else 0 + active_theme_id = request.session.get('theme', default_theme_id) + if active_theme_id not in themes: + active_theme_id = default_theme_id + + active_theme = themes[active_theme_id] if active_theme['randomize_primary_color']: from c3nav.site.themes import get_random_primary_color