refactor: rename display_blocks to children in seq_block

This commit is contained in:
Arunmozhi
2022-12-23 11:23:13 +05:30
committed by Agrendalath
parent 7c621e6ad2
commit 41e2f25d8f

View File

@@ -379,7 +379,7 @@ class SequenceBlock(
prereq_met = True
prereq_meta_info = {}
banner_text = None
display_blocks = self.get_children()
children = self.get_children()
course = self._get_course()
is_hidden_after_due = False
@@ -399,7 +399,7 @@ class SequenceBlock(
else:
is_hidden_after_due = True
meta = self._get_render_metadata(context, display_blocks, prereq_met, prereq_meta_info, banner_text, view)
meta = self._get_render_metadata(context, children, prereq_met, prereq_meta_info, banner_text, view)
meta['display_name'] = self.display_name_with_default
meta['format'] = getattr(self, 'format', '')
meta['is_hidden_after_due'] = is_hidden_after_due
@@ -567,7 +567,7 @@ class SequenceBlock(
# NOTE (CCB): We default to true to maintain the behavior in place prior to allowing anonymous access access.
return context.get('user_authenticated', True)
def _get_render_metadata(self, context, display_blocks, prereq_met, prereq_meta_info, banner_text=None,
def _get_render_metadata(self, context, children, prereq_met, prereq_meta_info, banner_text=None,
view=STUDENT_VIEW, fragment=None):
"""Returns a dictionary of sequence metadata, used by render methods and for the courseware API"""
if prereq_met and not self._is_gate_fulfilled():
@@ -576,7 +576,7 @@ class SequenceBlock(
'This section is a prerequisite. You must complete this section in order to unlock additional content.'
)
blocks = self._render_student_view_for_blocks(context, display_blocks, fragment, view) if prereq_met else []
blocks = self._render_student_view_for_blocks(context, children, fragment, view) if prereq_met else []
params = {
'items': blocks,
@@ -606,19 +606,19 @@ class SequenceBlock(
content.
"""
_ = self.runtime.service(self, "i18n").ugettext
display_blocks = self.get_children()
self._update_position(context, len(display_blocks))
children = self.get_children()
self._update_position(context, len(children))
fragment = Fragment()
params = self._get_render_metadata(context, display_blocks, prereq_met, prereq_meta_info, banner_text, view, fragment) # lint-amnesty, pylint: disable=line-too-long
params = self._get_render_metadata(context, children, prereq_met, prereq_meta_info, banner_text, view, fragment) # lint-amnesty, pylint: disable=line-too-long
if SHOW_PROGRESS_BAR.is_enabled() and getattr(settings, 'COMPLETION_AGGREGATOR_URL', ''):
parent_block_id = self.get_parent().scope_ids.usage_id.block_id
params['chapter_completion_aggregator_url'] = '/'.join(
[settings.COMPLETION_AGGREGATOR_URL, str(self.scope_ids.usage_id.context_key), parent_block_id]) + '/'
fragment.add_content(self.runtime.service(self, 'mako').render_template("seq_block.html", params))
self._capture_full_seq_item_metrics(display_blocks)
self._capture_current_unit_metrics(display_blocks)
self._capture_full_seq_item_metrics(children)
self._capture_current_unit_metrics(children)
add_webpack_to_fragment(fragment, 'SequenceBlockPreview')
shim_xmodule_js(fragment, 'Sequence')
@@ -740,10 +740,10 @@ class SequenceBlock(
return True, {}
def _update_position(self, context, number_of_display_blocks):
def _update_position(self, context, number_of_children):
"""
Update the user's sequential position given the context and the
number_of_display_blocks
number_of_children
"""
position = context.get('position')
@@ -756,15 +756,15 @@ class SequenceBlock(
if context.get('requested_child') == 'first':
self.position = 1
elif context.get('requested_child') == 'last':
self.position = number_of_display_blocks or 1
elif self.position is None or self.position > number_of_display_blocks:
self.position = number_of_children or 1
elif self.position is None or self.position > number_of_children:
self.position = 1
def _render_student_view_for_blocks(self, context, display_blocks, fragment, view=STUDENT_VIEW):
def _render_student_view_for_blocks(self, context, children, fragment, view=STUDENT_VIEW):
"""
Updates the given fragment with rendered student views of the given
display_blocks. Returns a list of dict objects with information about
the given display_blocks.
children. Returns a list of dict objects with information about
the given children.
"""
# Avoid circular imports.
from openedx.core.lib.xblock_utils import get_icon
@@ -784,7 +784,7 @@ class SequenceBlock(
self.display_name_with_default
]
contents = []
for block in display_blocks:
for block in children:
item_type = get_icon(block)
usage_id = block.scope_ids.usage_id
@@ -862,7 +862,7 @@ class SequenceBlock(
newrelic.agent.add_custom_parameter('seq.position', self.position)
newrelic.agent.add_custom_parameter('seq.is_time_limited', self.is_time_limited)
def _capture_full_seq_item_metrics(self, display_blocks):
def _capture_full_seq_item_metrics(self, children):
"""
Capture information about the number and types of XBlock content in
the sequence as a whole. We send this information to New Relic so that
@@ -872,7 +872,7 @@ class SequenceBlock(
return
# Basic count of the number of Units (a.k.a. VerticalBlocks) we have in
# this learning sequence
newrelic.agent.add_custom_parameter('seq.num_units', len(display_blocks))
newrelic.agent.add_custom_parameter('seq.num_units', len(children))
# Count of all modules (leaf nodes) in this sequence (e.g. videos,
# problems, etc.) The units (verticals) themselves are not counted.
@@ -884,7 +884,7 @@ class SequenceBlock(
for block_type, count in block_counts.items():
newrelic.agent.add_custom_parameter(f'seq.block_counts.{block_type}', count)
def _capture_current_unit_metrics(self, display_blocks):
def _capture_current_unit_metrics(self, children):
"""
Capture information about the current selected Unit within the Sequence.
"""
@@ -893,9 +893,9 @@ class SequenceBlock(
# Positions are stored with indexing starting at 1. If we get into a
# weird state where the saved position is out of bounds (e.g. the
# content was changed), avoid going into any details about this unit.
if 1 <= self.position <= len(display_blocks):
if 1 <= self.position <= len(children):
# Basic info about the Unit...
current = display_blocks[self.position - 1]
current = children[self.position - 1]
newrelic.agent.add_custom_parameter('seq.current.block_id', str(current.location))
newrelic.agent.add_custom_parameter('seq.current.display_name', current.display_name or '')