Skip to content

Commit

Permalink
move globals to helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch committed Sep 6, 2018
1 parent 12c944b commit 5886a0e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
10 changes: 0 additions & 10 deletions ckan/lib/app_globals.py
Expand Up @@ -83,12 +83,6 @@ def set_main_css(css_file):
# FIXME we should check the css file exists
app_globals.main_css = str(new_css)

def set_rtl_globals(rtl_css_file, rtl_languages):
assert rtl_css_file.endswith('.css')
new_css = rtl_css_file
# FIXME we should check the css file exists
app_globals.rtl_css = str(new_css)
app_globals.rtl_languages = rtl_languages

def set_app_global(key, value):
'''
Expand Down Expand Up @@ -181,10 +175,6 @@ def get_config_value(key, default=''):
main_css = get_config_value('ckan.main_css', '/base/css/main.css')
set_main_css(main_css)

rtl_css_file = get_config_value('ckan.i18n.rtl_css', '/base/css/rtl.css')
rtl_languages = get_config_value('ckan.i18n.rtl_languages', 'he ar')
set_rtl_globals(rtl_css_file, rtl_languages)

if app_globals.site_logo:
app_globals.header_class = 'header-image'
elif not app_globals.site_description:
Expand Down
12 changes: 11 additions & 1 deletion ckan/lib/helpers.py
Expand Up @@ -578,7 +578,7 @@ def ckan_version():

@core_helper
def lang_native_name(lang=None):
''' Return the langage name currently used in it's localised form
''' Return the language name currently used in it's localised form
either from parameter or current environ setting'''
lang = lang or lang()
locale = i18n.get_locales_dict().get(lang)
Expand All @@ -587,6 +587,16 @@ def lang_native_name(lang=None):
return lang


@core_helper
def is_rtl_language():
return lang() in config.get('ckan.i18n.rtl_languages', ['he', 'ar'])


@core_helper
def get_rtl_css():
return config.get('ckan.i18n.rtl_css', '/base/css/rtl.css')


class Message(object):
'''A message returned by ``Flash.pop_messages()``.
Expand Down
4 changes: 2 additions & 2 deletions ckan/templates/base.html
Expand Up @@ -67,8 +67,8 @@
#}
{%- block styles %}
{% resource g.main_css[6:] %}
{% if h.lang() in g.rtl_languages %}
{% resource g.rtl_css[6:] %}
{% if h.is_rtl_language() %}
{% resource h.get_rtl_css()[6:] %}
{% endif %}
{% endblock %}

Expand Down

0 comments on commit 5886a0e

Please sign in to comment.