Merge pull request #24193 from edx/ciduarte/AA-181
AA-181: Updating Outline Tab API to include Course Blocks
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
Outline Tab Serializers.
|
||||
"""
|
||||
|
||||
|
||||
from rest_framework import serializers
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
|
||||
class CourseToolSerializer(serializers.Serializer):
|
||||
@@ -21,8 +21,32 @@ class CourseToolSerializer(serializers.Serializer):
|
||||
return request.build_absolute_uri(url)
|
||||
|
||||
|
||||
class CourseBlockSerializer(serializers.Serializer):
|
||||
"""
|
||||
Serializer for Course Block Objects
|
||||
"""
|
||||
blocks = serializers.SerializerMethodField()
|
||||
|
||||
def get_blocks(self, blocks):
|
||||
return {
|
||||
str(block_key): {
|
||||
'id': str(block_key),
|
||||
'type': block_key.category,
|
||||
'display_name': blocks.get_xblock_field(block_key, 'display_name', block_key.category),
|
||||
'lms_web_url': reverse(
|
||||
'jump_to',
|
||||
kwargs={'course_id': str(block_key.course_key), 'location': str(block_key)},
|
||||
request=self.context['request'],
|
||||
),
|
||||
'children': [str(child_key) for child_key in blocks.get_children(block_key)],
|
||||
}
|
||||
for block_key in blocks
|
||||
}
|
||||
|
||||
|
||||
class OutlineTabSerializer(serializers.Serializer):
|
||||
"""
|
||||
Serializer for the Outline Tab
|
||||
"""
|
||||
course_tools = CourseToolSerializer(many=True)
|
||||
course_blocks = CourseBlockSerializer()
|
||||
|
||||
@@ -8,11 +8,17 @@ from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
|
||||
from edx_django_utils import monitoring as monitoring_utils
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from opaque_keys.edx.keys import CourseKey, UsageKey
|
||||
|
||||
from lms.djangoapps.course_api.blocks.transformers.blocks_api import BlocksAPITransformer
|
||||
from lms.djangoapps.course_home_api.outline.v1.serializers import OutlineTabSerializer
|
||||
from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers
|
||||
from openedx.features.course_experience.course_tools import CourseToolsPluginManager
|
||||
|
||||
from lms.djangoapps.course_blocks.api import get_course_blocks
|
||||
import lms.djangoapps.course_blocks.api as course_blocks_api
|
||||
from xmodule.modulestore.django import modulestore
|
||||
|
||||
|
||||
class OutlineTabView(RetrieveAPIView):
|
||||
"""
|
||||
@@ -29,9 +35,21 @@ class OutlineTabView(RetrieveAPIView):
|
||||
Body consists of the following fields:
|
||||
|
||||
course_tools: List of serialized Course Tool objects. Each serialization has the following fields:
|
||||
analytics_id: (str) The unique id given to the tool
|
||||
title: (str) The display title of the tool
|
||||
url: (str) The link to access the tool
|
||||
analytics_id: (str) The unique id given to the tool.
|
||||
title: (str) The display title of the tool.
|
||||
url: (str) The link to access the tool.
|
||||
course_blocks:
|
||||
blocks: List of serialized Course Block objects. Each serialization has the following fields:
|
||||
id: (str) The usage ID of the block.
|
||||
type: (str) The type of block. Possible values the names of any
|
||||
XBlock type in the system, including custom blocks. Examples are
|
||||
course, chapter, sequential, vertical, html, problem, video, and
|
||||
discussion.
|
||||
display_name: (str) The display name of the block.
|
||||
lms_web_url: (str) The URL to the navigational container of the
|
||||
xBlock on the web LMS.
|
||||
children: (list) If the block has child blocks, a list of IDs of
|
||||
the child blocks.
|
||||
|
||||
**Returns**
|
||||
|
||||
@@ -44,17 +62,29 @@ class OutlineTabView(RetrieveAPIView):
|
||||
permission_classes = (IsAuthenticated,)
|
||||
serializer_class = OutlineTabSerializer
|
||||
|
||||
def get(self, request, course_key_string):
|
||||
def get(self, request, *args, **kwargs):
|
||||
course_key_string = kwargs.get('course_key_string')
|
||||
course_key = CourseKey.from_string(course_key_string)
|
||||
course_usage_key = modulestore().make_course_usage_key(course_key)
|
||||
|
||||
# Enable NR tracing for this view based on course
|
||||
monitoring_utils.set_custom_metric('course_id', course_key_string)
|
||||
monitoring_utils.set_custom_metric('user_id', request.user.id)
|
||||
monitoring_utils.set_custom_metric('is_staff', request.user.is_staff)
|
||||
|
||||
course_key = CourseKey.from_string(course_key_string)
|
||||
course_tools = CourseToolsPluginManager.get_enabled_course_tools(request, course_key)
|
||||
|
||||
transformers = BlockStructureTransformers()
|
||||
transformers += course_blocks_api.get_course_block_access_transformers(request.user)
|
||||
transformers += [
|
||||
BlocksAPITransformer(None, None, depth=3),
|
||||
]
|
||||
|
||||
course_blocks = get_course_blocks(request.user, course_usage_key, transformers, include_completion=True)
|
||||
|
||||
data = {
|
||||
'course_tools': course_tools,
|
||||
'course_blocks': course_blocks,
|
||||
}
|
||||
context = self.get_serializer_context()
|
||||
context['course_key'] = course_key
|
||||
|
||||
Reference in New Issue
Block a user