Commit 830e55d3 by Nimisha Asthagiri

fixup! course_api checkpoint

parent 13673dae
......@@ -68,11 +68,11 @@ class BlockListGetForm(Form):
if cleaned_data.get(additional_field):
cleaned_data['requested_fields'].add(additional_field)
# validate and set user
usage_key = self.cleaned_data.get('usage_key')
if not usage_key:
return
# validate and set user
requested_username = cleaned_data.get('user', '')
requesting_user = self.initial['request'].user
......
......@@ -18,7 +18,7 @@ class BlockSerializer(serializers.Serializer):
return self.context['block_structure'].get_xblock_field(block_key, field_name)
def to_native(self, block_key):
# create response data dict for basic fields
data = {
'id': unicode(block_key),
'lms_web_url': reverse(
......@@ -33,6 +33,7 @@ class BlockSerializer(serializers.Serializer):
),
}
# add additional requested fields that are supported by the various transformers
for supported_field in SUPPORTED_FIELDS:
if supported_field.requested_field_name in self.context['requested_fields']:
data[supported_field.requested_field_name] = self._get_field(
......@@ -41,4 +42,7 @@ class BlockSerializer(serializers.Serializer):
supported_field.block_field_name,
)
if 'children' in self.context['requested_fields']:
data['children'] = self.context['block_structure'].get_children(block_key)
return data
......@@ -12,12 +12,6 @@ from .forms import BlockListGetForm
from .serializers import BlockSerializer
# TODO
# user not specified (-> staff)
# children field
# navigation to return descendants
# support hide_from_toc
@view_auth_classes()
class CourseBlocks(DeveloperErrorViewMixin, ListAPIView):
"""
......@@ -46,9 +40,9 @@ class CourseBlocks(DeveloperErrorViewMixin, ListAPIView):
Example: block_counts=video,problem
* fields: (list) Indicates which additional fields to return for each block.
Default is children,graded,format,student_view_multi_device
The following fields are always returned: type, display_name
Example: fields=graded,format,student_view_multi_device
Example: fields=graded,format,student_view_multi_device,children
* depth (integer or all) Indicates how deep to traverse into the blocks hierarchy.
A value of all means the entire hierarchy.
......@@ -73,7 +67,7 @@ class CourseBlocks(DeveloperErrorViewMixin, ListAPIView):
* display_name: (string) The display name of the block.
* children: (list) If the block has child blocks, a list of IDs of the child blocks.
Returned only if the "children" input parameter is True.
Returned only if "children" is included in the "fields" parameter.
* block_counts: (dict) For each block type specified in the block_counts parameter to the endpoint, the
aggregate number of blocks of that type for this block and all of its descendants.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment