From 8ea0d75ba2cece0159aa10d3fba01fb86c18e528 Mon Sep 17 00:00:00 2001 From: monteri <36768631+monteri@users.noreply.github.com> Date: Fri, 26 Jan 2024 13:40:29 +0200 Subject: [PATCH] feat: [AXIMST-416] add sequence_ids to container response (#2498) * feat: add sequence_ids to container response * fix: PR comments fix * fix: update --------- Co-authored-by: monteri --- .../rest_api/v1/serializers/vertical_block.py | 1 + .../contentstore/rest_api/v1/views/vertical_block.py | 5 +++++ cms/djangoapps/contentstore/utils.py | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py b/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py index 0900ba39d2b3..6aa1f1af27c0 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py @@ -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): """ diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py b/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py index a11380a08a66..584d21428854 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py @@ -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", + ... + ], } ``` """ diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 748e6a85a0d4..91e4a06693c5 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -632,6 +632,15 @@ 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 + """ + return [str(subsection.location) + for section in course.get_children() + for subsection in section.get_children()] + + def reverse_url(handler_name, key_name=None, key_value=None, kwargs=None): """ Creates the URL for the given handler. @@ -1848,6 +1857,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) @@ -1948,6 +1958,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