Commit a36eb51a by John Eskew

Move microsite config from startup.py to settings and AppConfig.ready.

parent 6939a581
import logging
from django.apps import AppConfig
from .microsite import enable_microsites
log = logging.getLogger(__name__)
class MicrositeConfigurationConfig(AppConfig):
name = 'microsite_configuration'
verbose_name = "Microsite Configuration"
def ready(self):
# Mako requires the directories to be added after the django setup.
enable_microsites(log)
...@@ -557,6 +557,8 @@ def _make_main_mako_templates(settings): ...@@ -557,6 +557,8 @@ def _make_main_mako_templates(settings):
for theme in get_themes_unchecked(themes_dirs, PROJECT_ROOT): for theme in get_themes_unchecked(themes_dirs, PROJECT_ROOT):
if theme.themes_base_dir not in settings.MAIN_MAKO_TEMPLATES_BASE: if theme.themes_base_dir not in settings.MAIN_MAKO_TEMPLATES_BASE:
settings.MAIN_MAKO_TEMPLATES_BASE.insert(0, theme.themes_base_dir) settings.MAIN_MAKO_TEMPLATES_BASE.insert(0, theme.themes_base_dir)
if settings.FEATURES.get('USE_MICROSITES', False) and getattr(settings, "MICROSITE_CONFIGURATION", False):
settings.MAIN_MAKO_TEMPLATES_BASE.insert(0, settings.MICROSITE_ROOT_DIR)
return settings.MAIN_MAKO_TEMPLATES_BASE return settings.MAIN_MAKO_TEMPLATES_BASE
MAKO_TEMPLATES['main'] = _make_main_mako_templates MAKO_TEMPLATES['main'] = _make_main_mako_templates
derived_dict_entry('MAKO_TEMPLATES', 'main') derived_dict_entry('MAKO_TEMPLATES', 'main')
...@@ -620,6 +622,18 @@ TEMPLATES = [ ...@@ -620,6 +622,18 @@ TEMPLATES = [
} }
] ]
DEFAULT_TEMPLATE_ENGINE = TEMPLATES[0] DEFAULT_TEMPLATE_ENGINE = TEMPLATES[0]
DEFAULT_TEMPLATE_ENGINE_DIRS = DEFAULT_TEMPLATE_ENGINE['DIRS'][:]
def _add_microsite_dirs_to_default_template_engine(settings):
"""
Derives the final DEFAULT_TEMPLATE_ENGINE['DIRS'] setting from other settings.
"""
if settings.FEATURES.get('USE_MICROSITES', False) and getattr(settings, "MICROSITE_CONFIGURATION", False):
DEFAULT_TEMPLATE_ENGINE_DIRS.append(settings.MICROSITE_ROOT_DIR)
return DEFAULT_TEMPLATE_ENGINE_DIRS
DEFAULT_TEMPLATE_ENGINE['DIRS'] = _add_microsite_dirs_to_default_template_engine
derived_dict_entry('DEFAULT_TEMPLATE_ENGINE', 'DIRS')
############################################################################################### ###############################################################################################
...@@ -2176,7 +2190,7 @@ INSTALLED_APPS = [ ...@@ -2176,7 +2190,7 @@ INSTALLED_APPS = [
'openedx.core.djangoapps.dark_lang', 'openedx.core.djangoapps.dark_lang',
# Microsite configuration # Microsite configuration
'microsite_configuration', 'microsite_configuration.apps.MicrositeConfigurationConfig',
# RSS Proxy # RSS Proxy
'rss_proxy', 'rss_proxy',
......
...@@ -21,8 +21,6 @@ import lms_xblock.runtime ...@@ -21,8 +21,6 @@ import lms_xblock.runtime
from startup_configurations.validate_config import validate_lms_config from startup_configurations.validate_config import validate_lms_config
from microsite_configuration import microsite
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -35,20 +33,12 @@ def run(): ...@@ -35,20 +33,12 @@ def run():
""" """
django_db_models_options.patch() django_db_models_options.patch()
# We currently use 2 template rendering engines, mako and django_templates,
# and one of them (django templates), requires the directories be added
# before the django.setup().
microsite.enable_microsites_pre_startup(log)
django.setup() django.setup()
autostartup() autostartup()
add_mimetypes() add_mimetypes()
# Mako requires the directories to be added after the django setup.
microsite.enable_microsites(log)
# In order to allow modules to use a handler url, we need to # In order to allow modules to use a handler url, we need to
# monkey-patch the x_module library. # monkey-patch the x_module library.
# TODO: Remove this code when Runtimes are no longer created by modulestores # TODO: Remove this code when Runtimes are no longer created by modulestores
......
"""Tests for the lms module itself.""" """Tests for the lms module itself."""
import logging
import mimetypes import mimetypes
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
...@@ -7,11 +8,13 @@ from django.test import TestCase ...@@ -7,11 +8,13 @@ from django.test import TestCase
from mock import patch from mock import patch
from edxmako import LOOKUP, add_lookup from edxmako import LOOKUP, add_lookup
from lms import startup from microsite_configuration import microsite
from openedx.features.course_experience import course_home_url_name from openedx.features.course_experience import course_home_url_name
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
log = logging.getLogger(__name__)
class LmsModuleTests(TestCase): class LmsModuleTests(TestCase):
""" """
...@@ -38,7 +41,7 @@ class TemplateLookupTests(TestCase): ...@@ -38,7 +41,7 @@ class TemplateLookupTests(TestCase):
self.assertEqual(len([directory for directory in directories if 'external_module' in directory]), 1) self.assertEqual(len([directory for directory in directories if 'external_module' in directory]), 1)
# This should not clear the directories list # This should not clear the directories list
startup.enable_microsites() microsite.enable_microsites(log)
directories = LOOKUP['main'].directories directories = LOOKUP['main'].directories
self.assertEqual(len([directory for directory in directories if 'external_module' in directory]), 1) self.assertEqual(len([directory for directory in directories if 'external_module' in directory]), 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment