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
7b79ccbb
Commit
7b79ccbb
authored
Aug 27, 2014
by
Matt Drayer
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mattdrayer/api-modulestore-direct: Added utility method
parent
f536c373
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
10 deletions
+15
-10
lms/djangoapps/api_manager/courses/tests.py
+6
-4
lms/djangoapps/api_manager/courses/views.py
+2
-3
lms/djangoapps/api_manager/courseware_access.py
+7
-3
No files found.
lms/djangoapps/api_manager/courses/tests.py
View file @
7b79ccbb
...
...
@@ -1526,8 +1526,9 @@ class CoursesApiTests(TestCase):
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTrue
(
len
(
response
.
data
.
keys
()),
2
)
self
.
assertIn
(
'1'
,
response
.
data
)
self
.
assertIn
(
'2'
,
response
.
data
)
users
=
response
.
data
[
'users'
]
self
.
assertTrue
(
users
.
get
(
'1'
))
self
.
assertTrue
(
users
.
get
(
'2'
))
# make the first user an observer to asset that its content is being filtered out from
# the aggregates
...
...
@@ -1536,8 +1537,9 @@ class CoursesApiTests(TestCase):
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTrue
(
len
(
response
.
data
.
keys
()),
1
)
self
.
assertNotIn
(
'1'
,
response
.
data
)
self
.
assertIn
(
'2'
,
response
.
data
)
users
=
response
.
data
[
'users'
]
self
.
assertFalse
(
users
.
get
(
'1'
))
self
.
assertTrue
(
users
.
get
(
'2'
))
def
test_courses_leaders_list_get
(
self
):
# make the last user an observer to asset that its content is being filtered out from
...
...
lms/djangoapps/api_manager/courses/views.py
View file @
7b79ccbb
...
...
@@ -28,7 +28,7 @@ from student.roles import CourseRole, CourseAccessRole, CourseInstructorRole, Co
from
xmodule.modulestore.django
import
modulestore
from
api_manager.courseware_access
import
get_course
,
get_course_child
,
get_course_leaf_nodes
,
get_course_key
,
course_exists
from
api_manager.courseware_access
import
get_course
,
get_course_child
,
get_course_leaf_nodes
,
get_course_key
,
course_exists
,
get_modulestore
from
api_manager.models
import
CourseGroupRelationship
,
CourseContentGroupRelationship
,
GroupProfile
,
\
CourseModuleCompletion
from
api_manager.permissions
import
SecureAPIView
,
SecureListAPIView
...
...
@@ -525,8 +525,7 @@ class CoursesList(SecureListAPIView):
serializer_class
=
CourseSerializer
def
get_queryset
(
self
):
store
=
modulestore
()
course_descriptors
=
store
.
get_courses
()
course_descriptors
=
get_modulestore
()
.
get_courses
()
return
course_descriptors
...
...
lms/djangoapps/api_manager/courseware_access.py
View file @
7b79ccbb
...
...
@@ -10,6 +10,10 @@ from xmodule.modulestore.django import modulestore
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
def
get_modulestore
():
return
modulestore
(
'direct'
)
def
get_course
(
request
,
user
,
course_id
,
depth
=
0
,
load_content
=
False
):
"""
Utility method to obtain course components
...
...
@@ -55,7 +59,7 @@ def get_course_leaf_nodes(course_key, detached_categories):
Get count of the leaf nodes with ability to exclude some categories
"""
nodes
=
[]
verticals
=
modulestore
()
.
get_items
(
course_key
,
category
=
'vertical'
)
verticals
=
get_
modulestore
()
.
get_items
(
course_key
,
category
=
'vertical'
)
for
vertical
in
verticals
:
nodes
.
extend
([
unit
for
unit
in
vertical
.
children
if
getattr
(
unit
,
'category'
)
not
in
detached_categories
])
...
...
@@ -96,7 +100,7 @@ def course_exists(request, user, course_id):
course_key
=
get_course_key
(
course_id
)
if
not
course_key
:
return
False
if
not
modulestore
()
.
has_course
(
course_key
):
if
not
get_
modulestore
()
.
has_course
(
course_key
):
return
False
return
True
...
...
@@ -114,7 +118,7 @@ def get_course_child_key(content_id):
def
get_course_child_descriptor
(
child_key
):
try
:
content_descriptor
=
modulestore
()
.
get_item
(
child_key
)
content_descriptor
=
get_
modulestore
()
.
get_item
(
child_key
)
except
ItemNotFoundError
:
content_descriptor
=
None
return
content_descriptor
...
...
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