Skip to content

Commit

Permalink
Merge pull request #121 from Code-Institute-Org/fix_studentactivity
Browse files Browse the repository at this point in the history
Fixing lookup of old studentactivity
  • Loading branch information
ray-codeinstitute authored Feb 29, 2024
2 parents fa275b9 + d125ac4 commit 590bae0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lms/djangoapps/ci_program/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,23 @@ def _get_or_infer_block_id(
block_id = activity_log[0].module_state_key.block_id
if block_id == 'course' and course_key:
latest_course_id = course_key.html_id().split(':')[1]
course_xblock = module_tree[latest_course_id]
course_xblock = self._find_course(latest_course_id, module_tree)
children = course_xblock.get('fields', {}).get('children')
if children:
activity_state = json.loads(activity_log[0].state)
section_block = children[activity_state.get('position', 1) - 1]
block_id = section_block[1] if section_block else None
return block_id

def _find_course(self, course_id, module_tree):
if course_id in module_tree:
return module_tree[course_id]
else:
for key in module_tree:
if course_id.startswith(key.rsplit('+', 1)[0]):
return module_tree[key]
return {}

def _read_module_tree_from_mongo(self, user):
if self.course_codes.exists():
aggregate_query = self._create_aggregate_query()
Expand Down

0 comments on commit 590bae0

Please sign in to comment.