Skip to content

Commit

Permalink
refactor: replace get_display_blocks with get_children
Browse files Browse the repository at this point in the history
  • Loading branch information
tecoholic authored and Agrendalath committed Jan 23, 2023
1 parent 1a20033 commit b6634a8
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions lms/djangoapps/courseware/courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ def _get_default_child_module(child_modules):
else:
content_children = [
child for child in child_modules
if child.has_children_at_depth(min_depth - 1) and child.get_display_blocks()
if child.has_children_at_depth(min_depth - 1) and child.get_children()
]
return _get_child(content_children) if content_children else None

Expand All @@ -926,7 +926,7 @@ def _get_default_child_module(child_modules):
return child

if has_position:
children = xmodule.get_display_blocks()
children = xmodule.get_children()
if len(children) > 0:
if xmodule.position is not None and not requested_child:
pos = int(xmodule.position) - 1 # position is 1-indexed
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/courseware/module_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_blocks()
chapters = course_block.get_children()

# Check for content which needs to be completed
# before the rest of the content is made available
Expand Down Expand Up @@ -190,7 +190,7 @@ def toc_for_course(user, request, course, active_chapter, active_section, field_
continue

sections = []
for section in chapter.get_display_blocks():
for section in chapter.get_children():
# skip the section if it is hidden from the user
if section.hide_from_toc:
continue
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/courseware/tests/test_courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_get_current_child(self):
assert get_current_child(mock_xmodule) is None

mock_xmodule.position = -1
mock_xmodule.get_display_blocks.return_value = ['one', 'two', 'three']
mock_xmodule.get_children.return_value = ['one', 'two', 'three']
assert get_current_child(mock_xmodule) == 'one'

mock_xmodule.position = 2
Expand All @@ -175,7 +175,7 @@ def test_get_current_child(self):
assert get_current_child(mock_xmodule, requested_child='last') == 'three'

mock_xmodule.position = 3
mock_xmodule.get_display_blocks.return_value = []
mock_xmodule.get_children.return_value = []
assert get_current_child(mock_xmodule) is None


Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/courseware/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def _add_sequence_title_to_context(self, courseware_context):
exceeds the length of the displayable items, default the position
to the first element.
"""
display_items = self.section.get_display_blocks()
display_items = self.section.get_children()
if not display_items:
return
if self.section.position > len(display_items):
Expand Down Expand Up @@ -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_blocks(), start=1):
for position, child in enumerate(seq_block.get_children(), start=1):
if child.location.block_id == child_name:
# Only save if position changed
if position != seq_block.position:
Expand Down
12 changes: 6 additions & 6 deletions lms/djangoapps/edxnotes/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ def test_get_course_position_no_chapter(self):
"""
mock_course_block = MagicMock()
mock_course_block.position = 3
mock_course_block.get_display_blocks.return_value = []
mock_course_block.get_children.return_value = []
assert helpers.get_course_position(mock_course_block) is None

def test_get_course_position_to_chapter(self):
Expand All @@ -833,7 +833,7 @@ def test_get_course_position_to_chapter(self):
mock_chapter.url_name = 'chapter_url_name'
mock_chapter.display_name_with_default = 'Test Chapter Display Name'

mock_course_block.get_display_blocks.return_value = [mock_chapter]
mock_course_block.get_children.return_value = [mock_chapter]

assert helpers.get_course_position(mock_course_block) == {
'display_name': 'Test Chapter Display Name',
Expand All @@ -845,7 +845,7 @@ def test_get_course_position_no_section(self):
Returns `None` if no section found.
"""
mock_course_block = MagicMock(id=self.course.id, position=None)
mock_course_block.get_display_blocks.return_value = [MagicMock()]
mock_course_block.get_children.return_value = [MagicMock()]
assert helpers.get_course_position(mock_course_block) is None

def test_get_course_position_to_section(self):
Expand All @@ -857,14 +857,14 @@ def test_get_course_position_to_section(self):

mock_chapter = MagicMock()
mock_chapter.url_name = 'chapter_url_name'
mock_course_block.get_display_blocks.return_value = [mock_chapter]
mock_course_block.get_children.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_blocks.return_value = [mock_section]
mock_section.get_display_blocks.return_value = [MagicMock()]
mock_chapter.get_children.return_value = [mock_section]
mock_section.get_children.return_value = [MagicMock()]

assert helpers.get_course_position(mock_course_block) == {
'display_name': 'Test Section Display Name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_ctas(self, xblock, category, completed):
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_blocks()):
if any(self._is_block_shiftable(item, category) for item in xblock.get_children()):
ctas.append(self._make_reset_deadlines_cta(xblock, category, is_learning_mfe))

return ctas
Expand Down
2 changes: 1 addition & 1 deletion xmodule/conditional_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def handle_ajax(self, _dispatch, _data):
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_blocks()]
fragments = [child.render(STUDENT_VIEW).to_dict() for child in self.get_children()]

return json.dumps({'fragments': fragments})

Expand Down
4 changes: 2 additions & 2 deletions xmodule/seq_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def get_metadata(self, view=STUDENT_VIEW, context=None):
prereq_met = True
prereq_meta_info = {}
banner_text = None
display_blocks = self.get_display_blocks()
display_blocks = self.get_children()
course = self._get_course()
is_hidden_after_due = False

Expand Down Expand Up @@ -606,7 +606,7 @@ def _student_or_public_view(self, context, prereq_met, prereq_meta_info, banner_
content.
"""
_ = self.runtime.service(self, "i18n").ugettext
display_blocks = self.get_display_blocks()
display_blocks = self.get_children()
self._update_position(context, len(display_blocks))

fragment = Fragment()
Expand Down
2 changes: 1 addition & 1 deletion xmodule/vertical_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _student_or_public_view(self, context, view):
'edx-platform.username'
)

child_blocks = self.get_display_blocks() # lint-amnesty, pylint: disable=no-member
child_blocks = self.get_children() # lint-amnesty, pylint: disable=no-member

child_blocks_to_complete_on_view = set()
completion_service = self.runtime.service(self, 'completion')
Expand Down

0 comments on commit b6634a8

Please sign in to comment.