From 1e599bed09a549a35798c0870f71b69fe29a879e Mon Sep 17 00:00:00 2001 From: Troy Sankey Date: Tue, 31 Oct 2017 12:51:59 -0400 Subject: [PATCH 1/2] Add lms_initialization app This app is a grab bag of init code which can't find a good home in other apps. This was created in response to removing lms.startup.run(). --- lms/djangoapps/lms_initialization/__init__.py | 3 +++ lms/djangoapps/lms_initialization/apps.py | 25 +++++++++++++++++++ lms/envs/common.py | 3 +++ 3 files changed, 31 insertions(+) create mode 100644 lms/djangoapps/lms_initialization/__init__.py create mode 100644 lms/djangoapps/lms_initialization/apps.py 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..330d0e3fa2 --- /dev/null +++ b/lms/djangoapps/lms_initialization/apps.py @@ -0,0 +1,25 @@ +""" +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. + """ + pass diff --git a/lms/envs/common.py b/lms/envs/common.py index bbbf537e19..43230c3216 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1988,6 +1988,9 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'djcelery', + # Initialization + 'lms_initialization.apps.LMSInitializationConfig', + # Common views 'openedx.core.djangoapps.common_views', From 20b6dd51828a7bf3d37c9063c55582554cc8bbcf Mon Sep 17 00:00:00 2001 From: Troy Sankey Date: Tue, 31 Oct 2017 12:54:42 -0400 Subject: [PATCH 2/2] Move analytics initialization out of lms.startup.run lms.startup is being removed, so initialize the analytics module in the lms_initialization ready() method instead. --- lms/djangoapps/lms_initialization/apps.py | 9 ++++++++- lms/startup.py | 5 ----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lms/djangoapps/lms_initialization/apps.py b/lms/djangoapps/lms_initialization/apps.py index 330d0e3fa2..12002ca0b0 100644 --- a/lms/djangoapps/lms_initialization/apps.py +++ b/lms/djangoapps/lms_initialization/apps.py @@ -22,4 +22,11 @@ class LMSInitializationConfig(AppConfig): Global LMS initialization methods are called here. This runs after settings have loaded, but before most other djangoapp initializations. """ - pass + 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/startup.py b/lms/startup.py index 05b4ff18f9..33e2ff3b18 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 @@ -57,10 +56,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