Commit 57e6b421 by dragonfi

Have all resource loading go trough utils.loader instance

parent e6e914ec
......@@ -32,7 +32,7 @@ from xblock.fragment import Fragment
from .light_children import LightChild, Boolean, Scope, String, Integer, Float
from .step import StepMixin
from .models import Answer
from .utils import render_js_template
from .utils import loader
# Globals ###########################################################
......@@ -92,11 +92,11 @@ class AnswerBlock(LightChild, StepMixin):
def mentoring_view(self, context=None):
if not self.read_only:
html = render_js_template('templates/html/answer_editable.html', {
html = loader.custom_render_js_template('templates/html/answer_editable.html', {
'self': self,
})
else:
html = render_js_template('templates/html/answer_read_only.html', {
html = loader.custom_render_js_template('templates/html/answer_read_only.html', {
'self': self,
})
......@@ -108,7 +108,7 @@ class AnswerBlock(LightChild, StepMixin):
return fragment
def mentoring_table_view(self, context=None):
html = render_js_template('templates/html/answer_table.html', {
html = loader.custom_render_js_template('templates/html/answer_table.html', {
'self': self,
})
fragment = Fragment(html)
......
......@@ -32,7 +32,7 @@ from xblock.fields import String, Scope
from xblock.fragment import Fragment
from .models import Answer
from .utils import list2csv, render_template
from .utils import list2csv, loader
# Globals ###########################################################
......@@ -50,7 +50,7 @@ class MentoringDataExportBlock(XBlock):
scope=Scope.settings)
def student_view(self, context):
html = render_template('templates/html/dataexport.html', {
html = loader.render_template('templates/html/dataexport.html', {
'self': self,
})
......
......@@ -28,7 +28,7 @@ import logging
from .light_children import Scope, String
from .questionnaire import QuestionnaireAbstractBlock
from .utils import render_template
from .utils import loader
# Globals ###########################################################
......@@ -59,7 +59,7 @@ class MCQBlock(QuestionnaireAbstractBlock):
if submission in tip.display_with_defaults:
tips_fragments.append(tip.render())
formatted_tips = render_template('templates/html/tip_choice_group.html', {
formatted_tips = loader.render_template('templates/html/tip_choice_group.html', {
'self': self,
'tips_fragments': tips_fragments,
'completed': correct,
......
......@@ -40,7 +40,7 @@ from .header import SharedHeaderBlock
from .html import HTMLBlock
from .message import MentoringMessageBlock
from .step import StepParentMixin
from .utils import get_scenarios_from_path, load_resource, render_template
from .utils import loader
# Globals ###########################################################
......@@ -127,7 +127,7 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
not_instance_of=self.FLOATING_BLOCKS,
)
fragment.add_content(render_template('templates/html/mentoring.html', {
fragment.add_content(loader.render_template('templates/html/mentoring.html', {
'self': self,
'named_children': named_children,
'missing_dependency_url': self.has_missing_dependency and self.next_step_url,
......@@ -145,8 +145,8 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
)
fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/mentoring.js'))
fragment.add_resource(load_resource('templates/html/mentoring_attempts.html'), "text/html")
fragment.add_resource(load_resource('templates/html/mentoring_grade.html'), "text/html")
fragment.add_resource(loader.load_unicode('templates/html/mentoring_attempts.html'), "text/html")
fragment.add_resource(loader.load_unicode('templates/html/mentoring_grade.html'), "text/html")
fragment.initialize_js('MentoringBlock')
......@@ -374,7 +374,7 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
Editing view in Studio
"""
fragment = Fragment()
fragment.add_content(render_template('templates/html/mentoring_edit.html', {
fragment.add_content(loader.render_template('templates/html/mentoring_edit.html', {
'self': self,
'xml_content': self.xml_content,
}))
......@@ -442,4 +442,4 @@ class MentoringBlock(XBlockWithLightChildren, StepParentMixin):
"""
Scenarios displayed by the workbench. Load them from external (private) repository
"""
return get_scenarios_from_path('templates/xml')
return loader.load_scenarios_from_path('templates/xml')
......@@ -26,7 +26,7 @@
import logging
from .light_children import LightChild, Scope, String
from .utils import render_template
from .utils import loader
# Globals ###########################################################
......@@ -47,7 +47,7 @@ class MentoringMessageBlock(LightChild):
def mentoring_view(self, context=None):
fragment, named_children = self.get_children_fragment(context, view_name='mentoring_view')
fragment.add_content(render_template('templates/html/message.html', {
fragment.add_content(loader.render_template('templates/html/message.html', {
'self': self,
'named_children': named_children,
}))
......
......@@ -28,7 +28,7 @@ import logging
from .light_children import List, Scope, Boolean
from .questionnaire import QuestionnaireAbstractBlock
from .utils import render_template
from .utils import loader
# Globals ###########################################################
......@@ -73,7 +73,7 @@ class MRQBlock(QuestionnaireAbstractBlock):
# Only include tips/results in returned response if we want to display them
if not self.hide_results:
choice_result['completed'] = choice_completed
choice_result['tips'] = render_template('templates/html/tip_choice_group.html', {
choice_result['tips'] = loader.render_template('templates/html/tip_choice_group.html', {
'self': self,
'tips_fragments': choice_tips_fragments,
'completed': choice_completed,
......
......@@ -31,7 +31,7 @@ from .choice import ChoiceBlock
from .step import StepMixin
from .light_children import LightChild, Scope, String, Float
from .tip import TipBlock
from .utils import render_template, render_js_template
from .utils import loader
# Globals ###########################################################
......@@ -82,14 +82,14 @@ class QuestionnaireAbstractBlock(LightChild, StepMixin):
template_path = 'templates/html/{}_{}.html'.format(name.lower(), self.type)
render_function = render_js_template if as_template else render_template
render_function = loader.custom_render_js_template if as_template else loader.render_template
html = render_function(template_path, {
'self': self,
'custom_choices': self.custom_choices
})
fragment = Fragment(html)
fragment.add_css(render_template('public/css/questionnaire.css', {
fragment.add_css(loader.render_template('public/css/questionnaire.css', {
'self': self
}))
fragment.add_javascript_url(self.runtime.local_resource_url(self.xblock_container,
......
......@@ -29,7 +29,7 @@ import logging
from xblock.fields import Scope
from .light_children import LightChild, String
from .utils import load_resource, render_template
from .utils import loader
# Globals ###########################################################
......@@ -58,14 +58,14 @@ class MentoringTableBlock(LightChild):
# Load an optional description for the background image, for accessibility
try:
bg_image_description = load_resource('static/text/table-{}.txt'.format(self.type))
bg_image_description = loader.load_unicode('static/text/table-{}.txt'.format(self.type))
except IOError as e:
if e.errno == errno.ENOENT:
bg_image_description = ''
else:
raise
fragment.add_content(render_template('templates/html/mentoring-table.html', {
fragment.add_content(loader.render_template('templates/html/mentoring-table.html', {
'self': self,
'columns_frags': columns_frags,
'header_frags': header_frags,
......@@ -101,7 +101,7 @@ class MentoringTableColumnBlock(LightChild):
fragment, named_children = self.get_children_fragment(
context, view_name='mentoring_table_view',
not_instance_of=MentoringTableColumnHeaderBlock)
fragment.add_content(render_template('templates/html/mentoring-table-column.html', {
fragment.add_content(loader.render_template('templates/html/mentoring-table-column.html', {
'self': self,
'named_children': named_children,
}))
......@@ -114,7 +114,7 @@ class MentoringTableColumnBlock(LightChild):
fragment, named_children = self.get_children_fragment(
context, view_name='mentoring_table_header_view',
instance_of=MentoringTableColumnHeaderBlock)
fragment.add_content(render_template('templates/html/mentoring-table-header.html', {
fragment.add_content(loader.render_template('templates/html/mentoring-table-header.html', {
'self': self,
'named_children': named_children,
}))
......
......@@ -26,7 +26,7 @@
import logging
from .light_children import LightChild, Scope, String
from .utils import render_template
from .utils import loader
# Globals ###########################################################
......@@ -65,7 +65,7 @@ class TipBlock(LightChild):
Returns a fragment containing the formatted tip
"""
fragment, named_children = self.get_children_fragment({})
fragment.add_content(render_template('templates/html/tip.html', {
fragment.add_content(loader.render_template('templates/html/tip.html', {
'self': self,
'named_children': named_children,
}))
......
......@@ -36,27 +36,12 @@ from xblockutils.resources import ResourceLoader
log = logging.getLogger(__name__)
loader = ResourceLoader(__name__)
class MentoringResourceLoader(ResourceLoader):
def custom_render_js_template(self, template_path, context={}):
return self.render_js_template(template_path, 'light-child-template', context)
def load_resource(resource_path):
return loader.load_unicode(resource_path)
def render_template(template_path, context={}):
return loader.render_template(template_path, context)
def render_js_template(template_path, context={}, unique_id='light-child-template'):
return loader.render_js_template(template_path, unique_id, context)
def get_scenarios_from_path(scenarios_path, include_identifier=False):
return loader.load_scenarios_from_path(scenarios_path, include_identifier)
def load_scenarios_from_path(scenarios_path):
return loader.load_scenarios_from_path(scenarios_path, include_identifier=True)
loader = MentoringResourceLoader(__name__)
def list2csv(row):
......
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