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-416] add sequence_ids to container response #2498

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ContainerHandlerSerializer(serializers.Serializer):
assets_url = serializers.SerializerMethodField()
unit_block_id = serializers.CharField(source="unit.location.block_id")
subsection_location = serializers.CharField(source="subsection.location")
course_sequence_ids = serializers.ListField(child=serializers.CharField())

def get_assets_url(self, obj):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ def get(self, request: Request, usage_key_string: str):
"assets_url": "/assets/course-v1:edX+DemoX+Demo_Course/",
"unit_block_id": "d6cee45205a449369d7ef8f159b22bdf",
"subsection_location": "block-v1:edX+DemoX+Demo_Course+type@sequential+block@graded_simulations"
"course_sequence_ids": [
"block-v1:edX+DemoX+Demo_Course+type@sequential+block@graded_simulations",
"block-v1:edX+DemoX+Demo_Course+type@sequential+block@something_else",
...
],
}
```
"""
Expand Down
16 changes: 16 additions & 0 deletions cms/djangoapps/contentstore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,20 @@ def ancestor_has_staff_lock(xblock, parent_xblock=None):
return parent_xblock.visible_to_staff_only


def get_sequence_usage_keys(course):
"""
Extracts a list of 'subsections' usage_keys
"""
course_sequence_ids = []
sections = course.get_children()
for section in sections:
subsections = section.get_children()
for subsection in subsections:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use list comprehensions here, everything else is good!

course_sequence_ids.append(str(subsection.location))

return course_sequence_ids


def reverse_url(handler_name, key_name=None, key_value=None, kwargs=None):
"""
Creates the URL for the given handler.
Expand Down Expand Up @@ -1848,6 +1862,7 @@ def get_container_handler_context(request, usage_key, course, xblock): # pylint
)
from openedx.core.djangoapps.content_staging import api as content_staging_api

course_sequence_ids = get_sequence_usage_keys(course)
component_templates = get_component_templates(course)
ancestor_xblocks = []
parent = get_parent_xblock(xblock)
Expand Down Expand Up @@ -1948,6 +1963,7 @@ def get_container_handler_context(request, usage_key, course, xblock): # pylint
# Status of the user's clipboard, exactly as would be returned from the "GET clipboard" REST API.
'user_clipboard': user_clipboard,
'is_fullwidth_content': is_library_xblock,
'course_sequence_ids': course_sequence_ids,
}
return context

Expand Down
Loading