core.py 1.1 KB
Newer Older
David Baumgold committed
1 2 3
"""
Core logic for Comprehensive Theming.
"""
4 5
from logging import getLogger

David Baumgold committed
6
from django.conf import settings
7
from path import Path as path
David Baumgold committed
8

9
from .helpers import get_themes
David Baumgold committed
10

11
logger = getLogger(__name__)  # pylint: disable=invalid-name
David Baumgold committed
12 13


14
def enable_theming():
David Baumgold committed
15
    """
16
    Add directories and relevant paths to settings for comprehensive theming.
David Baumgold committed
17
    """
18 19 20 21 22 23 24 25 26 27
    # Deprecated Warnings
    if hasattr(settings, "COMPREHENSIVE_THEME_DIR"):
        logger.warning(
            "\033[93m \nDeprecated: "
            "\n\tCOMPREHENSIVE_THEME_DIR setting has been deprecated in favor of COMPREHENSIVE_THEME_DIRS.\033[00m"
        )

    for theme in get_themes():
        if theme.themes_base_dir not in settings.MAKO_TEMPLATES['main']:
            settings.MAKO_TEMPLATES['main'].insert(0, theme.themes_base_dir)
28 29 30 31 32 33 34 35 36 37 38

    _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