Add deprecation warnings for ambgiguous config keys
This commit is contained in:
		
							parent
							
								
									a9ab59eb92
								
							
						
					
					
						commit
						f47e45a928
					
				
					 2 changed files with 27 additions and 10 deletions
				
			
		|  | @ -40,7 +40,7 @@ from tailbone import helpers | |||
| from tailbone.db import Session | ||||
| from tailbone.config import csrf_header_name, should_expose_websockets | ||||
| 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): | ||||
|  | @ -152,12 +152,11 @@ def before_render(event): | |||
|                                                        default=False) | ||||
|         renderer_globals['expose_theme_picker'] = expose_picker | ||||
|         if expose_picker: | ||||
|             # tailbone's config extension provides a default theme selection, | ||||
|             # so the default we specify here *probably* should not matter | ||||
|             available = request.rattail_config.getlist('tailbone', 'themes', | ||||
|                                                        default=['falafel']) | ||||
|             if 'default' not in available: | ||||
|                 available.insert(0, 'default') | ||||
| 
 | ||||
|             # TODO: should remove 'falafel' option altogether | ||||
|             available = get_available_themes(request.rattail_config, | ||||
|                                              include=['falafel']) | ||||
| 
 | ||||
|             options = [tags.Option(theme, value=theme) for theme in available] | ||||
|             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) | ||||
| 
 | ||||
| 
 | ||||
| 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): | ||||
|     """ | ||||
|     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() | ||||
| 
 | ||||
|     # confirm requested theme is available | ||||
|     available = rattail_config.getlist('tailbone', 'themes', | ||||
|                                        default=['bobcat']) | ||||
|     available.append('default') | ||||
|     available = get_available_themes(rattail_config) | ||||
|     if theme not in available: | ||||
|         raise ValueError("theme not available: {}".format(theme)) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar