From c24a9198562ccb7bb2e4dc683accce8628444deb Mon Sep 17 00:00:00 2001 From: Jeremy Bowman Date: Mon, 6 Nov 2017 11:32:55 -0500 Subject: [PATCH] PLAT-1774 Move x_module monkey-patching --- cms/djangoapps/xblock_config/apps.py | 26 ++++++++++++++++++++++++++ cms/envs/common.py | 2 +- cms/startup.py | 11 ----------- common/lib/xmodule/xmodule/x_module.py | 4 ++-- lms/djangoapps/lms_xblock/apps.py | 25 +++++++++++++++++++++++++ lms/envs/common.py | 2 +- lms/startup.py | 10 ---------- 7 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 cms/djangoapps/xblock_config/apps.py create mode 100644 lms/djangoapps/lms_xblock/apps.py diff --git a/cms/djangoapps/xblock_config/apps.py b/cms/djangoapps/xblock_config/apps.py new file mode 100644 index 0000000000..d378ee011d --- /dev/null +++ b/cms/djangoapps/xblock_config/apps.py @@ -0,0 +1,26 @@ +""" +xblock_config Application Configuration +""" +from __future__ import absolute_import + +from django.apps import AppConfig + +import cms.lib.xblock.runtime +import xmodule.x_module +from openedx.core.lib.xblock_utils import xblock_local_resource_url + + +class XBlockConfig(AppConfig): + """ + Default configuration for the "xblock_config" Django application. + """ + name = u'xblock_config' + verbose_name = u'XBlock Configuration' + + def ready(self): + # In order to allow descriptors 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 + # https://openedx.atlassian.net/wiki/display/PLAT/Convert+from+Storage-centric+runtimes+to+Application-centric+runtimes + xmodule.x_module.descriptor_global_handler_url = cms.lib.xblock.runtime.handler_url + xmodule.x_module.descriptor_global_local_resource_url = xblock_local_resource_url diff --git a/cms/envs/common.py b/cms/envs/common.py index 7394d9cbbf..4797aa1af6 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -955,7 +955,7 @@ INSTALLED_APPS = [ 'openedx.core.djangoapps.external_auth', 'student', # misleading name due to sharing with lms 'openedx.core.djangoapps.course_groups', # not used in cms (yet), but tests run - 'xblock_config', + 'xblock_config.apps.XBlockConfig', # Maintenance tools 'maintenance', diff --git a/cms/startup.py b/cms/startup.py index d7eac4c51d..bc336110e2 100644 --- a/cms/startup.py +++ b/cms/startup.py @@ -5,8 +5,6 @@ Module with code executed during Studio startup import django from django.conf import settings -import cms.lib.xblock.runtime -import xmodule.x_module from openedx.core.djangoapps.monkey_patch import django_db_models_options from openedx.core.lib.django_startup import autostartup @@ -14,8 +12,6 @@ from openedx.core.lib.django_startup import autostartup settings.INSTALLED_APPS # pylint: disable=pointless-statement -from openedx.core.lib.xblock_utils import xblock_local_resource_url - def run(): """ @@ -32,13 +28,6 @@ def run(): add_mimetypes() - # In order to allow descriptors 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 - # https://openedx.atlassian.net/wiki/display/PLAT/Convert+from+Storage-centric+runtimes+to+Application-centric+runtimes - xmodule.x_module.descriptor_global_handler_url = cms.lib.xblock.runtime.handler_url - xmodule.x_module.descriptor_global_local_resource_url = xblock_local_resource_url - def add_mimetypes(): """ diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py index 89356d6831..03bc8a0264 100644 --- a/common/lib/xmodule/xmodule/x_module.py +++ b/common/lib/xmodule/xmodule/x_module.py @@ -1270,7 +1270,7 @@ class ConfigurableFragmentWrapper(object): # the Runtime part of its interface. This function mostly matches the # Runtime.handler_url interface. # -# The monkey-patching happens in (lms|cms)/startup.py +# The monkey-patching happens in cms/djangoapps/xblock_config/apps.py and lms/djangoapps/lms_xblock/apps.py def descriptor_global_handler_url(block, handler_name, suffix='', query='', thirdparty=False): # pylint: disable=unused-argument """ See :meth:`xblock.runtime.Runtime.handler_url`. @@ -1282,7 +1282,7 @@ def descriptor_global_handler_url(block, handler_name, suffix='', query='', thir # we can refactor modulestore to split out the FieldData half of its interface from # the Runtime part of its interface. This function matches the Runtime.local_resource_url interface # -# The monkey-patching happens in (lms|cms)/startup.py +# The monkey-patching happens in cms/djangoapps/xblock_config/apps.py and lms/djangoapps/lms_xblock/apps.py def descriptor_global_local_resource_url(block, uri): # pylint: disable=invalid-name, unused-argument """ See :meth:`xblock.runtime.Runtime.local_resource_url`. diff --git a/lms/djangoapps/lms_xblock/apps.py b/lms/djangoapps/lms_xblock/apps.py new file mode 100644 index 0000000000..2925e86bfc --- /dev/null +++ b/lms/djangoapps/lms_xblock/apps.py @@ -0,0 +1,25 @@ +""" +lms_xblock Application Configuration +""" +from __future__ import absolute_import + +from django.apps import AppConfig + +import xmodule.x_module +from .runtime import handler_url, local_resource_url + + +class LMSXBlockConfig(AppConfig): + """ + Default configuration for the "lms.djangoapps.lms_xblock" Django application. + """ + name = u'lms.djangoapps.lms_xblock' + verbose_name = u'LMS XBlock' + + def ready(self): + # 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 + # https://openedx.atlassian.net/wiki/display/PLAT/Convert+from+Storage-centric+runtimes+to+Application-centric+runtimes + xmodule.x_module.descriptor_global_handler_url = handler_url + xmodule.x_module.descriptor_global_local_resource_url = local_resource_url diff --git a/lms/envs/common.py b/lms/envs/common.py index 403c2d2fb0..927fa1082b 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -2218,7 +2218,7 @@ INSTALLED_APPS = [ # Surveys 'survey', - 'lms.djangoapps.lms_xblock', + 'lms.djangoapps.lms_xblock.apps.LMSXBlockConfig', # Course data caching 'openedx.core.djangoapps.content.course_overviews.apps.CourseOverviewsConfig', diff --git a/lms/startup.py b/lms/startup.py index 96bf6e9122..2fe0fc6013 100644 --- a/lms/startup.py +++ b/lms/startup.py @@ -15,9 +15,6 @@ from openedx.core.lib.django_startup import autostartup from openedx.core.djangoapps.monkey_patch import django_db_models_options -import xmodule.x_module -import lms_xblock.runtime - log = logging.getLogger(__name__) @@ -36,13 +33,6 @@ def run(): add_mimetypes() - # 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 - # https://openedx.atlassian.net/wiki/display/PLAT/Convert+from+Storage-centric+runtimes+to+Application-centric+runtimes - xmodule.x_module.descriptor_global_handler_url = lms_xblock.runtime.handler_url - xmodule.x_module.descriptor_global_local_resource_url = lms_xblock.runtime.local_resource_url - def add_mimetypes(): """