Set xmodule_runtime on all XModule-like things (including pure XBlocks using the XModuleMixin)
Expose xmodule_runtime as .runtime if it's set (otherwise, fall back to the supplied runtime). This causes all blocks to act like XModules when they have a ModuleSystem, and like XModuleDescriptors if they only have a DescriptorSystem.
This commit is contained in:
@@ -191,6 +191,26 @@ class XModuleMixin(XBlockMixin):
|
||||
default=None
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.xmodule_runtime = None
|
||||
super(XModuleMixin, self).__init__(*args, **kwargs)
|
||||
|
||||
@property
|
||||
def runtime(self):
|
||||
# Handle XModule backwards compatibility. If this is a pure
|
||||
# XBlock, and it has an xmodule_runtime defined, then we're in
|
||||
# an XModule context, not an XModuleDescriptor context,
|
||||
# so we should use the xmodule_runtime (ModuleSystem) as the runtime.
|
||||
if (not isinstance(self, (XModule, XModuleDescriptor)) and
|
||||
self.xmodule_runtime is not None):
|
||||
return self.xmodule_runtime
|
||||
return self._runtime
|
||||
|
||||
@runtime.setter
|
||||
def runtime(self, value):
|
||||
self._runtime = value
|
||||
|
||||
|
||||
@property
|
||||
def system(self):
|
||||
"""
|
||||
@@ -1168,9 +1188,8 @@ class DescriptorSystem(MetricsMixin, ConfigurableFragmentWrapper, Runtime): # p
|
||||
return super(DescriptorSystem, self).render(block, view_name, context)
|
||||
|
||||
def handler_url(self, block, handler_name, suffix='', query='', thirdparty=False):
|
||||
xmodule_runtime = getattr(block, 'xmodule_runtime', None)
|
||||
if xmodule_runtime is not None:
|
||||
return xmodule_runtime.handler_url(block, handler_name, suffix, query, thirdparty)
|
||||
if block.xmodule_runtime is not None:
|
||||
return block.xmodule_runtime.handler_url(block, handler_name, suffix, query, thirdparty)
|
||||
else:
|
||||
# Currently, Modulestore is responsible for instantiating DescriptorSystems
|
||||
# This means that LMS/CMS don't have a way to define a subclass of DescriptorSystem
|
||||
@@ -1182,9 +1201,8 @@ class DescriptorSystem(MetricsMixin, ConfigurableFragmentWrapper, Runtime): # p
|
||||
"""
|
||||
See :meth:`xblock.runtime.Runtime:local_resource_url` for documentation.
|
||||
"""
|
||||
xmodule_runtime = getattr(block, 'xmodule_runtime', None)
|
||||
if xmodule_runtime is not None:
|
||||
return xmodule_runtime.local_resource_url(block, uri)
|
||||
if block.xmodule_runtime is not None:
|
||||
return block.xmodule_runtime.local_resource_url(block, uri)
|
||||
else:
|
||||
# Currently, Modulestore is responsible for instantiating DescriptorSystems
|
||||
# This means that LMS/CMS don't have a way to define a subclass of DescriptorSystem
|
||||
@@ -1202,9 +1220,8 @@ class DescriptorSystem(MetricsMixin, ConfigurableFragmentWrapper, Runtime): # p
|
||||
"""
|
||||
See :meth:`xblock.runtime.Runtime:publish` for documentation.
|
||||
"""
|
||||
xmodule_runtime = getattr(block, 'xmodule_runtime', None)
|
||||
if xmodule_runtime is not None:
|
||||
return xmodule_runtime.publish(block, event_type, event)
|
||||
if block.xmodule_runtime is not None:
|
||||
return block.xmodule_runtime.publish(block, event_type, event)
|
||||
|
||||
def add_block_as_child_node(self, block, node):
|
||||
child = etree.SubElement(node, "unknown")
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
-e git+https://github.com/pmitros/django-pyfs.git@d175715e0fe3367ec0f1ee429c242d603f6e8b10#egg=djpyfs
|
||||
|
||||
# Our libraries:
|
||||
-e git+https://github.com/edx/XBlock.git@81a6d713c98d4914af96a0ca624ee7fa4903625e#egg=XBlock
|
||||
-e git+https://github.com/edx/XBlock.git@246811773c67a84fdb17614a8e9f7ec7b1890574#egg=XBlock
|
||||
-e git+https://github.com/edx/codejail.git@66dd5a45e5072666ff9a70c768576e9ffd1daa4b#egg=codejail
|
||||
-e git+https://github.com/edx/diff-cover.git@v0.5.0#egg=diff_cover
|
||||
-e git+https://github.com/edx/js-test-tool.git@v0.1.5#egg=js_test_tool
|
||||
|
||||
Reference in New Issue
Block a user