diff --git a/common/djangoapps/microsite_configuration/apps.py b/common/djangoapps/microsite_configuration/apps.py new file mode 100644 index 0000000000..6233628385 --- /dev/null +++ b/common/djangoapps/microsite_configuration/apps.py @@ -0,0 +1,15 @@ + +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) diff --git a/lms/envs/common.py b/lms/envs/common.py index ae9079993d..4fb74b49c0 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -557,6 +557,8 @@ def _make_main_mako_templates(settings): for theme in get_themes_unchecked(themes_dirs, PROJECT_ROOT): if theme.themes_base_dir not in settings.MAIN_MAKO_TEMPLATES_BASE: 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 MAKO_TEMPLATES['main'] = _make_main_mako_templates derived_dict_entry('MAKO_TEMPLATES', 'main') @@ -620,6 +622,18 @@ TEMPLATES = [ } ] 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 = [ 'openedx.core.djangoapps.dark_lang', # Microsite configuration - 'microsite_configuration', + 'microsite_configuration.apps.MicrositeConfigurationConfig', # RSS Proxy 'rss_proxy', diff --git a/lms/startup.py b/lms/startup.py index 83055939c9..0afc7f782b 100644 --- a/lms/startup.py +++ b/lms/startup.py @@ -21,8 +21,6 @@ import lms_xblock.runtime from startup_configurations.validate_config import validate_lms_config -from microsite_configuration import microsite - log = logging.getLogger(__name__) @@ -35,20 +33,12 @@ def run(): """ 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() autostartup() 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 # monkey-patch the x_module library. # TODO: Remove this code when Runtimes are no longer created by modulestores diff --git a/lms/tests.py b/lms/tests.py index cddcc181d9..bab5c7df1e 100644 --- a/lms/tests.py +++ b/lms/tests.py @@ -1,5 +1,6 @@ """Tests for the lms module itself.""" +import logging import mimetypes from django.core.urlresolvers import reverse @@ -7,11 +8,13 @@ from django.test import TestCase from mock import patch 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 xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory +log = logging.getLogger(__name__) + class LmsModuleTests(TestCase): """ @@ -38,7 +41,7 @@ class TemplateLookupTests(TestCase): self.assertEqual(len([directory for directory in directories if 'external_module' in directory]), 1) # This should not clear the directories list - startup.enable_microsites() + microsite.enable_microsites(log) directories = LOOKUP['main'].directories self.assertEqual(len([directory for directory in directories if 'external_module' in directory]), 1)