diff --git a/lms/djangoapps/lms_initialization/__init__.py b/lms/djangoapps/lms_initialization/__init__.py new file mode 100644 index 0000000000..a89aa1b1b1 --- /dev/null +++ b/lms/djangoapps/lms_initialization/__init__.py @@ -0,0 +1,3 @@ +""" +Initialization app for the LMS +""" diff --git a/lms/djangoapps/lms_initialization/apps.py b/lms/djangoapps/lms_initialization/apps.py new file mode 100644 index 0000000000..12002ca0b0 --- /dev/null +++ b/lms/djangoapps/lms_initialization/apps.py @@ -0,0 +1,32 @@ +""" +Initialization app for the LMS + +This app consists solely of a ready method in its AppConfig, and should be +included early in the INSTALLED_APPS list. +""" + +import analytics +from django.apps import AppConfig +from django.conf import settings + + +class LMSInitializationConfig(AppConfig): + """ + Application Configuration for lms_initialization. + """ + name = 'lms_initialization' + verbose_name = 'LMS Initialization' + + def ready(self): + """ + Global LMS initialization methods are called here. This runs after + settings have loaded, but before most other djangoapp initializations. + """ + self._initialize_analytics() + + def _initialize_analytics(self): + """ + Initialize Segment analytics module by setting the write_key. + """ + if settings.LMS_SEGMENT_KEY: + analytics.write_key = settings.LMS_SEGMENT_KEY diff --git a/lms/envs/common.py b/lms/envs/common.py index 1517e8be6d..61787e1077 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -2016,6 +2016,9 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'djcelery', + # Initialization + 'lms_initialization.apps.LMSInitializationConfig', + # Common views 'openedx.core.djangoapps.common_views', diff --git a/lms/startup.py b/lms/startup.py index d5836dad34..969093f34a 100644 --- a/lms/startup.py +++ b/lms/startup.py @@ -13,7 +13,6 @@ settings.INSTALLED_APPS # pylint: disable=pointless-statement from openedx.core.lib.django_startup import autostartup from openedx.core.release import doc_version -import analytics from openedx.core.djangoapps.monkey_patch import django_db_models_options @@ -50,10 +49,6 @@ def run(): # Mako requires the directories to be added after the django setup. microsite.enable_microsites(log) - # Initialize Segment analytics module by setting the write_key. - if settings.LMS_SEGMENT_KEY: - analytics.write_key = settings.LMS_SEGMENT_KEY - # register any dependency injections that we need to support in edx_proctoring # right now edx_proctoring is dependent on the openedx.core.djangoapps.credit and # lms.djangoapps.grades