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
403ebbd5
Commit
403ebbd5
authored
Aug 07, 2014
by
Chris Dodge
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cdodge/speed-up-get-current-position: enough said
more cleanup fix method name
parent
0225e33a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
17 deletions
+38
-17
lms/djangoapps/api_manager/courseware_access.py
+4
-4
lms/djangoapps/api_manager/users/views.py
+34
-13
No files found.
lms/djangoapps/api_manager/courseware_access.py
View file @
403ebbd5
...
...
@@ -31,10 +31,10 @@ def get_course(request, user, course_id, depth=0):
pass
if
course_descriptor
:
field_data_cache
=
FieldDataCache
([
course_descriptor
],
course_key
,
user
)
course_content
=
module_render
.
get_module
(
course_content
=
module_render
.
get_module
_for_descriptor
(
user
,
request
,
course_descriptor
.
location
,
course_descriptor
,
field_data_cache
,
course_key
)
return
course_descriptor
,
course_key
,
course_content
...
...
@@ -61,10 +61,10 @@ def get_course_child(request, user, course_key, content_id):
pass
if
content_descriptor
:
field_data_cache
=
FieldDataCache
([
content_descriptor
],
course_key
,
user
)
content
=
module_render
.
get_module
(
content
=
module_render
.
get_module
_for_descriptor
(
user
,
request
,
content_
key
,
content_
descriptor
,
field_data_cache
,
course_key
)
return
content_descriptor
,
content_key
,
content
...
...
lms/djangoapps/api_manager/users/views.py
View file @
403ebbd5
...
...
@@ -47,6 +47,8 @@ from opaque_keys.edx.keys import UsageKey, CourseKey
from
opaque_keys.edx.locations
import
Location
from
xmodule.modulestore
import
InvalidLocationError
from
xmodule.modulestore.django
import
modulestore
log
=
logging
.
getLogger
(
__name__
)
AUDIT_LOG
=
logging
.
getLogger
(
"audit"
)
...
...
@@ -719,6 +721,27 @@ class UsersCoursesList(SecureAPIView):
return
Response
(
response_data
,
status
=
status
.
HTTP_200_OK
)
def
_get_current_position_loc
(
parent_module
):
"""
An optimized lookup for the current position. The LMS version can cause unnecessary round trips to
the Mongo database
"""
if
not
hasattr
(
parent_module
,
'position'
):
return
None
if
not
parent_module
.
children
:
return
None
index
=
0
if
parent_module
.
position
:
index
=
parent_module
.
position
-
1
# position is 1 indexed
if
0
<=
index
<
len
(
parent_module
.
children
):
return
parent_module
.
children
[
index
]
return
parent_module
.
children
[
0
]
class
UsersCoursesDetail
(
SecureAPIView
):
"""
### The UsersCoursesDetail view allows clients to interact with a specific User-Course relationship (aka, enrollment)
...
...
@@ -782,7 +805,7 @@ class UsersCoursesDetail(SecureAPIView):
base_uri
=
generate_base_uri
(
request
)
try
:
user
=
User
.
objects
.
get
(
id
=
user_id
,
is_active
=
True
)
course_descriptor
,
course_key
,
course_content
=
get_course
(
request
,
user
,
course_id
,
depth
=
2
)
course_descriptor
,
course_key
,
course_content
=
get_course
(
request
,
user
,
course_id
)
except
(
ObjectDoesNotExist
,
ValueError
):
return
Response
({},
status
=
status
.
HTTP_404_NOT_FOUND
)
if
not
CourseEnrollment
.
is_enrolled
(
user
,
course_key
):
...
...
@@ -794,7 +817,7 @@ class UsersCoursesDetail(SecureAPIView):
course_key
,
user
,
course_descriptor
,
depth
=
2
)
depth
=
0
)
course_module
=
module_render
.
get_module_for_descriptor
(
user
,
request
,
...
...
@@ -805,17 +828,15 @@ class UsersCoursesDetail(SecureAPIView):
response_data
[
'position_tree'
]
=
{}
parent_module
=
course_module
while
parent_module
is
not
None
:
current_child_descriptor
=
get_current_child
(
parent_module
)
if
current_child_descriptor
:
response_data
[
'position_tree'
][
current_child_descriptor
.
category
]
=
{}
response_data
[
'position_tree'
][
current_child_descriptor
.
category
][
'id'
]
=
unicode
(
current_child_descriptor
.
scope_ids
.
usage_id
)
parent_module
=
module_render
.
get_module
(
user
,
request
,
current_child_descriptor
.
scope_ids
.
usage_id
,
field_data_cache
,
course_key
)
current_child_loc
=
_get_current_position_loc
(
parent_module
)
if
current_child_loc
:
response_data
[
'position_tree'
][
current_child_loc
.
category
]
=
{}
response_data
[
'position_tree'
][
current_child_loc
.
category
][
'id'
]
=
unicode
(
current_child_loc
)
_
,
_
,
parent_module
=
get_course_child
(
request
,
user
,
course_key
,
unicode
(
current_child_loc
))
else
:
parent_module
=
None
return
Response
(
response_data
,
status
=
status
.
HTTP_200_OK
)
...
...
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