Add deprecation warnings for ambgiguous config keys
This commit is contained in:
parent
a9ab59eb92
commit
f47e45a928
|
@ -40,7 +40,7 @@ from tailbone import helpers
|
||||||
from tailbone.db import Session
|
from tailbone.db import Session
|
||||||
from tailbone.config import csrf_header_name, should_expose_websockets
|
from tailbone.config import csrf_header_name, should_expose_websockets
|
||||||
from tailbone.menus import make_simple_menus
|
from tailbone.menus import make_simple_menus
|
||||||
from tailbone.util import get_global_search_options
|
from tailbone.util import get_available_themes, get_global_search_options
|
||||||
|
|
||||||
|
|
||||||
def new_request(event):
|
def new_request(event):
|
||||||
|
@ -152,12 +152,11 @@ def before_render(event):
|
||||||
default=False)
|
default=False)
|
||||||
renderer_globals['expose_theme_picker'] = expose_picker
|
renderer_globals['expose_theme_picker'] = expose_picker
|
||||||
if expose_picker:
|
if expose_picker:
|
||||||
# tailbone's config extension provides a default theme selection,
|
|
||||||
# so the default we specify here *probably* should not matter
|
# TODO: should remove 'falafel' option altogether
|
||||||
available = request.rattail_config.getlist('tailbone', 'themes',
|
available = get_available_themes(request.rattail_config,
|
||||||
default=['falafel'])
|
include=['falafel'])
|
||||||
if 'default' not in available:
|
|
||||||
available.insert(0, 'default')
|
|
||||||
options = [tags.Option(theme, value=theme) for theme in available]
|
options = [tags.Option(theme, value=theme) for theme in available]
|
||||||
renderer_globals['theme_picker_options'] = options
|
renderer_globals['theme_picker_options'] = options
|
||||||
|
|
||||||
|
|
|
@ -333,6 +333,26 @@ def get_theme_template_path(rattail_config, theme=None, session=None):
|
||||||
return resource_path(theme_path)
|
return resource_path(theme_path)
|
||||||
|
|
||||||
|
|
||||||
|
def get_available_themes(rattail_config, include=None):
|
||||||
|
available = rattail_config.getlist('tailbone', 'themes.keys')
|
||||||
|
if not available:
|
||||||
|
available = rattail_config.getlist('tailbone', 'themes',
|
||||||
|
ignore_ambiguous=True)
|
||||||
|
if available:
|
||||||
|
warnings.warn(f"URGENT: instead of 'tailbone.themes', "
|
||||||
|
f"you should set 'tailbone.themes.keys'",
|
||||||
|
DeprecationWarning, stacklevel=2)
|
||||||
|
else:
|
||||||
|
available = []
|
||||||
|
if 'default' not in available:
|
||||||
|
available.insert(0, 'default')
|
||||||
|
if include is not None:
|
||||||
|
for theme in include:
|
||||||
|
if theme not in available:
|
||||||
|
available.append(theme)
|
||||||
|
return available
|
||||||
|
|
||||||
|
|
||||||
def get_effective_theme(rattail_config, theme=None, session=None):
|
def get_effective_theme(rattail_config, theme=None, session=None):
|
||||||
"""
|
"""
|
||||||
Validates and returns the "effective" theme. If you provide a theme, that
|
Validates and returns the "effective" theme. If you provide a theme, that
|
||||||
|
@ -350,9 +370,7 @@ def get_effective_theme(rattail_config, theme=None, session=None):
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
# confirm requested theme is available
|
# confirm requested theme is available
|
||||||
available = rattail_config.getlist('tailbone', 'themes',
|
available = get_available_themes(rattail_config)
|
||||||
default=['bobcat'])
|
|
||||||
available.append('default')
|
|
||||||
if theme not in available:
|
if theme not in available:
|
||||||
raise ValueError("theme not available: {}".format(theme))
|
raise ValueError("theme not available: {}".format(theme))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue