diff --git a/changes/6817.bugfix b/changes/6817.bugfix new file mode 100644 index 00000000000..281dabd7666 --- /dev/null +++ b/changes/6817.bugfix @@ -0,0 +1,6 @@ +Fix theme settings. Options which were used to specify a CSS file +with a base theme are replaced. Use altenatives below in order +to specify **asset** with a base theme for application: + +* `ckan.main_css` replaced by `ckan.theme` +* `ckan.i18n.rtl_css` replaced by `ckan.i18n.rtl_theme` diff --git a/ckan/controllers/admin.py b/ckan/controllers/admin.py index bed19630cc0..8f79ac4906a 100644 --- a/ckan/controllers/admin.py +++ b/ckan/controllers/admin.py @@ -35,11 +35,11 @@ def __before__(self, action, **params): def _get_config_form_items(self): # Styles for use in the form.select() macro. - styles = [{'text': 'Default', 'value': '/base/css/main.css'}, - {'text': 'Red', 'value': '/base/css/red.css'}, - {'text': 'Green', 'value': '/base/css/green.css'}, - {'text': 'Maroon', 'value': '/base/css/maroon.css'}, - {'text': 'Fuchsia', 'value': '/base/css/fuchsia.css'}] + styles = [{'text': 'Default', 'value': 'css/main'}, + {'text': 'Red', 'value': 'css/red'}, + {'text': 'Green', 'value': 'css/green'}, + {'text': 'Maroon', 'value': 'css/maroon'}, + {'text': 'Fuchsia', 'value': 'css/fuchsia'}] homepages = [{'value': '1', 'text': 'Introductory area, search, featured group and featured organization'}, {'value': '2', 'text': 'Search, stats, introductory area, featured organization and featured group'}, @@ -47,7 +47,7 @@ def _get_config_form_items(self): items = [ {'name': 'ckan.site_title', 'control': 'input', 'label': _('Site Title'), 'placeholder': ''}, - {'name': 'ckan.main_css', 'control': 'select', 'options': styles, 'label': _('Style'), 'placeholder': ''}, + {'name': 'ckan.theme', 'control': 'select', 'options': styles, 'label': _('Style'), 'placeholder': ''}, {'name': 'ckan.site_description', 'control': 'input', 'label': _('Site Tag Line'), 'placeholder': ''}, {'name': 'ckan.site_logo', 'control': 'image_upload', 'label': _('Site Tag Logo'), 'placeholder': '', 'upload_enabled':h.uploads_enabled(), 'field_url': 'ckan.site_logo', 'field_upload': 'logo_upload', 'field_clear': 'clear_logo_upload'}, diff --git a/ckan/lib/app_globals.py b/ckan/lib/app_globals.py index 3fddba54e1e..43719ebc03d 100644 --- a/ckan/lib/app_globals.py +++ b/ckan/lib/app_globals.py @@ -72,12 +72,23 @@ # A place to store the origional config options of we override them _CONFIG_CACHE = {} -def set_main_css(css_file): - ''' Sets the main_css. The css_file must be of the form file.css ''' - assert css_file.endswith('.css') - new_css = css_file - # FIXME we should check the css file exists - app_globals.main_css = str(new_css) +def set_theme(asset): + ''' Sets the theme. + The `asset` argument is a name of existing web-asset registered by CKAN + itself or by any enabled extension. + If asset is not registered, use default theme instead. + ''' + from ckan.lib.webassets_tools import env + + assert env + if asset not in env: + log.error( + "Asset '%s' does not exist. Fallback to '%s'", + asset, 'css/main' + ) + asset = 'css/main' + + app_globals.theme = asset def set_app_global(key, value): @@ -168,8 +179,8 @@ def get_config_value(key, default=''): get_config_value(key) # custom styling - main_css = get_config_value('ckan.main_css', '/base/css/main.css') - set_main_css(main_css) + theme = get_config_value('ckan.theme') or 'css/main' + set_theme(theme) if app_globals.site_logo: app_globals.header_class = 'header-image' diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index 063ed4d4583..2c28e86f99b 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -687,8 +687,8 @@ def is_rtl_language(): @core_helper -def get_rtl_css(): - return config.get('ckan.i18n.rtl_css', '/base/css/main-rtl.css') +def get_rtl_theme(): + return config.get('ckan.i18n.rtl_theme', 'css/main-rtl') class Message(object): diff --git a/ckan/logic/schema.py b/ckan/logic/schema.py index 9c1cf759a06..35bf21a9395 100644 --- a/ckan/logic/schema.py +++ b/ckan/logic/schema.py @@ -741,7 +741,7 @@ def default_update_configuration_schema( 'ckan.site_about': [ignore_missing, unicode_safe], 'ckan.site_intro_text': [ignore_missing, unicode_safe], 'ckan.site_custom_css': [ignore_missing, unicode_safe], - 'ckan.main_css': [ignore_missing, unicode_safe], + 'ckan.theme': [ignore_missing, unicode_safe], 'ckan.homepage_style': [ignore_missing, is_positive_integer], 'logo_upload': [ignore_missing, unicode_safe], 'clear_logo_upload': [ignore_missing, unicode_safe], diff --git a/ckan/templates/admin/config.html b/ckan/templates/admin/config.html index 2fb72909f24..48f929cc1e1 100644 --- a/ckan/templates/admin/config.html +++ b/ckan/templates/admin/config.html @@ -13,7 +13,7 @@ {{ form.input('ckan.site_title', id='field-ckan-site-title', label=_('Site Title'), value=data['ckan.site_title'], error=error, classes=['control-medium']) }} - {{ form.select('ckan.main_css', id='field-ckan-main-css', label=_('Style'), options=styles, selected=data['ckan.main_css'], error=error) }} + {{ form.select('ckan.theme', id='field-ckan-main-css', label=_('Style'), options=styles, selected=data['ckan.theme'], error=error) }} {{ form.input('ckan.site_description', id='field-ckan-site-description', label=_('Site Tag Line'), value=data['ckan.site_description'], error=error, classes=['control-medium']) }} diff --git a/ckan/templates/base.html b/ckan/templates/base.html index e3c9bf54a6e..38ee3591d2f 100644 --- a/ckan/templates/base.html +++ b/ckan/templates/base.html @@ -67,9 +67,8 @@ #} {%- block styles %} {# TODO: store just name of asset instead of path to it. #} - {% set main_css = h.get_rtl_css() if h.is_rtl_language() else g.main_css %} - {# strip '/base/' prefix and '.css' suffix #} - {% asset main_css[6:-4] %} + {% set theme = h.get_rtl_theme() if h.is_rtl_language() else g.theme %} + {% asset theme %} {% endblock %} {% block head_extras %} diff --git a/ckan/templates/macros/autoform.html b/ckan/templates/macros/autoform.html index 7ffc4c59f5d..c469b814343 100644 --- a/ckan/templates/macros/autoform.html +++ b/ckan/templates/macros/autoform.html @@ -12,7 +12,7 @@ {% set form_info = [ {'name': 'ckan.site_title', 'control': 'input', 'label': _('Site Title'), 'placeholder': ''}, - {'name': 'ckan.main_css', 'control': 'select', 'options': styles, 'label': _('Style'), 'placeholder': ''}, + {'name': 'ckan.theme', 'control': 'select', 'options': styles, 'label': _('Style'), 'placeholder': ''}, {'name': 'ckan.site_description', 'control': 'input', 'label': _('Site Tag Line'), 'placeholder': ''}, {'name': 'ckan.site_logo', 'control': 'input', 'label': _('Site Tag Logo'), 'placeholder': ''}, {'name': 'ckan.site_about', 'control': 'markdown', 'label': _('About'), 'placeholder': _('About page text')}, diff --git a/ckan/tests/controllers/test_admin.py b/ckan/tests/controllers/test_admin.py index c0d0c91a031..e7bf519f9ff 100644 --- a/ckan/tests/controllers/test_admin.py +++ b/ckan/tests/controllers/test_admin.py @@ -63,7 +63,7 @@ def test_main_css_list(self, app, sysadmin_env): for option in style_select_options: assert option.string in STYLE_NAMES - def test_main_css(self, app, sysadmin_env): + def test_main_theme(self, app, sysadmin_env): """Select a colour style""" # current style @@ -72,7 +72,7 @@ def test_main_css(self, app, sysadmin_env): url = url_for(u"admin.config") # set new style css - form = {"ckan.main_css": "/base/css/red.css", "save": ""} + form = {"ckan.theme": "css/red", "save": ""} resp = app.post(url, data=form, environ_overrides=sysadmin_env) assert "red.css" in resp or "red.min.css" in resp diff --git a/ckan/views/admin.py b/ckan/views/admin.py index 1b58adbb925..88f11ea7374 100644 --- a/ckan/views/admin.py +++ b/ckan/views/admin.py @@ -29,19 +29,19 @@ def _get_sysadmins(): def _get_config_options(): styles = [{ u'text': u'Default', - u'value': u'/base/css/main.css' + u'value': u'css/main' }, { u'text': u'Red', - u'value': u'/base/css/red.css' + u'value': u'css/red' }, { u'text': u'Green', - u'value': u'/base/css/green.css' + u'value': u'css/green' }, { u'text': u'Maroon', - u'value': u'/base/css/maroon.css' + u'value': u'css/maroon' }, { u'text': u'Fuchsia', - u'value': u'/base/css/fuchsia.css' + u'value': u'css/fuchsia' }] homepages = [{ @@ -62,7 +62,7 @@ def _get_config_options(): def _get_config_items(): return [ - u'ckan.site_title', u'ckan.main_css', u'ckan.site_description', + u'ckan.site_title', u'ckan.theme', u'ckan.site_description', u'ckan.site_logo', u'ckan.site_about', u'ckan.site_intro_text', u'ckan.site_custom_css', u'ckan.homepage_style' ] diff --git a/doc/contributing/frontend/templating.rst b/doc/contributing/frontend/templating.rst index c3df14cb87d..41cfe67e329 100644 --- a/doc/contributing/frontend/templating.rst +++ b/doc/contributing/frontend/templating.rst @@ -448,7 +448,7 @@ values for the (key, value, delete) fields respectively. classes - An array of classes to apply to the control-group. attrs - Dictionary of extra tag attributes is_required - Boolean of whether this input is required for the form to validate - + Examples: @@ -481,7 +481,7 @@ Example {% set form_info = [ {'name': 'ckan.site_title', 'control': 'input', 'label': _('Site Title'), 'placeholder': ''}, - {'name': 'ckan.main_css', 'control': 'select', 'options': styles, 'label': _('Style'), 'placeholder': ''}, + {'name': 'ckan.theme', 'control': 'select', 'options': styles, 'label': _('Style'), 'placeholder': ''}, {'name': 'ckan.site_description', 'control': 'input', 'label': _('Site Tag Line'), 'placeholder': ''}, {'name': 'ckan.site_logo', 'control': 'input', 'label': _('Site Tag Logo'), 'placeholder': ''}, {'name': 'ckan.site_about', 'control': 'markdown', 'label': _('About'), 'placeholder': _('About page text')}, diff --git a/doc/extensions/remote-config-update.rst b/doc/extensions/remote-config-update.rst index e3fb66ca29c..fcce27f0cd2 100644 --- a/doc/extensions/remote-config-update.rst +++ b/doc/extensions/remote-config-update.rst @@ -34,7 +34,7 @@ First of all, let's call the :py:func:`~ckan.logic.action.get.config_option_list "help": "http://localhost:5000/api/3/action/help_show?name=config_option_list", "result": [ "ckan.site_custom_css", - "ckan.main_css", + "ckan.theme", "ckan.site_title", "ckan.site_about", "ckan.site_url", @@ -71,7 +71,7 @@ Restart the web server and do another request to the :py:func:`~ckan.logic.actio "ckan.datasets_per_page", "ckanext.example_iconfigurer.test_conf", "ckan.site_custom_css", - "ckan.main_css", + "ckan.theme", "ckan.site_title", "ckan.site_about", "ckan.site_url",