File tree Expand file tree Collapse file tree 4 files changed +44
-0
lines changed
openedx/core/lib/xblock_utils Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 11## xss-lint: disable=mako-missing-default
22< %!
33from openedx.core.djangolib.js_utils import dump_js_escaped_json
4+ from django.utils.translation import gettext as _
45%>
6+ % if 'data-is-optional="True"' in data_attributes:
7+ < span class ="optional-completion-banner " style ="display: block; background: #5b5b5b67; padding: 8px; margin-bottom: 8px; "> ${_("Optional 1")}</ span >
8+ % endif
59< div class ="${' '.join(classes) | n, decode.utf8} " ${data_attributes} >
10+
11+ % if 'data-is-optional="True"' in data_attributes:
12+ < span class ="optional-completion-banner " style ="display: block; background: #bc43437f; padding: 8px; margin-bottom: 8px; "> ${_("Optional 2")}</ span >
13+ % endif
14+
615% if js_init_parameters:
716 < script type ="json/xblock-args " class ="xblock-json-init-args ">
817 $ { js_init_parameters | n , dump_js_escaped_json }
918 </ script >
1019% endif
1120 ${content}
1221</ div >
22+
23+ % if 'data-is-optional="True"' in data_attributes:
24+ < span class ="optional-completion-banner " style ="display: block; background: #215b768b; padding: 8px; margin-bottom: 8px; "> ${_("Optional 3")}</ span >
25+ % endif
Original file line number Diff line number Diff line change 2323from web_fragments .fragment import Fragment
2424from xblock .core import XBlock
2525from xblock .exceptions import InvalidScopeError
26+ from xblock .fields import Scope
2627from xblock .scorable import ScorableXBlockMixin
2728
2829from common .djangoapps import static_replace
@@ -141,6 +142,13 @@ def wrap_xblock(
141142 if block .name :
142143 data ['name' ] = block .name
143144
145+ # We check whether the block is explicitly set as optional because this information is already displayed for units
146+ # in the Learning MFE.
147+ has_children = getattr (block , "children" , False )
148+ is_explicitly_optional = block .get_explicitly_set_fields_by_scope (Scope .settings ).get ('optional_completion' , False )
149+ if view != STUDIO_VIEW and not has_children and is_explicitly_optional :
150+ data ['is-optional' ] = getattr (block , 'optional_completion' , False )
151+
144152 template_context = {
145153 'content' : block .display_name if display_name_only else frag .content ,
146154 'classes' : css_classes ,
Original file line number Diff line number Diff line change 4040]
4141XBLOCKS_ASIDES = [
4242 'tagging_aside = cms.lib.xblock.tagging:StructuredTagsAside' ,
43+ 'optional_completion_aside = xmodule.x_module:OptionalCompletionDisplayAside' ,
4344]
4445
4546
Original file line number Diff line number Diff line change @@ -1652,3 +1652,25 @@ def get(self, _key):
16521652
16531653 def set (self , key , value , timeout = None ):
16541654 pass
1655+
1656+
1657+ class OptionalCompletionDisplayAside (XBlockAside ):
1658+ """
1659+ Displays the "Optional" information below each optional individual XBlock.
1660+
1661+ We check whether the block is explicitly set as optional because this information is already displayed for units
1662+ in the Learning MFE.
1663+ """
1664+
1665+ @XBlockAside .aside_for (STUDENT_VIEW )
1666+ def aside_view (self , block , context = None ):
1667+ """The student view for the optional completion aside."""
1668+ has_children = getattr (block , "children" , False )
1669+ is_explicitly_optional = block .get_explicitly_set_fields_by_scope (Scope .settings ).get (
1670+ 'optional_completion' , False
1671+ )
1672+ if has_children or not is_explicitly_optional :
1673+ return Fragment ("" )
1674+ fragment = Fragment (f'<div class="optional-completion-banner">{ _ ("Optional 4" )} </div>' )
1675+ fragment .add_css (".optional-completion-banner { background: #eef; padding: 8px; margin-bottom: 8px; }" )
1676+ return fragment
You can’t perform that action at this time.
0 commit comments