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
8a0f785c
Commit
8a0f785c
authored
Jan 06, 2014
by
Andy Armstrong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix STUD-1129: handle out-of-range page numbers
parent
32710d4c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
8 deletions
+30
-8
cms/djangoapps/contentstore/tests/test_assets.py
+5
-0
cms/djangoapps/contentstore/views/assets.py
+25
-8
No files found.
cms/djangoapps/contentstore/tests/test_assets.py
View file @
8a0f785c
...
...
@@ -60,6 +60,11 @@ class AssetsToyCourseTestCase(CourseTestCase):
self
.
assert_correct_asset_response
(
url
+
"?page_size=2"
,
0
,
2
,
3
)
self
.
assert_correct_asset_response
(
url
+
"?page_size=2&page=1"
,
2
,
1
,
3
)
# Verify querying outside the range of valid pages
self
.
assert_correct_asset_response
(
url
+
"?page_size=2&page=-1"
,
0
,
2
,
3
)
self
.
assert_correct_asset_response
(
url
+
"?page_size=2&page=2"
,
2
,
1
,
3
)
self
.
assert_correct_asset_response
(
url
+
"?page_size=3&page=1"
,
0
,
3
,
3
)
def
assert_correct_asset_response
(
self
,
url
,
expected_start
,
expected_length
,
expected_total
):
resp
=
self
.
client
.
get
(
url
,
HTTP_ACCEPT
=
'application/json'
)
json_response
=
json
.
loads
(
resp
.
content
)
...
...
cms/djangoapps/contentstore/views/assets.py
View file @
8a0f785c
...
...
@@ -27,7 +27,7 @@ from django.http import HttpResponseNotFound
import
json
from
django.utils.translation
import
ugettext
as
_
from
pymongo
import
DESCENDING
import
math
__all__
=
[
'assets_handler'
]
...
...
@@ -91,17 +91,20 @@ def _assets_json(request, location):
"""
requested_page
=
int
(
request
.
REQUEST
.
get
(
'page'
,
0
))
requested_page_size
=
int
(
request
.
REQUEST
.
get
(
'page_size'
,
50
))
sort
=
[(
'uploadDate'
,
DESCENDING
)]
current_page
=
max
(
requested_page
,
0
)
start
=
current_page
*
requested_page_size
old_location
=
loc_mapper
()
.
translate_locator_to_location
(
location
)
course_reference
=
StaticContent
.
compute_location
(
old_location
.
org
,
old_location
.
course
,
old_location
.
name
)
assets
,
total_count
=
contentstore
()
.
get_all_content_for_course
(
course_reference
,
start
=
start
,
maxresults
=
requested_page_size
,
sort
=
[(
'uploadDate'
,
DESCENDING
)]
)
assets
,
total_count
=
_get_assets_for_page
(
request
,
location
,
current_page
,
requested_page_size
,
sort
)
end
=
start
+
len
(
assets
)
# If the query is beyond the final page, then re-query the final page so that at least one asset is returned
if
requested_page
>
0
and
start
>=
total_count
:
current_page
=
int
(
math
.
floor
((
total_count
-
1
)
/
requested_page_size
))
start
=
current_page
*
requested_page_size
assets
,
total_count
=
_get_assets_for_page
(
request
,
location
,
current_page
,
requested_page_size
,
sort
)
end
=
start
+
len
(
assets
)
asset_json
=
[]
for
asset
in
assets
:
asset_id
=
asset
[
'_id'
]
...
...
@@ -123,6 +126,20 @@ def _assets_json(request, location):
})
def
_get_assets_for_page
(
request
,
location
,
current_page
,
page_size
,
sort
):
"""
Returns the list of assets for the specified page and page size.
"""
start
=
current_page
*
page_size
old_location
=
loc_mapper
()
.
translate_locator_to_location
(
location
)
course_reference
=
StaticContent
.
compute_location
(
old_location
.
org
,
old_location
.
course
,
old_location
.
name
)
return
contentstore
()
.
get_all_content_for_course
(
course_reference
,
start
=
start
,
maxresults
=
page_size
,
sort
=
sort
)
@require_POST
@ensure_csrf_cookie
@login_required
...
...
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