Commit cb569289 by Xavier Antoviaque

Fixes TODOs

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