Commit 63f81d8a by Nimisha Asthagiri

fixup! course_api updates from DRF upgrade.

parent 678da3d2
...@@ -21,7 +21,7 @@ class BlockSerializer(serializers.Serializer): ...@@ -21,7 +21,7 @@ class BlockSerializer(serializers.Serializer):
# for example, if student_view_multi_device is false, just don't specify it? # for example, if student_view_multi_device is false, just don't specify it?
return value if (value is not None) else default return value if (value is not None) else default
def to_native(self, block_key): def to_representation(self, block_key):
# create response data dict for basic fields # create response data dict for basic fields
data = { data = {
'id': unicode(block_key), 'id': unicode(block_key),
...@@ -62,7 +62,7 @@ class BlockDictSerializer(serializers.Serializer): ...@@ -62,7 +62,7 @@ class BlockDictSerializer(serializers.Serializer):
Serializer that formats to a dictionary, rather than a list, of blocks Serializer that formats to a dictionary, rather than a list, of blocks
""" """
root = serializers.CharField(source='root_block_key') root = serializers.CharField(source='root_block_key')
blocks = serializers.SerializerMethodField('get_blocks') blocks = serializers.SerializerMethodField()
def get_blocks(self, structure): def get_blocks(self, structure):
""" """
......
...@@ -56,7 +56,7 @@ class BlockNavigationTransformer(BlockStructureTransformer): ...@@ -56,7 +56,7 @@ class BlockNavigationTransformer(BlockStructureTransformer):
# add self to parent's descendants # add self to parent's descendants
for parent_desc_list in parents_descendants_list: for parent_desc_list in parents_descendants_list:
if parent_desc_list is not None: if parent_desc_list is not None:
parent_desc_list.items.append(block_key) parent_desc_list.items.append(unicode(block_key))
if BlockDepthTransformer.get_block_depth(block_structure, block_key) > self.nav_depth: if BlockDepthTransformer.get_block_depth(block_structure, block_key) > self.nav_depth:
children_descendants_list = parents_descendants_list children_descendants_list = parents_descendants_list
......
...@@ -49,7 +49,7 @@ class BlockNavigationTransformerTestCase(TestCase, ChildrenMapTestMixin): ...@@ -49,7 +49,7 @@ class BlockNavigationTransformerTestCase(TestCase, ChildrenMapTestMixin):
for block_key, expected_nav in enumerate(expected_nav_map): for block_key, expected_nav in enumerate(expected_nav_map):
self.assertSetEqual( self.assertSetEqual(
set(expected_nav), set(unicode(block) for block in expected_nav),
set( set(
block_structure.get_transformer_block_data( block_structure.get_transformer_block_data(
block_key, block_key,
...@@ -104,7 +104,7 @@ class BlockNavigationTransformerCourseTestCase(ModuleStoreTestCase): ...@@ -104,7 +104,7 @@ class BlockNavigationTransformerCourseTestCase(ModuleStoreTestCase):
course_key.make_usage_key('vertical', 'vertical_y1a'), course_key.make_usage_key('vertical', 'vertical_y1a'),
course_key.make_usage_key('problem', 'problem_y1a_1'), course_key.make_usage_key('problem', 'problem_y1a_1'),
]: ]:
self.assertIn(block_key, course_descendants) self.assertIn(unicode(block_key), course_descendants)
# chapter_x and its descendants should not be included # chapter_x and its descendants should not be included
for block_key in [ for block_key in [
...@@ -113,4 +113,4 @@ class BlockNavigationTransformerCourseTestCase(ModuleStoreTestCase): ...@@ -113,4 +113,4 @@ class BlockNavigationTransformerCourseTestCase(ModuleStoreTestCase):
course_key.make_usage_key('vertical', 'vertical_x1a'), course_key.make_usage_key('vertical', 'vertical_x1a'),
course_key.make_usage_key('problem', 'problem_x1a_1'), course_key.make_usage_key('problem', 'problem_x1a_1'),
]: ]:
self.assertNotIn(block_key, course_descendants) self.assertNotIn(unicode(block_key), course_descendants)
...@@ -24,10 +24,10 @@ class CourseBlocks(DeveloperErrorViewMixin, ListAPIView): ...@@ -24,10 +24,10 @@ class CourseBlocks(DeveloperErrorViewMixin, ListAPIView):
GET /api/courses/v1/blocks/<root_block_usage_id>/?depth=all GET /api/courses/v1/blocks/<root_block_usage_id>/?depth=all
GET /api/courses/v1/blocks/<usage_id>/? GET /api/courses/v1/blocks/<usage_id>/?
user=anjali, user=anjali,
&fields=graded,format,multi_device, &depth=all,
&requested_fields=graded,format,student_view_multi_device,
&block_counts=video, &block_counts=video,
&student_view_data=video, &student_view_data=video,
&student_view_data.video=mobile_low
**Parameters**: **Parameters**:
...@@ -42,7 +42,7 @@ class CourseBlocks(DeveloperErrorViewMixin, ListAPIView): ...@@ -42,7 +42,7 @@ class CourseBlocks(DeveloperErrorViewMixin, ListAPIView):
* requested_fields: (list) Indicates which additional fields to return for each block. * requested_fields: (list) Indicates which additional fields to return for each block.
The following fields are always returned: type, display_name The following fields are always returned: type, display_name
Example: requested_fields=graded,format,student_view_multi_device,children Example: requested_fields=graded,format,student_view_multi_device
* depth (integer or all) Indicates how deep to traverse into the blocks hierarchy. * depth (integer or all) Indicates how deep to traverse into the blocks hierarchy.
A value of all means the entire hierarchy. A value of all means the entire hierarchy.
...@@ -50,7 +50,11 @@ class CourseBlocks(DeveloperErrorViewMixin, ListAPIView): ...@@ -50,7 +50,11 @@ class CourseBlocks(DeveloperErrorViewMixin, ListAPIView):
Example: depth=all Example: depth=all
NOTE: This parameter is currently not honored or supported. For now, it only implements depth=all. * nav_depth (integer) Indicates how far deep to traverse into the course hierarchy before bundling
all the descendants.
Default is 3 since typical navigational views of the course show a maximum of chapter->sequential->vertical.
Example: nav_depth=3
* return_type (string) Indicates in what data type to return the blocks. * return_type (string) Indicates in what data type to return the blocks.
Default is dict. Supported values are: dict, list Default is dict. Supported values are: dict, list
......
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