Skip to content

Commit 4a5f209

Browse files
Merge pull request #130 from Code-Institute-Org/fix_resume_programme
Adding more data for current section and unit
2 parents cf34e0a + 8f3ff5c commit 4a5f209

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

lms/djangoapps/ci_program/models.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ def get_program_descriptor(self, request):
200200
latest_block_id = self._get_or_infer_block_id(
201201
activity_log, latest_course_key, module_tree)
202202

203+
section_block_id, unit_block_id = self._find_section_unit(
204+
module_tree, activity_log, latest_block_id)
205+
206+
203207
completed_block_ids = [
204208
ac.module_state_key.block_id for ac in activity_log]
205209
self._add_progress_info_to_module_tree(
@@ -222,6 +226,8 @@ def get_program_descriptor(self, request):
222226
"latest_course_key": latest_course_key,
223227
"completed_percent": completed_percent,
224228
'modules': modules,
229+
'section_block_id': section_block_id,
230+
'unit_block_id': unit_block_id,
225231
}
226232

227233
return program_descriptor
@@ -283,6 +289,30 @@ def _get_latest_course_key(self, activity_log):
283289
else:
284290
return None
285291

292+
def _find_section_unit(self, module_tree, activity_log, xblock_id):
293+
if not activity_log:
294+
return None, None
295+
latest_course_key = self._get_latest_course_key(activity_log)
296+
latest_course_id = latest_course_key.html_id().split(':')[1]
297+
block_id = activity_log[0].module_state_key.block_id
298+
course_xblock = self._find_course(latest_course_id, module_tree)
299+
for section in course_xblock['sections']:
300+
if xblock_id == section['block_id']:
301+
if section['units']:
302+
return section['block_id'], section['units'][0]['block_id']
303+
else:
304+
return section['block_id'], None
305+
for unit in section['units']:
306+
if xblock_id == unit['block_id']:
307+
return section['block_id'], unit['block_id']
308+
for vertical in unit['verticals']:
309+
if xblock_id == vertical['block_id']:
310+
return section['block_id'], unit['block_id']
311+
for xblock in vertical['xblocks']:
312+
if xblock_id == xblock['block_id']:
313+
return section['block_id'], unit['block_id']
314+
return None, None
315+
286316
def _get_or_infer_block_id(
287317
self, activity_log, course_key, module_tree):
288318
''' Resolves the xblock id if the activity log type is "course", and

lms/djangoapps/ci_program/xblock_tree_builder.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,37 @@ def xblock_is_type(self, xblock, block_type, block_id):
3535
return (xblock['block_type'] == block_type and
3636
xblock['block_id'] == block_id)
3737

38+
def collect_xblocks(self, course, section_vertical):
39+
xblocks = []
40+
for xblock_block_type, xblock_block_id in section_vertical:
41+
for xblock in course['blocks']:
42+
if self.xblock_is_type(xblock, xblock_block_type, xblock_block_id):
43+
if self.is_xblock_visible_to_user(xblock):
44+
xblocks.append(xblock)
45+
return xblocks
46+
47+
def collect_verticals(self, course, unit_children):
48+
verticals = []
49+
for vertical_block_type, vertical_block_id in unit_children:
50+
for vertical in course['blocks']:
51+
if self.xblock_is_type(vertical, vertical_block_type, vertical_block_id):
52+
if self.is_xblock_visible_to_user(vertical):
53+
verticals.append(vertical)
54+
vertical['xblocks'] = self.collect_xblocks(
55+
course,
56+
vertical.get('fields', {}).get('children', []))
57+
return verticals
58+
3859
def collect_units(self, course, section_children):
3960
units = []
4061
for unit_block_type, unit_block_id in section_children:
4162
for unit in course['blocks']:
4263
if self.xblock_is_type(unit, unit_block_type, unit_block_id):
4364
if self.is_xblock_visible_to_user(unit):
4465
units.append(unit)
66+
unit['verticals'] = self.collect_verticals(
67+
course,
68+
unit.get('fields', {}).get('children', []))
4569
return units
4670

4771
def collect_sections(self, course, children):

0 commit comments

Comments
 (0)