From 2de2e3027d8db8c05049f34873f162bb86c59bda Mon Sep 17 00:00:00 2001 From: Jeremy Bowman Date: Tue, 31 Oct 2017 18:19:06 -0400 Subject: [PATCH] PLAT-1773 Delegate edx-proctoring service registration to app ready methods --- cms/envs/common.py | 2 +- lms/djangoapps/grades/apps.py | 5 +++++ lms/djangoapps/instructor/apps.py | 19 +++++++++++++++++++ lms/envs/common.py | 4 ++-- lms/startup.py | 17 ----------------- openedx/core/djangoapps/credit/apps.py | 19 +++++++++++++++++++ 6 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 lms/djangoapps/instructor/apps.py create mode 100644 openedx/core/djangoapps/credit/apps.py diff --git a/cms/envs/common.py b/cms/envs/common.py index a0d36d2f8f..07c31719ed 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -1028,7 +1028,7 @@ INSTALLED_APPS = [ 'openedx.core.djangoapps.coursegraph.apps.CoursegraphConfig', # Credit courses - 'openedx.core.djangoapps.credit', + 'openedx.core.djangoapps.credit.apps.CreditConfig', 'xblock_django', diff --git a/lms/djangoapps/grades/apps.py b/lms/djangoapps/grades/apps.py index 3f509a9259..66684d5051 100644 --- a/lms/djangoapps/grades/apps.py +++ b/lms/djangoapps/grades/apps.py @@ -5,6 +5,8 @@ Signal handlers are connected here. """ from django.apps import AppConfig +from django.conf import settings +from edx_proctoring.runtime import set_runtime_service class GradesConfig(AppConfig): @@ -20,3 +22,6 @@ class GradesConfig(AppConfig): # Can't import models at module level in AppConfigs, and models get # included from the signal handlers from .signals import handlers # pylint: disable=unused-variable + if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'): + from .services import GradesService + set_runtime_service('grades', GradesService()) diff --git a/lms/djangoapps/instructor/apps.py b/lms/djangoapps/instructor/apps.py new file mode 100644 index 0000000000..53922d66a0 --- /dev/null +++ b/lms/djangoapps/instructor/apps.py @@ -0,0 +1,19 @@ +""" +Instructor Application Configuration +""" + +from django.apps import AppConfig +from django.conf import settings +from edx_proctoring.runtime import set_runtime_service + + +class InstructorConfig(AppConfig): + """ + Default configuration for the "lms.djangoapps.instructor" Django application. + """ + name = u'lms.djangoapps.instructor' + + def ready(self): + if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'): + from .services import InstructorService + set_runtime_service('instructor', InstructorService()) diff --git a/lms/envs/common.py b/lms/envs/common.py index 1477a1b429..ae9079993d 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -2074,7 +2074,7 @@ INSTALLED_APPS = [ 'util', 'certificates.apps.CertificatesConfig', 'dashboard', - 'lms.djangoapps.instructor', + 'lms.djangoapps.instructor.apps.InstructorConfig', 'lms.djangoapps.instructor_task', 'openedx.core.djangoapps.course_groups', 'bulk_email', @@ -2228,7 +2228,7 @@ INSTALLED_APPS = [ 'commerce', # Credit courses - 'openedx.core.djangoapps.credit', + 'openedx.core.djangoapps.credit.apps.CreditConfig', # Course teams 'lms.djangoapps.teams', diff --git a/lms/startup.py b/lms/startup.py index 969093f34a..83055939c9 100644 --- a/lms/startup.py +++ b/lms/startup.py @@ -49,23 +49,6 @@ def run(): # Mako requires the directories to be added after the django setup. microsite.enable_microsites(log) - # 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 - if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'): - # Import these here to avoid circular dependencies of the form: - # edx-platform app --> DRF --> django translation --> edx-platform app - from edx_proctoring.runtime import set_runtime_service - from lms.djangoapps.instructor.services import InstructorService - from openedx.core.djangoapps.credit.services import CreditService - from lms.djangoapps.grades.services import GradesService - set_runtime_service('credit', CreditService()) - - # register InstructorService (for deleting student attempts and user staff access roles) - set_runtime_service('instructor', InstructorService()) - - set_runtime_service('grades', GradesService()) - # 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/openedx/core/djangoapps/credit/apps.py b/openedx/core/djangoapps/credit/apps.py new file mode 100644 index 0000000000..eedac30579 --- /dev/null +++ b/openedx/core/djangoapps/credit/apps.py @@ -0,0 +1,19 @@ +""" +Credit Application Configuration +""" + +from django.apps import AppConfig +from django.conf import settings +from edx_proctoring.runtime import set_runtime_service + + +class CreditConfig(AppConfig): + """ + Default configuration for the "openedx.core.djangoapps.credit" Django application. + """ + name = u'openedx.core.djangoapps.credit' + + def ready(self): + if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'): + from .services import CreditService + set_runtime_service('credit', CreditService())