Commit eb030cc6 by Xavier Antoviaque

Load image resources with local_resource_url()

parent 27b6ba9c
...@@ -57,6 +57,7 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin): ...@@ -57,6 +57,7 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin):
* get_children_objects() * get_children_objects()
* Functionality of XBlockWithChildrenFragmentsMixin * Functionality of XBlockWithChildrenFragmentsMixin
* self.xblock_container for when we need a real XBlock reference
Other changes caused by LightChild use: Other changes caused by LightChild use:
...@@ -152,6 +153,7 @@ class XBlockWithLightChildren(LightChildrenMixin, XBlock): ...@@ -152,6 +153,7 @@ class XBlockWithLightChildren(LightChildrenMixin, XBlock):
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(XBlockWithLightChildren, self).__init__(*args, **kwargs) super(XBlockWithLightChildren, self).__init__(*args, **kwargs)
self.xblock_container = self
self.load_children_from_xml_content() self.load_children_from_xml_content()
@XBlock.json_handler @XBlock.json_handler
...@@ -184,6 +186,7 @@ class LightChild(Plugin, LightChildrenMixin): ...@@ -184,6 +186,7 @@ class LightChild(Plugin, LightChildrenMixin):
def __init__(self, parent): def __init__(self, parent):
self.parent = parent self.parent = parent
self.xblock_container = parent.xblock_container
@property @property
def runtime(self): def runtime(self):
......
...@@ -69,6 +69,9 @@ class MentoringBlock(XBlockWithLightChildren): ...@@ -69,6 +69,9 @@ class MentoringBlock(XBlockWithLightChildren):
fragment, named_children = self.get_children_fragment(context, view_name='mentoring_view', fragment, named_children = self.get_children_fragment(context, view_name='mentoring_view',
not_instance_of=MentoringMessageBlock) not_instance_of=MentoringMessageBlock)
correct_icon_url = self.runtime.local_resource_url(self.xblock_container,
'public/img/correct-icon.png')
fragment.add_content(render_template('templates/html/mentoring.html', { fragment.add_content(render_template('templates/html/mentoring.html', {
'self': self, 'self': self,
'named_children': named_children, 'named_children': named_children,
...@@ -77,10 +80,8 @@ class MentoringBlock(XBlockWithLightChildren): ...@@ -77,10 +80,8 @@ class MentoringBlock(XBlockWithLightChildren):
fragment.add_css(load_resource('static/css/mentoring.css')) fragment.add_css(load_resource('static/css/mentoring.css'))
fragment.add_javascript(load_resource('static/js/vendor/underscore-min.js')) fragment.add_javascript(load_resource('static/js/vendor/underscore-min.js'))
fragment.add_javascript(load_resource('static/js/mentoring.js')) fragment.add_javascript(load_resource('static/js/mentoring.js'))
# TODO-LMS-WORKAROUND: Use self.runtime.resources_url() when supported
fragment.add_resource(load_resource('templates/html/mentoring_progress.html').format( fragment.add_resource(load_resource('templates/html/mentoring_progress.html').format(
completed='/static/images/correct-icon.png'), completed=correct_icon_url),
"text/html") "text/html")
fragment.initialize_js('MentoringBlock') fragment.initialize_js('MentoringBlock')
......
...@@ -54,8 +54,8 @@ class MentoringTableBlock(LightChild): ...@@ -54,8 +54,8 @@ class MentoringTableBlock(LightChild):
view_name='mentoring_table_view') view_name='mentoring_table_view')
f, header_frags = self.get_children_fragment(context, view_name='mentoring_table_header_view') f, header_frags = self.get_children_fragment(context, view_name='mentoring_table_header_view')
# TODO: What's the right way to link to images from CSS? This hack won't work in prod bg_image_url = self.runtime.local_resource_url(self.xblock_container,
bg_image_url = '' #self.runtime.resources_url('mentoring/img/{}-bg.png'.format(self.type)) 'public/img/{}-bg.png'.format(self.type))
# Load an optional description for the background image, for accessibility # Load an optional description for the background image, for accessibility
try: try:
......
...@@ -71,5 +71,5 @@ setup( ...@@ -71,5 +71,5 @@ setup(
'xblock.v1': BLOCKS, 'xblock.v1': BLOCKS,
'xblock.light_children': BLOCKS_CHILDREN, 'xblock.light_children': BLOCKS_CHILDREN,
}, },
package_data=package_data("mentoring", ["static", "templates"]), package_data=package_data("mentoring", ["static", "templates", "public"]),
) )
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