Commit b4f9b511 by Kelketek

Merge pull request #30 from edx/augment_nested_blocks

Allow blocks to nest utils-unaware blocks.
parents 588f7fd3 5d4da388
......@@ -39,6 +39,17 @@ class EditableXBlock(StudioEditableXBlockMixin, XBlock):
validation.add(ValidationMessage(ValidationMessage.ERROR, u"No swearing allowed"))
class UnawareXBlock(XBlock):
"""
A naive XBlock for use in tests
"""
color = String(default="red")
def student_view(self, context):
return Fragment()
class TestEditableXBlock_StudioView(StudioEditableBaseTest):
"""
Test the Studio View created for EditableXBlock
......@@ -368,6 +379,14 @@ class XBlockWithDisabledNested(StudioContainerWithNestedXBlocksMixin, XBlock):
]
class XBlockWithOverriddenNested(StudioContainerWithNestedXBlocksMixin, XBlock):
@property
def allowed_nested_blocks(self):
return [
NestedXBlockSpec(UnawareXBlock, category='unaware', label='Unaware Block')
]
class StudioContainerWithNestedXBlocksTest(StudioContainerWithNestedXBlocksBaseTest):
def setUp(self):
super(StudioContainerWithNestedXBlocksTest, self).setUp()
......@@ -452,3 +471,14 @@ class StudioContainerWithNestedXBlocksTest(StudioContainerWithNestedXBlocksBaseT
button_editable, button_fancy = self.get_add_buttons()
self._assert_disabled(button_editable, False)
self._assert_disabled(button_fancy, True)
@XBlock.register_temp_plugin(XBlockWithOverriddenNested, "overrider")
@XBlock.register_temp_plugin(UnawareXBlock, "unaware")
def test_unaware_nested(self):
scenario = textwrap.dedent("""
<overrider />
""")
self.set_up_root_block(scenario, "author_edit_view")
button_unaware = self.get_add_buttons()[0]
self._assert_disabled(button_unaware, False)
self.assertEqual(button_unaware.text, 'Unaware Block')
......@@ -335,22 +335,30 @@ class NestedXBlockSpec(object):
Class that allows detailed specification of allowed nested XBlocks. For use with
StudioContainerWithNestedXBlocksMixin.allowed_nested_blocks
"""
def __init__(self, block, single_instance=False, disabled=False, disabled_reason=None, boilerplate=None):
def __init__(
self, block, single_instance=False, disabled=False, disabled_reason=None, boilerplate=None,
category=None, label=None,
):
self._block = block
self._single_instance = single_instance
self._disabled = disabled
self._disabled_reason = disabled_reason
self._boilerplate = boilerplate
# Some blocks may not be nesting-aware, but can be nested anyway with a bit of help.
# For example, if you wanted to include an XBlock from a different project that didn't
# yet use XBlock utils, you could specify the category and studio label here.
self._category = category
self._label = label
@property
def category(self):
""" Block category - used as a computer-readable name of an XBlock """
return self._block.CATEGORY
return self._category or self._block.CATEGORY
@property
def label(self):
""" Block label - used as human-readable name of an XBlock """
return self._block.STUDIO_LABEL
return self._label or self._block.STUDIO_LABEL
@property
def single_instance(self):
......
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