Commit 879d03c4 by Alan Boudreault Committed by Zia Fazal

Add the ability to specify explicitly the block_type for pkg_resource

parent 6aced636
...@@ -98,8 +98,8 @@ class PreviewModuleSystem(ModuleSystem): # pylint: disable=abstract-method ...@@ -98,8 +98,8 @@ class PreviewModuleSystem(ModuleSystem): # pylint: disable=abstract-method
'suffix': suffix, 'suffix': suffix,
}) + '?' + query }) + '?' + query
def local_resource_url(self, block, uri): def local_resource_url(self, block, uri, block_type=None):
return local_resource_url(block, uri) return local_resource_url(block, uri, block_type)
def applicable_aside_types(self, block): def applicable_aside_types(self, block):
""" """
......
...@@ -25,11 +25,11 @@ def handler_url(block, handler_name, suffix='', query='', thirdparty=False): ...@@ -25,11 +25,11 @@ def handler_url(block, handler_name, suffix='', query='', thirdparty=False):
return url return url
def local_resource_url(block, uri): def local_resource_url(block, uri, block_type=None):
""" """
local_resource_url for Studio local_resource_url for Studio
""" """
return reverse('xblock_resource_url', kwargs={ return reverse('xblock_resource_url', kwargs={
'block_type': block.scope_ids.block_type, 'block_type': block_type or block.scope_ids.block_type,
'uri': uri, 'uri': uri,
}) })
...@@ -1273,15 +1273,19 @@ class DescriptorSystem(MetricsMixin, ConfigurableFragmentWrapper, Runtime): # p ...@@ -1273,15 +1273,19 @@ class DescriptorSystem(MetricsMixin, ConfigurableFragmentWrapper, Runtime): # p
# global function that the application can override. # global function that the application can override.
return descriptor_global_handler_url(block, handler_name, suffix, query, thirdparty) return descriptor_global_handler_url(block, handler_name, suffix, query, thirdparty)
def local_resource_url(self, block, uri): def local_resource_url(self, block, uri, block_type=None):
""" """
See :meth:`xblock.runtime.Runtime:local_resource_url` for documentation. See :meth:`xblock.runtime.Runtime:local_resource_url` for documentation.
""" """
# Currently, Modulestore is responsible for instantiating DescriptorSystems xmodule_runtime = getattr(block, 'xmodule_runtime', None)
# This means that LMS/CMS don't have a way to define a subclass of DescriptorSystem if xmodule_runtime is not None:
# that implements the correct local_resource_url. So, for now, instead, we will reference a return xmodule_runtime.local_resource_url(block, uri, block_type)
# global function that the application can override. else:
return descriptor_global_local_resource_url(block, uri) # Currently, Modulestore is responsible for instantiating DescriptorSystems
# This means that LMS/CMS don't have a way to define a subclass of DescriptorSystem
# that implements the correct local_resource_url. So, for now, instead, we will reference a
# global function that the application can override.
return descriptor_global_local_resource_url(block, uri)
def applicable_aside_types(self, block): def applicable_aside_types(self, block):
""" """
......
...@@ -116,12 +116,12 @@ class LmsHandlerUrls(object): ...@@ -116,12 +116,12 @@ class LmsHandlerUrls(object):
return url return url
def local_resource_url(self, block, uri): def local_resource_url(self, block, uri, block_type=None):
""" """
local_resource_url for Studio local_resource_url for Studio
""" """
path = reverse('xblock_resource_url', kwargs={ path = reverse('xblock_resource_url', kwargs={
'block_type': block.scope_ids.block_type, 'block_type': block_type or block.scope_ids.block_type,
'uri': uri, 'uri': uri,
}) })
return '//{}{}'.format(settings.SITE_NAME, path) return '//{}{}'.format(settings.SITE_NAME, path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment