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
b8c5b984
Commit
b8c5b984
authored
Nov 26, 2014
by
Greg Price
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6076 from edx/gprice/last-visited-module-path
Add last visited module path to course status API
parents
763b29d0
3a7e1251
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
7 deletions
+21
-7
lms/djangoapps/mobile_api/users/tests.py
+5
-1
lms/djangoapps/mobile_api/users/views.py
+16
-6
No files found.
lms/djangoapps/mobile_api/users/tests.py
View file @
b8c5b984
...
...
@@ -186,7 +186,7 @@ class TestUserApi(ModuleStoreTestCase, APITestCase):
self
.
assertEqual
(
response
.
status_code
,
401
)
def
test_default_value
(
self
):
(
__
,
__
,
unit
,
__
)
=
self
.
_setup_course_skeleton
()
(
section
,
sub_section
,
unit
,
__
)
=
self
.
_setup_course_skeleton
()
self
.
client
.
login
(
username
=
self
.
username
,
password
=
self
.
password
)
url
=
self
.
_course_status_url
()
...
...
@@ -195,6 +195,10 @@ class TestUserApi(ModuleStoreTestCase, APITestCase):
self
.
assertEqual
(
result
.
status_code
,
200
)
self
.
assertEqual
(
json_data
[
"last_visited_module_id"
],
unicode
(
unit
.
location
))
self
.
assertEqual
(
json_data
[
"last_visited_module_path"
],
[
unicode
(
module
.
location
)
for
module
in
[
unit
,
sub_section
,
section
,
self
.
course
]]
)
def
test_course_update_no_args
(
self
):
self
.
client
.
login
(
username
=
self
.
username
,
password
=
self
.
password
)
...
...
lms/djangoapps/mobile_api/users/views.py
View file @
b8c5b984
...
...
@@ -90,10 +90,11 @@ class UserCourseStatus(views.APIView):
http_method_names
=
[
"get"
,
"patch"
]
def
_last_visited_module_
id
(
self
,
request
,
course
):
def
_last_visited_module_
path
(
self
,
request
,
course
):
"""
Returns the id of the last module visited by the current user in the given course.
If there is no such visit returns the default (the first item deep enough down the course tree)
Returns the path from the last module visited by the current user in the given course up to
the course module. If there is no such visit, the first item deep enough down the course
tree is used.
"""
field_data_cache
=
FieldDataCache
.
cache_for_descriptor_descendents
(
course
.
id
,
request
.
user
,
course
,
depth
=
2
)
...
...
@@ -101,13 +102,16 @@ class UserCourseStatus(views.APIView):
course_module
=
get_module_for_descriptor
(
request
.
user
,
request
,
course
,
field_data_cache
,
course
.
id
)
current
=
course_module
path
=
[]
child
=
current
while
child
:
path
.
append
(
child
)
child
=
get_current_child
(
current
)
if
child
:
current
=
child
return
current
path
.
reverse
()
return
path
def
_process_arguments
(
self
,
request
,
username
,
course_id
,
course_handler
):
"""
...
...
@@ -134,8 +138,12 @@ class UserCourseStatus(views.APIView):
"""
Returns the course status
"""
current_module
=
self
.
_last_visited_module_id
(
request
,
course
)
return
Response
({
"last_visited_module_id"
:
unicode
(
current_module
.
location
)})
path
=
self
.
_last_visited_module_path
(
request
,
course
)
path_ids
=
[
unicode
(
module
.
location
)
for
module
in
path
]
return
Response
({
"last_visited_module_id"
:
path_ids
[
0
],
"last_visited_module_path"
:
path_ids
,
})
def
get
(
self
,
request
,
username
,
course_id
):
"""
...
...
@@ -151,6 +159,8 @@ class UserCourseStatus(views.APIView):
* last_visited_module_id: The id of the last module visited by the user in the given course
* last_visited_module_path: The ids of the modules in the path from the last visited module
to the course module
"""
return
self
.
_process_arguments
(
request
,
username
,
course_id
,
lambda
course
:
self
.
get_course_info
(
request
,
course
))
...
...
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