WL-603 load locale paths for themes directories

This commit is contained in:
asadiqbal
2016-09-16 18:00:14 +05:00
parent dd876d8be1
commit 2833d1e9a5
8 changed files with 72 additions and 4 deletions

View File

@@ -2,6 +2,7 @@
Core logic for Comprehensive Theming.
"""
from django.conf import settings
from path import Path as path
from .helpers import get_themes
@@ -21,9 +22,16 @@ def enable_theming():
)
for theme in get_themes():
locale_dir = theme.path / "conf" / "locale"
if locale_dir.isdir():
settings.LOCALE_PATHS = (locale_dir, ) + settings.LOCALE_PATHS
if theme.themes_base_dir not in settings.MAKO_TEMPLATES['main']:
settings.MAKO_TEMPLATES['main'].insert(0, theme.themes_base_dir)
_add_theming_locales()
def _add_theming_locales():
"""
Add locale paths to settings for comprehensive theming.
"""
theme_locale_paths = settings.COMPREHENSIVE_THEME_LOCALE_PATHS
for locale_path in theme_locale_paths:
settings.LOCALE_PATHS += (path(locale_path), ) # pylint: disable=no-member

View File

@@ -0,0 +1,26 @@
"""
Tests for Themeing locales
"""
import unittest
from django.conf import settings
from django.test import TestCase
import os
class TestComprehensiveThemeLocale(TestCase):
"""
Test Comprehensive Theme Locales
"""
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_theme_locale_path_in_settings(self):
"""
test comprehensive theming paths in settings.
"""
self.assertIn(settings.REPO_ROOT / 'themes/conf/locale', settings.LOCALE_PATHS) # pylint: disable=no-member
def test_theme_locale_path_exist(self):
"""
test comprehensive theming directory path exist.
"""
self.assertTrue(os.path.exists(settings.REPO_ROOT / "themes/conf/locale"))