Skip to content

Commit

Permalink
Adding more data for current section and unit
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-codeinstitute committed Jan 15, 2025
1 parent e250062 commit 8f3ff5c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lms/djangoapps/ci_program/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ def get_program_descriptor(self, request):
latest_block_id = self._get_or_infer_block_id(
activity_log, latest_course_key, module_tree)

section_block_id, unit_block_id = self._find_section_unit(
module_tree, activity_log, latest_block_id)


completed_block_ids = [
ac.module_state_key.block_id for ac in activity_log]
self._add_progress_info_to_module_tree(
Expand All @@ -222,6 +226,8 @@ def get_program_descriptor(self, request):
"latest_course_key": latest_course_key,
"completed_percent": completed_percent,
'modules': modules,
'section_block_id': section_block_id,
'unit_block_id': unit_block_id,
}

return program_descriptor
Expand Down Expand Up @@ -283,6 +289,30 @@ def _get_latest_course_key(self, activity_log):
else:
return None

def _find_section_unit(self, module_tree, activity_log, xblock_id):
if not activity_log:
return None, None
latest_course_key = self._get_latest_course_key(activity_log)
latest_course_id = latest_course_key.html_id().split(':')[1]
block_id = activity_log[0].module_state_key.block_id
course_xblock = self._find_course(latest_course_id, module_tree)
for section in course_xblock['sections']:
if xblock_id == section['block_id']:
if section['units']:
return section['block_id'], section['units'][0]['block_id']
else:
return section['block_id'], None
for unit in section['units']:
if xblock_id == unit['block_id']:
return section['block_id'], unit['block_id']
for vertical in unit['verticals']:
if xblock_id == vertical['block_id']:
return section['block_id'], unit['block_id']
for xblock in vertical['xblocks']:
if xblock_id == xblock['block_id']:
return section['block_id'], unit['block_id']
return None, None

def _get_or_infer_block_id(
self, activity_log, course_key, module_tree):
''' Resolves the xblock id if the activity log type is "course", and
Expand Down
24 changes: 24 additions & 0 deletions lms/djangoapps/ci_program/xblock_tree_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,37 @@ def xblock_is_type(self, xblock, block_type, block_id):
return (xblock['block_type'] == block_type and
xblock['block_id'] == block_id)

def collect_xblocks(self, course, section_vertical):
xblocks = []
for xblock_block_type, xblock_block_id in section_vertical:
for xblock in course['blocks']:
if self.xblock_is_type(xblock, xblock_block_type, xblock_block_id):
if self.is_xblock_visible_to_user(xblock):
xblocks.append(xblock)
return xblocks

def collect_verticals(self, course, unit_children):
verticals = []
for vertical_block_type, vertical_block_id in unit_children:
for vertical in course['blocks']:
if self.xblock_is_type(vertical, vertical_block_type, vertical_block_id):
if self.is_xblock_visible_to_user(vertical):
verticals.append(vertical)
vertical['xblocks'] = self.collect_xblocks(
course,
vertical.get('fields', {}).get('children', []))
return verticals

def collect_units(self, course, section_children):
units = []
for unit_block_type, unit_block_id in section_children:
for unit in course['blocks']:
if self.xblock_is_type(unit, unit_block_type, unit_block_id):
if self.is_xblock_visible_to_user(unit):
units.append(unit)
unit['verticals'] = self.collect_verticals(
course,
unit.get('fields', {}).get('children', []))
return units

def collect_sections(self, course, children):
Expand Down

0 comments on commit 8f3ff5c

Please sign in to comment.