Skip to content

Commit 92ae027

Browse files
committed
fixup! temp: support optional completion for individual XBlocks
1 parent 27f938e commit 92ae027

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

common/templates/xblock_wrapper.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
## xss-lint: disable=mako-missing-default
22
<%!
33
from 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-badge text-uppercase border badge badge-light mb-3">${_("Optional")}</span>
8+
% endif
59
<div class="${' '.join(classes) | n, decode.utf8}" ${data_attributes}>
610
% if js_init_parameters:
711
<script type="json/xblock-args" class="xblock-json-init-args">

openedx/core/lib/xblock_utils/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from web_fragments.fragment import Fragment
2424
from xblock.core import XBlock
2525
from xblock.exceptions import InvalidScopeError
26+
from xblock.fields import Scope
2627
from xblock.scorable import ScorableXBlockMixin
2728

2829
from 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,

0 commit comments

Comments
 (0)