Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
2f2c6fc5
Commit
2f2c6fc5
authored
Mar 10, 2016
by
lenacom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed comments
parent
23b61749
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
19 deletions
+18
-19
lms/djangoapps/course_api/blocks/api.py
+4
-4
lms/djangoapps/course_api/blocks/forms.py
+2
-2
lms/djangoapps/course_api/blocks/tests/test_api.py
+5
-6
lms/djangoapps/course_api/blocks/tests/test_forms.py
+1
-1
lms/djangoapps/course_api/blocks/views.py
+6
-6
No files found.
lms/djangoapps/course_api/blocks/api.py
View file @
2f2c6fc5
...
@@ -20,7 +20,7 @@ def get_blocks(
...
@@ -20,7 +20,7 @@ def get_blocks(
block_counts
=
None
,
block_counts
=
None
,
student_view_data
=
None
,
student_view_data
=
None
,
return_type
=
'dict'
,
return_type
=
'dict'
,
block_type_filter
=
None
,
block_type
s
_filter
=
None
,
):
):
"""
"""
Return a serialized representation of the course blocks.
Return a serialized representation of the course blocks.
...
@@ -45,7 +45,7 @@ def get_blocks(
...
@@ -45,7 +45,7 @@ def get_blocks(
which blocks to return their student_view_data.
which blocks to return their student_view_data.
return_type (string): Possible values are 'dict' or 'list'. Indicates
return_type (string): Possible values are 'dict' or 'list'. Indicates
the format for returning the blocks.
the format for returning the blocks.
block_type_filter (list): Optional list of block type names used to filter
block_type
s
_filter (list): Optional list of block type names used to filter
the final result of returned blocks.
the final result of returned blocks.
"""
"""
# create ordered list of transformers, adding BlocksAPITransformer at end.
# create ordered list of transformers, adding BlocksAPITransformer at end.
...
@@ -65,11 +65,11 @@ def get_blocks(
...
@@ -65,11 +65,11 @@ def get_blocks(
blocks
=
get_course_blocks
(
user
,
usage_key
,
transformers
)
blocks
=
get_course_blocks
(
user
,
usage_key
,
transformers
)
# filter blocks by types
# filter blocks by types
if
block_type_filter
:
if
block_type
s
_filter
:
block_keys_to_remove
=
[]
block_keys_to_remove
=
[]
for
block_key
in
blocks
:
for
block_key
in
blocks
:
block_type
=
blocks
.
get_xblock_field
(
block_key
,
'category'
)
block_type
=
blocks
.
get_xblock_field
(
block_key
,
'category'
)
if
block_type
not
in
block_type_filter
:
if
block_type
not
in
block_type
s
_filter
:
block_keys_to_remove
.
append
(
block_key
)
block_keys_to_remove
.
append
(
block_key
)
for
block_key
in
block_keys_to_remove
:
for
block_key
in
block_keys_to_remove
:
blocks
.
remove_block
(
block_key
,
keep_descendants
=
True
)
blocks
.
remove_block
(
block_key
,
keep_descendants
=
True
)
...
...
lms/djangoapps/course_api/blocks/forms.py
View file @
2f2c6fc5
...
@@ -31,7 +31,7 @@ class BlockListGetForm(Form):
...
@@ -31,7 +31,7 @@ class BlockListGetForm(Form):
student_view_data
=
MultiValueField
(
required
=
False
)
student_view_data
=
MultiValueField
(
required
=
False
)
usage_key
=
CharField
(
required
=
True
)
usage_key
=
CharField
(
required
=
True
)
username
=
CharField
(
required
=
False
)
username
=
CharField
(
required
=
False
)
block_type_filter
=
MultiValueField
(
required
=
False
)
block_type
s
_filter
=
MultiValueField
(
required
=
False
)
def
clean_depth
(
self
):
def
clean_depth
(
self
):
"""
"""
...
@@ -89,7 +89,7 @@ class BlockListGetForm(Form):
...
@@ -89,7 +89,7 @@ class BlockListGetForm(Form):
'student_view_data'
,
'student_view_data'
,
'block_counts'
,
'block_counts'
,
'nav_depth'
,
'nav_depth'
,
'block_type_filter'
,
'block_type
s
_filter'
,
]
]
for
additional_field
in
additional_requested_fields
:
for
additional_field
in
additional_requested_fields
:
field_value
=
cleaned_data
.
get
(
additional_field
)
field_value
=
cleaned_data
.
get
(
additional_field
)
...
...
lms/djangoapps/course_api/blocks/tests/test_api.py
View file @
2f2c6fc5
...
@@ -12,8 +12,6 @@ from xmodule.modulestore.tests.factories import SampleCourseFactory
...
@@ -12,8 +12,6 @@ from xmodule.modulestore.tests.factories import SampleCourseFactory
from
..api
import
get_blocks
from
..api
import
get_blocks
import
re
class
TestGetBlocks
(
EnableTransformerRegistryMixin
,
SharedModuleStoreTestCase
):
class
TestGetBlocks
(
EnableTransformerRegistryMixin
,
SharedModuleStoreTestCase
):
"""
"""
...
@@ -84,16 +82,17 @@ class TestGetBlocks(EnableTransformerRegistryMixin, SharedModuleStoreTestCase):
...
@@ -84,16 +82,17 @@ class TestGetBlocks(EnableTransformerRegistryMixin, SharedModuleStoreTestCase):
sequential_block
=
self
.
store
.
get_item
(
self
.
course
.
id
.
make_usage_key
(
'sequential'
,
'sequential_y1'
))
sequential_block
=
self
.
store
.
get_item
(
self
.
course
.
id
.
make_usage_key
(
'sequential'
,
'sequential_y1'
))
# not filtered blocks
# not filtered blocks
blocks
=
get_blocks
(
self
.
request
,
sequential_block
.
location
,
self
.
user
)
blocks
=
get_blocks
(
self
.
request
,
sequential_block
.
location
,
self
.
user
,
requested_fields
=
[
'type'
]
)
self
.
assertEquals
(
len
(
blocks
[
'blocks'
]),
5
)
self
.
assertEquals
(
len
(
blocks
[
'blocks'
]),
5
)
found_not_problem
=
False
found_not_problem
=
False
for
key
in
blocks
[
'blocks'
]:
for
key
in
blocks
[
'blocks'
]:
if
not
re
.
search
(
r'/problem/'
,
key
)
:
if
blocks
[
'blocks'
][
key
][
'type'
]
!=
'problem'
:
found_not_problem
=
True
found_not_problem
=
True
self
.
assertTrue
(
found_not_problem
)
self
.
assertTrue
(
found_not_problem
)
# filtered blocks
# filtered blocks
blocks
=
get_blocks
(
self
.
request
,
sequential_block
.
location
,
self
.
user
,
block_type_filter
=
[
'problem'
])
blocks
=
get_blocks
(
self
.
request
,
sequential_block
.
location
,
self
.
user
,
block_types_filter
=
[
'problem'
],
requested_fields
=
[
'type'
])
self
.
assertEquals
(
len
(
blocks
[
'blocks'
]),
3
)
self
.
assertEquals
(
len
(
blocks
[
'blocks'
]),
3
)
for
key
in
blocks
[
'blocks'
]:
for
key
in
blocks
[
'blocks'
]:
self
.
assert
True
(
re
.
search
(
r'/problem/'
,
key
)
)
self
.
assert
Equal
(
blocks
[
'blocks'
][
key
][
'type'
],
'problem'
)
lms/djangoapps/course_api/blocks/tests/test_forms.py
View file @
2f2c6fc5
...
@@ -60,7 +60,7 @@ class TestBlockListGetForm(EnableTransformerRegistryMixin, FormTestMixin, Shared
...
@@ -60,7 +60,7 @@ class TestBlockListGetForm(EnableTransformerRegistryMixin, FormTestMixin, Shared
'usage_key'
:
usage_key
,
'usage_key'
:
usage_key
,
'username'
:
self
.
student
.
username
,
'username'
:
self
.
student
.
username
,
'user'
:
self
.
student
,
'user'
:
self
.
student
,
'block_type_filter'
:
set
(),
'block_type
s
_filter'
:
set
(),
}
}
def
assert_raises_permission_denied
(
self
):
def
assert_raises_permission_denied
(
self
):
...
...
lms/djangoapps/course_api/blocks/views.py
View file @
2f2c6fc5
...
@@ -33,7 +33,7 @@ class BlocksView(DeveloperErrorViewMixin, ListAPIView):
...
@@ -33,7 +33,7 @@ class BlocksView(DeveloperErrorViewMixin, ListAPIView):
&requested_fields=graded,format,student_view_multi_device,lti_url
&requested_fields=graded,format,student_view_multi_device,lti_url
&block_counts=video
&block_counts=video
&student_view_data=video
&student_view_data=video
&block_type_filter=problem,html
&block_type
s
_filter=problem,html
**Parameters**:
**Parameters**:
...
@@ -86,11 +86,11 @@ class BlocksView(DeveloperErrorViewMixin, ListAPIView):
...
@@ -86,11 +86,11 @@ class BlocksView(DeveloperErrorViewMixin, ListAPIView):
Example: return_type=dict
Example: return_type=dict
* block_type_filter: (list) Requested types of blocks used to filter the final result
* block_type
s
_filter: (list) Requested types of blocks used to filter the final result
of returned blocks. Possible values include sequential,vertical, html, problem,
of returned blocks. Possible values include sequential,
vertical, html, problem,
video, and discussion.
video, and discussion.
Example: block_type_filter=vertical,html
Example: block_type
s
_filter=vertical,html
**Response Values**
**Response Values**
...
@@ -186,7 +186,7 @@ class BlocksView(DeveloperErrorViewMixin, ListAPIView):
...
@@ -186,7 +186,7 @@ class BlocksView(DeveloperErrorViewMixin, ListAPIView):
params
.
cleaned_data
.
get
(
'block_counts'
,
[]),
params
.
cleaned_data
.
get
(
'block_counts'
,
[]),
params
.
cleaned_data
.
get
(
'student_view_data'
,
[]),
params
.
cleaned_data
.
get
(
'student_view_data'
,
[]),
params
.
cleaned_data
[
'return_type'
],
params
.
cleaned_data
[
'return_type'
],
params
.
cleaned_data
.
get
(
'block_type_filter'
,
None
),
params
.
cleaned_data
.
get
(
'block_type
s
_filter'
,
None
),
)
)
)
)
except
ItemNotFoundError
as
exception
:
except
ItemNotFoundError
as
exception
:
...
@@ -210,7 +210,7 @@ class BlocksInCourseView(BlocksView):
...
@@ -210,7 +210,7 @@ class BlocksInCourseView(BlocksView):
&requested_fields=graded,format,student_view_multi_device,lti_url
&requested_fields=graded,format,student_view_multi_device,lti_url
&block_counts=video
&block_counts=video
&student_view_data=video
&student_view_data=video
&block_type_filter=problem,html
&block_type
s
_filter=problem,html
**Parameters**:
**Parameters**:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment