Commit cb569289 by Xavier Antoviaque

Fixes TODOs

parent 390e447e
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
import logging import logging
from lxml import etree
from xblock.fragment import Fragment from xblock.fragment import Fragment
from .light_children import LightChild, Scope, String from .light_children import LightChild, Scope, String
...@@ -46,9 +48,9 @@ class HTMLBlock(LightChild): ...@@ -46,9 +48,9 @@ class HTMLBlock(LightChild):
@classmethod @classmethod
def init_block_from_node(cls, block, node, attr): def init_block_from_node(cls, block, node, attr):
block.light_children = [] block.light_children = []
# TODO-LIGHT-CHILDREN: get real value from `node` (lxml) node.tag = 'div'
block.content = '<div>Placeholder HTML content</div>' block.content = etree.tostring(node)
return block return block
......
...@@ -40,13 +40,6 @@ from .utils import XBlockWithChildrenFragmentsMixin ...@@ -40,13 +40,6 @@ from .utils import XBlockWithChildrenFragmentsMixin
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# Functions #########################################################
def node_to_xml(node):
# TODO-LIGHT-CHILDREN
return '<mentoring><html>Hello</html><answer name="test1" /></mentoring>'
# Classes ########################################################### # Classes ###########################################################
class LightChildrenMixin(XBlockWithChildrenFragmentsMixin): class LightChildrenMixin(XBlockWithChildrenFragmentsMixin):
...@@ -58,12 +51,12 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin): ...@@ -58,12 +51,12 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin):
TODO: Replace this once the support for XBlock children has matured TODO: Replace this once the support for XBlock children has matured
by a mixin implementing the following abstractions, used to keep by a mixin implementing the following abstractions, used to keep
code reusable in the XBlocks: code reusable in the XBlocks:
* get_children_objects() * get_children_objects()
* Functionality of XBlockWithChildrenFragmentsMixin * Functionality of XBlockWithChildrenFragmentsMixin
Other changes caused by LightChild use: Other changes caused by LightChild use:
* overrides of `parse_xml()` have been replaced by overrides of * overrides of `parse_xml()` have been replaced by overrides of
`init_block_from_node()` on LightChildren `init_block_from_node()` on LightChildren
* fields on LightChild don't have any persistence * fields on LightChild don't have any persistence
...@@ -73,7 +66,7 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin): ...@@ -73,7 +66,7 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin):
def parse_xml(cls, node, runtime, keys, id_generator): def parse_xml(cls, node, runtime, keys, id_generator):
block = runtime.construct_xblock_from_class(cls, keys) block = runtime.construct_xblock_from_class(cls, keys)
cls.init_block_from_node(block, node, node.items()) cls.init_block_from_node(block, node, node.items())
block.xml_content = getattr(block, 'xml_content', '') or node_to_xml(node) block.xml_content = getattr(block, 'xml_content', '') or etree.tostring(node)
return block return block
@classmethod @classmethod
...@@ -97,6 +90,12 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin): ...@@ -97,6 +90,12 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin):
# Add any children the child may itself have # Add any children the child may itself have
child_class.init_block_from_node(child, xml_child, xml_child.items()) child_class.init_block_from_node(child, xml_child, xml_child.items())
text = xml_child.text
if text:
text = text.strip()
if text:
child.content = text
block.light_children.append(child) block.light_children.append(child)
@classmethod @classmethod
...@@ -162,10 +161,16 @@ class LightChildField(object): ...@@ -162,10 +161,16 @@ class LightChildField(object):
Fake field with no persistence - allows to keep XBlocks fields definitions on LightChild Fake field with no persistence - allows to keep XBlocks fields definitions on LightChild
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
pass self.value = kwargs.get('default', '')
def __nonzero__(self):
return bool(self.value)
class String(LightChildField): class String(LightChildField):
pass def __str__(self):
return self.value
class Boolean(LightChildField): class Boolean(LightChildField):
pass pass
......
...@@ -43,6 +43,7 @@ class MentoringMessageBlock(LightChild): ...@@ -43,6 +43,7 @@ class MentoringMessageBlock(LightChild):
""" """
content = String(help="Message to display upon completion", scope=Scope.content, default="") content = String(help="Message to display upon completion", scope=Scope.content, default="")
type = String(help="Type of message", scope=Scope.content, default="completed") type = String(help="Type of message", scope=Scope.content, default="completed")
has_children = True
def mentoring_view(self, context=None): def mentoring_view(self, context=None):
fragment, named_children = self.get_children_fragment(context, view_name='mentoring_view') fragment, named_children = self.get_children_fragment(context, view_name='mentoring_view')
......
...@@ -81,7 +81,7 @@ class QuizzBlock(LightChild): ...@@ -81,7 +81,7 @@ class QuizzBlock(LightChild):
return block return block
def mentoring_view(self, context=None): def mentoring_view(self, context=None):
if self.type not in ('rating', 'choices'): if str(self.type) not in ('rating', 'choices'):
raise ValueError, u'Invalid value for QuizzBlock.type: `{}`'.format(self.type) raise ValueError, u'Invalid value for QuizzBlock.type: `{}`'.format(self.type)
template_path = 'templates/html/quizz_{}.html'.format(self.type) template_path = 'templates/html/quizz_{}.html'.format(self.type)
......
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
import errno import errno
import logging import logging
from xblock.fields import Scope, String from xblock.fields import Scope
from .light_children import LightChild, XBlockWithLightChildren, String as LightString from .light_children import LightChild, String
from .utils import load_resource, render_template from .utils import load_resource, render_template
...@@ -39,8 +39,7 @@ log = logging.getLogger(__name__) ...@@ -39,8 +39,7 @@ log = logging.getLogger(__name__)
# Classes ########################################################### # Classes ###########################################################
# TODO-LIGHT-CHILDREN: Transform this into always using as LightChildren class MentoringTableBlock(LightChild):
class MentoringTableBlock(XBlockWithLightChildren):
""" """
Table-type display of information from mentoring blocks Table-type display of information from mentoring blocks
...@@ -90,7 +89,7 @@ class MentoringTableColumnBlock(LightChild): ...@@ -90,7 +89,7 @@ class MentoringTableColumnBlock(LightChild):
""" """
Individual column of a mentoring table Individual column of a mentoring table
""" """
header = LightString(help="Header of the column", scope=Scope.content, default=None) header = String(help="Header of the column", scope=Scope.content, default=None)
has_children = True has_children = True
def mentoring_table_view(self, context): def mentoring_table_view(self, context):
...@@ -124,7 +123,7 @@ class MentoringTableColumnHeaderBlock(LightChild): ...@@ -124,7 +123,7 @@ class MentoringTableColumnHeaderBlock(LightChild):
""" """
Header content for a given column Header content for a given column
""" """
content = LightString(help="Body of the header", scope=Scope.content, default='') content = String(help="Body of the header", scope=Scope.content, default='')
def mentoring_table_header_view(self, context): def mentoring_table_header_view(self, context):
fragment = super(MentoringTableColumnHeaderBlock, self).children_view(context) fragment = super(MentoringTableColumnHeaderBlock, self).children_view(context)
......
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