Commit cc2026a4 by Xavier Antoviaque

Merge pull request #83 from aboudreault/lightchild-changes

Various changes in LightChildren
parents 0f58a6fc 1707e565
...@@ -56,10 +56,15 @@ class HTMLBlock(LightChild): ...@@ -56,10 +56,15 @@ class HTMLBlock(LightChild):
return block return block
def student_view(self, context=None): def student_view(self, context=None):
return Fragment(u"<script type='text/template' id='{}'>\n{}\n</script>".format( if context.get('as_template', True):
'light-child-template', return Fragment(u"<script type='text/template' id='{}'>\n{}\n</script>".format(
self.content 'light-child-template',
)) self.content
))
# bug? got AssertionError if I don't use unicode here. (assert isinstance(content, unicode))
# Although it is set when constructed?
return Fragment(unicode(self.content))
def mentoring_view(self, context=None): def mentoring_view(self, context=None):
return self.student_view(context) return self.student_view(context)
......
...@@ -210,9 +210,12 @@ class LightChild(Plugin, LightChildrenMixin): ...@@ -210,9 +210,12 @@ class LightChild(Plugin, LightChildrenMixin):
Base class for the light children Base class for the light children
""" """
entry_point = 'xblock.light_children' entry_point = 'xblock.light_children'
block_type = None
def __init__(self, parent): def __init__(self, parent):
self.parent = parent self.parent = parent
self.location = parent.location
self.scope_ids = parent.scope_ids
self.xblock_container = parent.xblock_container self.xblock_container = parent.xblock_container
self._student_data_loaded = False self._student_data_loaded = False
...@@ -313,6 +316,9 @@ class LightChild(Plugin, LightChildrenMixin): ...@@ -313,6 +316,9 @@ class LightChild(Plugin, LightChildrenMixin):
) )
return lightchild_data return lightchild_data
def local_resource_url(self, block, uri):
return self.runtime.local_resource_url(block, uri, block_type=self.block_type)
class LightChildField(object): class LightChildField(object):
""" """
......
...@@ -73,14 +73,17 @@ class QuestionnaireAbstractBlock(LightChild, StepMixin): ...@@ -73,14 +73,17 @@ class QuestionnaireAbstractBlock(LightChild, StepMixin):
return block return block
def mentoring_view(self, context=None): def student_view(self, context=None):
name = self.__class__.__name__ name = self.__class__.__name__
as_template = context.get('as_template', True)
if str(self.type) not in self.valid_types: if str(self.type) not in self.valid_types:
raise ValueError, u'Invalid value for {}.type: `{}`'.format(name, self.type) raise ValueError, u'Invalid value for {}.type: `{}`'.format(name, self.type)
template_path = 'templates/html/{}_{}.html'.format(name.lower(), self.type) template_path = 'templates/html/{}_{}.html'.format(name.lower(), self.type)
html = render_js_template(template_path, {
render_function = render_js_template if as_template else render_template
html = render_function(template_path, {
'self': self, 'self': self,
'custom_choices': self.custom_choices 'custom_choices': self.custom_choices
}) })
...@@ -94,6 +97,9 @@ class QuestionnaireAbstractBlock(LightChild, StepMixin): ...@@ -94,6 +97,9 @@ class QuestionnaireAbstractBlock(LightChild, StepMixin):
fragment.initialize_js(name) fragment.initialize_js(name)
return fragment return fragment
def mentoring_view(self, context=None):
return self.student_view(context)
@property @property
def custom_choices(self): def custom_choices(self):
custom_choices = [] custom_choices = []
......
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