refactor: rename get_displayable_items and displayable_items
This commit is contained in:
@@ -912,7 +912,7 @@ def get_current_child(xmodule, min_depth=None, requested_child=None):
|
||||
else:
|
||||
content_children = [
|
||||
child for child in child_modules
|
||||
if child.has_children_at_depth(min_depth - 1) and child.get_display_items()
|
||||
if child.has_children_at_depth(min_depth - 1) and child.get_display_blocks()
|
||||
]
|
||||
return _get_child(content_children) if content_children else None
|
||||
|
||||
@@ -926,7 +926,7 @@ def get_current_child(xmodule, min_depth=None, requested_child=None):
|
||||
return child
|
||||
|
||||
if has_position:
|
||||
children = xmodule.get_display_items()
|
||||
children = xmodule.get_display_blocks()
|
||||
if len(children) > 0:
|
||||
if xmodule.position is not None and not requested_child:
|
||||
pos = int(xmodule.position) - 1 # position is 1-indexed
|
||||
|
||||
@@ -162,7 +162,7 @@ def toc_for_course(user, request, course, active_chapter, active_section, field_
|
||||
return None, None, None
|
||||
|
||||
toc_chapters = []
|
||||
chapters = course_block.get_display_items()
|
||||
chapters = course_block.get_display_blocks()
|
||||
|
||||
# Check for content which needs to be completed
|
||||
# before the rest of the content is made available
|
||||
@@ -190,7 +190,7 @@ def toc_for_course(user, request, course, active_chapter, active_section, field_
|
||||
continue
|
||||
|
||||
sections = []
|
||||
for section in chapter.get_display_items():
|
||||
for section in chapter.get_display_blocks():
|
||||
# skip the section if it is hidden from the user
|
||||
if section.hide_from_toc:
|
||||
continue
|
||||
|
||||
@@ -166,7 +166,7 @@ class CoursesTest(ModuleStoreTestCase):
|
||||
assert get_current_child(mock_xmodule) is None
|
||||
|
||||
mock_xmodule.position = -1
|
||||
mock_xmodule.get_display_items.return_value = ['one', 'two', 'three']
|
||||
mock_xmodule.get_display_blocks.return_value = ['one', 'two', 'three']
|
||||
assert get_current_child(mock_xmodule) == 'one'
|
||||
|
||||
mock_xmodule.position = 2
|
||||
@@ -175,7 +175,7 @@ class CoursesTest(ModuleStoreTestCase):
|
||||
assert get_current_child(mock_xmodule, requested_child='last') == 'three'
|
||||
|
||||
mock_xmodule.position = 3
|
||||
mock_xmodule.get_display_items.return_value = []
|
||||
mock_xmodule.get_display_blocks.return_value = []
|
||||
assert get_current_child(mock_xmodule) is None
|
||||
|
||||
|
||||
|
||||
@@ -491,7 +491,7 @@ class CoursewareIndex(View):
|
||||
exceeds the length of the displayable items, default the position
|
||||
to the first element.
|
||||
"""
|
||||
display_items = self.section.get_display_items()
|
||||
display_items = self.section.get_display_blocks()
|
||||
if not display_items:
|
||||
return
|
||||
if self.section.position > len(display_items):
|
||||
@@ -565,7 +565,7 @@ def save_child_position(seq_block, child_name):
|
||||
"""
|
||||
child_name: url_name of the child
|
||||
"""
|
||||
for position, child in enumerate(seq_block.get_display_items(), start=1):
|
||||
for position, child in enumerate(seq_block.get_display_blocks(), start=1):
|
||||
if child.location.block_id == child_name:
|
||||
# Only save if position changed
|
||||
if position != seq_block.position:
|
||||
|
||||
@@ -819,7 +819,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
|
||||
"""
|
||||
mock_course_block = MagicMock()
|
||||
mock_course_block.position = 3
|
||||
mock_course_block.get_display_items.return_value = []
|
||||
mock_course_block.get_display_blocks.return_value = []
|
||||
assert helpers.get_course_position(mock_course_block) is None
|
||||
|
||||
def test_get_course_position_to_chapter(self):
|
||||
@@ -833,7 +833,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
|
||||
mock_chapter.url_name = 'chapter_url_name'
|
||||
mock_chapter.display_name_with_default = 'Test Chapter Display Name'
|
||||
|
||||
mock_course_block.get_display_items.return_value = [mock_chapter]
|
||||
mock_course_block.get_display_blocks.return_value = [mock_chapter]
|
||||
|
||||
assert helpers.get_course_position(mock_course_block) == {
|
||||
'display_name': 'Test Chapter Display Name',
|
||||
@@ -845,7 +845,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
|
||||
Returns `None` if no section found.
|
||||
"""
|
||||
mock_course_block = MagicMock(id=self.course.id, position=None)
|
||||
mock_course_block.get_display_items.return_value = [MagicMock()]
|
||||
mock_course_block.get_display_blocks.return_value = [MagicMock()]
|
||||
assert helpers.get_course_position(mock_course_block) is None
|
||||
|
||||
def test_get_course_position_to_section(self):
|
||||
@@ -857,14 +857,14 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
|
||||
|
||||
mock_chapter = MagicMock()
|
||||
mock_chapter.url_name = 'chapter_url_name'
|
||||
mock_course_block.get_display_items.return_value = [mock_chapter]
|
||||
mock_course_block.get_display_blocks.return_value = [mock_chapter]
|
||||
|
||||
mock_section = MagicMock()
|
||||
mock_section.url_name = 'section_url_name'
|
||||
mock_section.display_name_with_default = 'Test Section Display Name'
|
||||
|
||||
mock_chapter.get_display_items.return_value = [mock_section]
|
||||
mock_section.get_display_items.return_value = [MagicMock()]
|
||||
mock_chapter.get_display_blocks.return_value = [mock_section]
|
||||
mock_section.get_display_blocks.return_value = [MagicMock()]
|
||||
|
||||
assert helpers.get_course_position(mock_course_block) == {
|
||||
'display_name': 'Test Section Display Name',
|
||||
|
||||
@@ -395,16 +395,16 @@ class XBlockShim:
|
||||
"""
|
||||
return False
|
||||
|
||||
def get_display_items(self):
|
||||
def get_display_blocks(self):
|
||||
"""
|
||||
Returns a list of descendent XBlock instances that will display
|
||||
immediately inside this module.
|
||||
"""
|
||||
warnings.warn("get_display_items() is deprecated.", DeprecationWarning, stacklevel=2)
|
||||
items = []
|
||||
warnings.warn("get_display_blocks() is deprecated.", DeprecationWarning, stacklevel=2)
|
||||
blocks = []
|
||||
for child in self.get_children():
|
||||
items.extend(child.displayable_items())
|
||||
return items
|
||||
blocks.extend(child.displayable_blocks())
|
||||
return blocks
|
||||
|
||||
def displayable_items(self):
|
||||
"""
|
||||
|
||||
@@ -57,7 +57,7 @@ class PersonalizedLearnerScheduleCallToAction:
|
||||
elif category == self.VERTICAL_BANNER and not completed and missed_deadlines:
|
||||
# xblock is a vertical, so we'll check all the problems inside it. If there are any that will show a
|
||||
# a "shift dates" CTA under CAPA_SUBMIT_DISABLED, then we'll also show the same CTA as a vertical banner.
|
||||
if any(self._is_block_shiftable(item, category) for item in xblock.get_display_items()):
|
||||
if any(self._is_block_shiftable(item, category) for item in xblock.get_display_blocks()):
|
||||
ctas.append(self._make_reset_deadlines_cta(xblock, category, is_learning_mfe))
|
||||
|
||||
return ctas
|
||||
|
||||
@@ -287,7 +287,7 @@ class ConditionalBlock(
|
||||
html = self.runtime.service(self, 'mako').render_template('conditional_block.html', context)
|
||||
return json.dumps({'fragments': [{'content': html}], 'message': bool(self.conditional_message)})
|
||||
|
||||
fragments = [child.render(STUDENT_VIEW).to_dict() for child in self.get_display_items()]
|
||||
fragments = [child.render(STUDENT_VIEW).to_dict() for child in self.get_display_blocks()]
|
||||
|
||||
return json.dumps({'fragments': fragments})
|
||||
|
||||
|
||||
@@ -399,7 +399,7 @@ class LibraryContentBlock(
|
||||
# 500-response.
|
||||
logger.error('Skipping display for child block that is None')
|
||||
continue
|
||||
for displayable in child.displayable_items():
|
||||
for displayable in child.displayable_blocks():
|
||||
rendered_child = displayable.render(STUDENT_VIEW, child_context)
|
||||
fragment.add_fragment_resources(rendered_child)
|
||||
contents.append({
|
||||
|
||||
@@ -379,7 +379,7 @@ class SequenceBlock(
|
||||
prereq_met = True
|
||||
prereq_meta_info = {}
|
||||
banner_text = None
|
||||
display_items = self.get_display_items()
|
||||
display_blocks = self.get_display_blocks()
|
||||
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_items, prereq_met, prereq_meta_info, banner_text, view)
|
||||
meta = self._get_render_metadata(context, display_blocks, 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_items, prereq_met, prereq_meta_info, banner_text=None,
|
||||
def _get_render_metadata(self, context, display_blocks, 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,10 +576,10 @@ class SequenceBlock(
|
||||
'This section is a prerequisite. You must complete this section in order to unlock additional content.'
|
||||
)
|
||||
|
||||
items = self._render_student_view_for_items(context, display_items, fragment, view) if prereq_met else []
|
||||
blocks = self._render_student_view_for_blocks(context, display_blocks, fragment, view) if prereq_met else []
|
||||
|
||||
params = {
|
||||
'items': items,
|
||||
'items': blocks,
|
||||
'element_id': self.location.html_id(),
|
||||
'item_id': str(self.location),
|
||||
'is_time_limited': self.is_time_limited,
|
||||
@@ -606,19 +606,19 @@ class SequenceBlock(
|
||||
content.
|
||||
"""
|
||||
_ = self.runtime.service(self, "i18n").ugettext
|
||||
display_items = self.get_display_items()
|
||||
self._update_position(context, len(display_items))
|
||||
display_blocks = self.get_display_blocks()
|
||||
self._update_position(context, len(display_blocks))
|
||||
|
||||
fragment = Fragment()
|
||||
params = self._get_render_metadata(context, display_items, prereq_met, prereq_meta_info, banner_text, view, fragment) # lint-amnesty, pylint: disable=line-too-long
|
||||
params = self._get_render_metadata(context, display_blocks, 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_items)
|
||||
self._capture_current_unit_metrics(display_items)
|
||||
self._capture_full_seq_item_metrics(display_blocks)
|
||||
self._capture_current_unit_metrics(display_blocks)
|
||||
|
||||
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_items):
|
||||
def _update_position(self, context, number_of_display_blocks):
|
||||
"""
|
||||
Update the user's sequential position given the context and the
|
||||
number_of_display_items
|
||||
number_of_display_blocks
|
||||
"""
|
||||
|
||||
position = context.get('position')
|
||||
@@ -751,25 +751,25 @@ class SequenceBlock(
|
||||
self.position = position
|
||||
|
||||
# If we're rendering this sequence, but no position is set yet,
|
||||
# or exceeds the length of the displayable items,
|
||||
# or exceeds the length of the displayable blocks,
|
||||
# default the position to the first element
|
||||
if context.get('requested_child') == 'first':
|
||||
self.position = 1
|
||||
elif context.get('requested_child') == 'last':
|
||||
self.position = number_of_display_items or 1
|
||||
elif self.position is None or self.position > number_of_display_items:
|
||||
self.position = number_of_display_blocks or 1
|
||||
elif self.position is None or self.position > number_of_display_blocks:
|
||||
self.position = 1
|
||||
|
||||
def _render_student_view_for_items(self, context, display_items, fragment, view=STUDENT_VIEW):
|
||||
def _render_student_view_for_blocks(self, context, display_blocks, fragment, view=STUDENT_VIEW):
|
||||
"""
|
||||
Updates the given fragment with rendered student views of the given
|
||||
display_items. Returns a list of dict objects with information about
|
||||
the given display_items.
|
||||
display_blocks. Returns a list of dict objects with information about
|
||||
the given display_blocks.
|
||||
"""
|
||||
# Avoid circular imports.
|
||||
from openedx.core.lib.xblock_utils import get_icon
|
||||
|
||||
render_items = not context.get('exclude_units', False)
|
||||
render_blocks = not context.get('exclude_units', False)
|
||||
is_user_authenticated = self.is_user_authenticated(context)
|
||||
completion_service = self.runtime.service(self, 'completion')
|
||||
try:
|
||||
@@ -784,9 +784,9 @@ class SequenceBlock(
|
||||
self.display_name_with_default
|
||||
]
|
||||
contents = []
|
||||
for item in display_items:
|
||||
item_type = get_icon(item)
|
||||
usage_id = item.scope_ids.usage_id
|
||||
for block in display_blocks:
|
||||
item_type = get_icon(block)
|
||||
usage_id = block.scope_ids.usage_id
|
||||
|
||||
show_bookmark_button = False
|
||||
is_bookmarked = False
|
||||
@@ -799,10 +799,10 @@ class SequenceBlock(
|
||||
context['bookmarked'] = is_bookmarked
|
||||
context['format'] = getattr(self, 'format', '')
|
||||
|
||||
if render_items:
|
||||
rendered_item = item.render(view, context)
|
||||
fragment.add_fragment_resources(rendered_item)
|
||||
content = rendered_item.content
|
||||
if render_blocks:
|
||||
rendered_block = block.render(view, context)
|
||||
fragment.add_fragment_resources(rendered_block)
|
||||
content = rendered_block.content
|
||||
else:
|
||||
content = ''
|
||||
|
||||
@@ -810,27 +810,27 @@ class SequenceBlock(
|
||||
contains_content_type_gated_content = False
|
||||
if content_type_gating_service:
|
||||
contains_content_type_gated_content = content_type_gating_service.check_children_for_content_type_gating_paywall( # pylint:disable=line-too-long
|
||||
item, self.scope_ids.usage_id.context_key
|
||||
block, self.scope_ids.usage_id.context_key
|
||||
) is not None
|
||||
iteminfo = {
|
||||
block_info = {
|
||||
'content': content,
|
||||
'page_title': getattr(item, 'tooltip_title', ''),
|
||||
'page_title': getattr(block, 'tooltip_title', ''),
|
||||
'type': item_type,
|
||||
'id': str(usage_id),
|
||||
'bookmarked': is_bookmarked,
|
||||
'path': " > ".join(display_names + [item.display_name_with_default]),
|
||||
'graded': item.graded,
|
||||
'path': " > ".join(display_names + [block.display_name_with_default]),
|
||||
'graded': block.graded,
|
||||
'contains_content_type_gated_content': contains_content_type_gated_content,
|
||||
}
|
||||
if not render_items:
|
||||
if not render_blocks:
|
||||
# The item url format can be defined in the template context like so:
|
||||
# context['item_url'] = '/my/item/path/{usage_key}/whatever'
|
||||
iteminfo['href'] = context.get('item_url', '').format(usage_key=usage_id)
|
||||
block_info['href'] = context.get('item_url', '').format(usage_key=usage_id)
|
||||
if is_user_authenticated:
|
||||
if item.location.block_type == 'vertical' and completion_service:
|
||||
iteminfo['complete'] = completion_service.vertical_is_complete(item)
|
||||
if block.location.block_type == 'vertical' and completion_service:
|
||||
block_info['complete'] = completion_service.vertical_is_complete(block)
|
||||
|
||||
contents.append(iteminfo)
|
||||
contents.append(block_info)
|
||||
|
||||
return contents
|
||||
|
||||
@@ -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_items):
|
||||
def _capture_full_seq_item_metrics(self, display_blocks):
|
||||
"""
|
||||
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_items))
|
||||
newrelic.agent.add_custom_parameter('seq.num_units', len(display_blocks))
|
||||
|
||||
# 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_items):
|
||||
def _capture_current_unit_metrics(self, display_blocks):
|
||||
"""
|
||||
Capture information about the current selected Unit within the Sequence.
|
||||
"""
|
||||
@@ -893,13 +893,13 @@ 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_items):
|
||||
if 1 <= self.position <= len(display_blocks):
|
||||
# Basic info about the Unit...
|
||||
current = display_items[self.position - 1]
|
||||
current = display_blocks[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 '')
|
||||
|
||||
# Examining all items inside the Unit (or split_test, conditional, etc.)
|
||||
# Examining all blocks inside the Unit (or split_test, conditional, etc.)
|
||||
child_locs = self._locations_in_subtree(current)
|
||||
newrelic.agent.add_custom_parameter('seq.current.num_items', len(child_locs))
|
||||
curr_block_counts = collections.Counter(usage_key.block_type for usage_key in child_locs)
|
||||
|
||||
@@ -91,7 +91,7 @@ class ConditionalFactory:
|
||||
child_descriptor.visible_to_staff_only = False
|
||||
child_descriptor._xmodule.student_view.return_value = Fragment(content='<p>This is a secret</p>') # lint-amnesty, pylint: disable=protected-access
|
||||
child_descriptor.student_view = child_descriptor._xmodule.student_view # lint-amnesty, pylint: disable=protected-access
|
||||
child_descriptor.displayable_items.return_value = [child_descriptor]
|
||||
child_descriptor.displayable_blocks.return_value = [child_descriptor]
|
||||
child_descriptor.runtime = descriptor_system
|
||||
child_descriptor.xmodule_runtime = get_test_system()
|
||||
child_descriptor.render = lambda view, context=None: descriptor_system.render(child_descriptor, view, context)
|
||||
|
||||
@@ -95,7 +95,7 @@ class VerticalBlock(
|
||||
'edx-platform.username'
|
||||
)
|
||||
|
||||
child_blocks = self.get_display_items() # lint-amnesty, pylint: disable=no-member
|
||||
child_blocks = self.get_display_blocks() # lint-amnesty, pylint: disable=no-member
|
||||
|
||||
child_blocks_to_complete_on_view = set()
|
||||
completion_service = self.runtime.service(self, 'completion')
|
||||
|
||||
@@ -524,18 +524,18 @@ class XModuleMixin(XModuleFields, XBlock):
|
||||
not children of this module"""
|
||||
return []
|
||||
|
||||
def get_display_items(self):
|
||||
def get_display_blocks(self):
|
||||
"""
|
||||
Returns a list of descendent module instances that will display
|
||||
immediately inside this module.
|
||||
"""
|
||||
items = []
|
||||
blocks = []
|
||||
for child in self.get_children():
|
||||
items.extend(child.displayable_items())
|
||||
blocks.extend(child.displayable_blocks())
|
||||
|
||||
return items
|
||||
return blocks
|
||||
|
||||
def displayable_items(self):
|
||||
def displayable_blocks(self):
|
||||
"""
|
||||
Returns list of displayable modules contained by this module. If this
|
||||
module is visible, should return [self].
|
||||
|
||||
Reference in New Issue
Block a user