Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xblock-utils
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
xblock-utils
Commits
b4f9b511
Commit
b4f9b511
authored
Oct 19, 2015
by
Kelketek
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #30 from edx/augment_nested_blocks
Allow blocks to nest utils-unaware blocks.
parents
588f7fd3
5d4da388
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
3 deletions
+41
-3
tests/integration/test_studio_editable.py
+30
-0
xblockutils/studio_editable.py
+11
-3
No files found.
tests/integration/test_studio_editable.py
View file @
b4f9b511
...
@@ -39,6 +39,17 @@ class EditableXBlock(StudioEditableXBlockMixin, XBlock):
...
@@ -39,6 +39,17 @@ class EditableXBlock(StudioEditableXBlockMixin, XBlock):
validation
.
add
(
ValidationMessage
(
ValidationMessage
.
ERROR
,
u"No swearing allowed"
))
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
):
class
TestEditableXBlock_StudioView
(
StudioEditableBaseTest
):
"""
"""
Test the Studio View created for EditableXBlock
Test the Studio View created for EditableXBlock
...
@@ -368,6 +379,14 @@ class XBlockWithDisabledNested(StudioContainerWithNestedXBlocksMixin, XBlock):
...
@@ -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
):
class
StudioContainerWithNestedXBlocksTest
(
StudioContainerWithNestedXBlocksBaseTest
):
def
setUp
(
self
):
def
setUp
(
self
):
super
(
StudioContainerWithNestedXBlocksTest
,
self
)
.
setUp
()
super
(
StudioContainerWithNestedXBlocksTest
,
self
)
.
setUp
()
...
@@ -452,3 +471,14 @@ class StudioContainerWithNestedXBlocksTest(StudioContainerWithNestedXBlocksBaseT
...
@@ -452,3 +471,14 @@ class StudioContainerWithNestedXBlocksTest(StudioContainerWithNestedXBlocksBaseT
button_editable
,
button_fancy
=
self
.
get_add_buttons
()
button_editable
,
button_fancy
=
self
.
get_add_buttons
()
self
.
_assert_disabled
(
button_editable
,
False
)
self
.
_assert_disabled
(
button_editable
,
False
)
self
.
_assert_disabled
(
button_fancy
,
True
)
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'
)
xblockutils/studio_editable.py
View file @
b4f9b511
...
@@ -335,22 +335,30 @@ class NestedXBlockSpec(object):
...
@@ -335,22 +335,30 @@ class NestedXBlockSpec(object):
Class that allows detailed specification of allowed nested XBlocks. For use with
Class that allows detailed specification of allowed nested XBlocks. For use with
StudioContainerWithNestedXBlocksMixin.allowed_nested_blocks
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
.
_block
=
block
self
.
_single_instance
=
single_instance
self
.
_single_instance
=
single_instance
self
.
_disabled
=
disabled
self
.
_disabled
=
disabled
self
.
_disabled_reason
=
disabled_reason
self
.
_disabled_reason
=
disabled_reason
self
.
_boilerplate
=
boilerplate
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
@property
def
category
(
self
):
def
category
(
self
):
""" Block category - used as a computer-readable name of an XBlock """
""" Block category - used as a computer-readable name of an XBlock """
return
self
.
_block
.
CATEGORY
return
self
.
_
category
or
self
.
_
block
.
CATEGORY
@property
@property
def
label
(
self
):
def
label
(
self
):
""" Block label - used as human-readable name of an XBlock """
""" Block label - used as human-readable name of an XBlock """
return
self
.
_block
.
STUDIO_LABEL
return
self
.
_
label
or
self
.
_
block
.
STUDIO_LABEL
@property
@property
def
single_instance
(
self
):
def
single_instance
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment