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
a2c044b8
Commit
a2c044b8
authored
Apr 22, 2014
by
Chris Dodge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create optimized course tree query API endpoint
parent
b87f54a6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
1 deletions
+66
-1
lms/djangoapps/api_manager/courses_urls.py
+1
-0
lms/djangoapps/api_manager/courses_views.py
+35
-1
lms/djangoapps/api_manager/tests/test_courses_views.py
+30
-0
No files found.
lms/djangoapps/api_manager/courses_urls.py
View file @
a2c044b8
...
@@ -17,5 +17,6 @@ urlpatterns = patterns(
...
@@ -17,5 +17,6 @@ urlpatterns = patterns(
url
(
r'^(?P<course_id>[^/]+/[^/]+/[^/]+)/static_tabs/(?P<tab_id>[a-zA-Z0-9/_:]+)$'
,
'static_tab_detail'
),
url
(
r'^(?P<course_id>[^/]+/[^/]+/[^/]+)/static_tabs/(?P<tab_id>[a-zA-Z0-9/_:]+)$'
,
'static_tab_detail'
),
url
(
r'^(?P<course_id>[^/]+/[^/]+/[^/]+)/static_tabs$'
,
'static_tabs_list'
),
url
(
r'^(?P<course_id>[^/]+/[^/]+/[^/]+)/static_tabs$'
,
'static_tabs_list'
),
url
(
r'^(?P<course_id>[^/]+/[^/]+/[^/]+)/users$'
,
'course_users_list'
),
url
(
r'^(?P<course_id>[^/]+/[^/]+/[^/]+)/users$'
,
'course_users_list'
),
url
(
r'^(?P<course_id>[^/]+/[^/]+/[^/]+)/tree/(?P<depth>[0-9]+)$'
,
'course_tree'
),
url
(
r'^(?P<course_id>[^/]+/[^/]+/[^/]+)$'
,
'courses_detail'
),
url
(
r'^(?P<course_id>[^/]+/[^/]+/[^/]+)$'
,
'courses_detail'
),
)
)
lms/djangoapps/api_manager/courses_views.py
View file @
a2c044b8
...
@@ -16,7 +16,7 @@ from api_manager.models import CourseGroupRelationship
...
@@ -16,7 +16,7 @@ from api_manager.models import CourseGroupRelationship
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore
import
Location
,
InvalidLocationError
from
xmodule.modulestore
import
Location
,
InvalidLocationError
from
courseware.courses
import
get_course_about_section
,
get_course_info_section
from
courseware.courses
import
get_course_about_section
,
get_course_info_section
,
get_course_by_id
from
courseware.views
import
get_static_tab_contents
from
courseware.views
import
get_static_tab_contents
from
student.models
import
CourseEnrollment
,
CourseEnrollmentAllowed
from
student.models
import
CourseEnrollment
,
CourseEnrollmentAllowed
...
@@ -226,6 +226,40 @@ def courses_detail(request, course_id):
...
@@ -226,6 +226,40 @@ def courses_detail(request, course_id):
return
Response
(
response_data
,
status
=
status_code
)
return
Response
(
response_data
,
status
=
status_code
)
@api_view
([
'GET'
])
@permission_classes
((
ApiKeyHeaderPermission
,))
def
course_tree
(
request
,
course_id
,
depth
):
"""
GET retrieves an existing course from the system and returns summary information about the submodules
to the specified depth
"""
response_data
=
{}
depth_int
=
int
(
depth
)
# note, passing in depth=N optimizes the number of round trips to the database
course_descriptor
=
get_course_by_id
(
course_id
,
depth
=
depth_int
)
if
not
course_descriptor
:
return
Response
({},
status
.
HTTP_404_NOT_FOUND
)
def
_serialize_node_with_children
(
descriptor
,
depth
):
data
=
_serialize_module
(
request
,
course_descriptor
.
id
,
descriptor
)
if
depth
>
0
:
data
[
'modules'
]
=
[]
for
child
in
descriptor
.
get_children
():
data
[
'modules'
]
.
append
(
_serialize_node_with_children
(
child
,
depth
-
1
))
return
data
response_data
=
_serialize_node_with_children
(
course_descriptor
,
depth_int
)
return
Response
(
response_data
)
@api_view
([
'POST'
])
@api_view
([
'POST'
])
@permission_classes
((
ApiKeyHeaderPermission
,))
@permission_classes
((
ApiKeyHeaderPermission
,))
def
courses_groups_list
(
request
,
course_id
):
def
courses_groups_list
(
request
,
course_id
):
...
...
lms/djangoapps/api_manager/tests/test_courses_views.py
View file @
a2c044b8
...
@@ -170,6 +170,36 @@ class CoursesApiTests(TestCase):
...
@@ -170,6 +170,36 @@ class CoursesApiTests(TestCase):
response
=
self
.
do_get
(
test_uri
)
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_course_tree_get
(
self
):
# query the course tree to quickly get naviation information
test_uri
=
self
.
base_courses_uri
+
'/'
+
self
.
test_course_id
+
'/tree/2'
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertGreater
(
len
(
response
.
data
),
0
)
self
.
assertEqual
(
response
.
data
[
'category'
],
'course'
)
self
.
assertEqual
(
response
.
data
[
'name'
],
self
.
course
.
display_name
)
self
.
assertEqual
(
len
(
response
.
data
[
'modules'
]),
1
)
chapter
=
response
.
data
[
'modules'
][
0
]
self
.
assertEqual
(
chapter
[
'category'
],
'chapter'
)
self
.
assertEqual
(
chapter
[
'name'
],
'Overview'
)
self
.
assertEqual
(
len
(
chapter
[
'modules'
]),
1
)
sequence
=
chapter
[
'modules'
][
0
]
self
.
assertEqual
(
sequence
[
'category'
],
'videosequence'
)
self
.
assertEqual
(
sequence
[
'name'
],
'Video_Sequence'
)
self
.
assertNotIn
(
'modules'
,
sequence
)
def
test_course_tree_get_root
(
self
):
# query the course tree to quickly get naviation information
test_uri
=
self
.
base_courses_uri
+
'/'
+
self
.
test_course_id
+
'/tree/0'
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertGreater
(
len
(
response
.
data
),
0
)
self
.
assertEqual
(
response
.
data
[
'category'
],
'course'
)
self
.
assertEqual
(
response
.
data
[
'name'
],
self
.
course
.
display_name
)
self
.
assertNotIn
(
'modules'
,
response
.
data
)
def
test_chapter_list_get
(
self
):
def
test_chapter_list_get
(
self
):
test_uri
=
self
.
base_chapters_uri
test_uri
=
self
.
base_chapters_uri
response
=
self
.
do_get
(
test_uri
)
response
=
self
.
do_get
(
test_uri
)
...
...
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