Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [AXIMST-676] Extend Sidenav endpoint with additional parameters #2516

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lms/djangoapps/course_home_api/outline/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def get_blocks(self, block): # pylint: disable=missing-function-docstring
description = block['special_exam_info'].get('short_description')
icon = block['special_exam_info'].get('suggested_icon', 'fa-pencil-square-o')

if self.context.get('enable_prerequisite_block_type', False) and block.get('accessible') is False:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question] is the a reason why we use is False instead of == False?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Python, False is a singleton object, meaning there is only one instance of it. Therefore, using is to check if a variable is False is both clearer and more efficient than using ==.

Here's the link to the Python documentation that supports this:
Python Documentation: The Python Language Reference - Boolean Operations

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for clarification!

block_type = 'lock'

serialized = {
block_key: {
'children': [child['id'] for child in children],
Expand All @@ -61,6 +64,9 @@ def get_blocks(self, block): # pylint: disable=missing-function-docstring
'hide_from_toc': block.get('hide_from_toc'),
},
}
if 'special_exam_info' in self.context.get('extra_fields', []) and block.get('special_exam_info'):
serialized[block_key]['special_exam_info'] = block.get('special_exam_info').get('short_description')

for child in children:
serialized.update(self.get_blocks(child))
return serialized
Expand Down
10 changes: 8 additions & 2 deletions lms/djangoapps/course_home_api/outline/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ def test_get_unknown_course(self):
assert response.status_code == 404

@patch.dict('django.conf.settings.FEATURES', {'ENABLE_SPECIAL_EXAMS': True})
def test_proctored_exam(self):
@patch('lms.djangoapps.course_api.blocks.transformers.milestones.get_attempt_status_summary')
def test_proctored_exam(self, mock_summary):
"""
Test that the API returns the correct data for a proctored exam.
"""
Expand Down Expand Up @@ -596,6 +597,10 @@ def test_proctored_exam(self):
sequence.is_proctored_exam = True
update_outline_from_modulestore(course.id)
CourseEnrollment.enroll(self.user, course.id)
mock_summary.return_value = {
'short_description': 'My Exam',
'suggested_icon': 'fa-foo-bar',
}

url = reverse('course-home:course-sidebar-blocks', args=[course.id])
response = self.client.get(url)
Expand All @@ -604,6 +609,7 @@ def test_proctored_exam(self):
exam_data = response.data['blocks'][str(sequence.location)]
assert not exam_data['complete']
assert exam_data['display_name'] == 'Test Proctored Exam'
assert exam_data['special_exam_info'] == 'My Exam'
assert exam_data['due'] is not None

def test_assignment(self):
Expand Down Expand Up @@ -663,7 +669,7 @@ def test_hide_learning_sequences(self):
assert response.status_code == 200

blocks = response.data['blocks']
seq_block_id = next(block_id for block_id, block in blocks.items() if block['type'] == 'sequential')
seq_block_id = next(block_id for block_id, block in blocks.items() if block['type'] in ('sequential', 'lock'))

# With a course outline loaded, the same sequence is removed.
new_learning_seq_outline = CourseOutlineData(
Expand Down
10 changes: 9 additions & 1 deletion lms/djangoapps/course_home_api/outline/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,17 @@ def get(self, request, *args, **kwargs):
seq_data for seq_data in chapter_data['children']
if (seq_data['id'] in available_sequence_ids or seq_data['type'] != 'sequential')
] if 'children' in chapter_data else []
accessible_sequence_ids = {str(usage_key) for usage_key in user_course_outline.accessible_sequences}
for sequence_data in chapter_data['children']:
sequence_data['accessible'] = sequence_data['id'] in accessible_sequence_ids

context = self.get_serializer_context()
context['include_vertical'] = True
context.update({
'include_vertical': True,
'extra_fields': ['special_exam_info'],
'enable_prerequisite_block_type': True,
})

serializer = self.get_serializer_class()(course_blocks, context=context)

return Response(serializer.data)
Expand Down
Loading