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
a6ae44a0
Commit
a6ae44a0
authored
Jul 01, 2015
by
Jonathan Piacenti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to activate a child block via jump_to_id.
parent
93e31e61
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
16 deletions
+76
-16
common/lib/xmodule/xmodule/modulestore/search.py
+2
-1
common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py
+10
-7
lms/djangoapps/courseware/tests/test_views.py
+53
-5
lms/djangoapps/courseware/url_helpers.py
+8
-1
lms/djangoapps/courseware/views.py
+2
-1
lms/djangoapps/open_ended_grading/utils.py
+1
-1
No files found.
common/lib/xmodule/xmodule/modulestore/search.py
View file @
a6ae44a0
...
...
@@ -86,6 +86,7 @@ def path_to_location(modulestore, usage_key):
# pull out the location names
chapter
=
path
[
1
]
.
name
if
n
>
1
else
None
section
=
path
[
2
]
.
name
if
n
>
2
else
None
vertical
=
path
[
3
]
.
name
if
n
>
3
else
None
# Figure out the position
position
=
None
...
...
@@ -109,7 +110,7 @@ def path_to_location(modulestore, usage_key):
position_list
.
append
(
str
(
child_locs
.
index
(
path
[
path_index
+
1
])
+
1
))
position
=
"_"
.
join
(
position_list
)
return
(
course_id
,
chapter
,
section
,
position
)
return
(
course_id
,
chapter
,
section
,
vertical
,
position
,
path
[
-
1
]
)
def
navigation_index
(
position
):
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py
View file @
a6ae44a0
...
...
@@ -1221,15 +1221,16 @@ class TestMixedModuleStore(CommonMixedModuleStoreSetup):
should_work
=
(
(
self
.
problem_x1a_2
,
(
course_key
,
u"Chapter_x"
,
u"Sequential_x1"
,
'1'
)),
(
course_key
,
u"Chapter_x"
,
u"Sequential_x1"
,
u'Vertical_x1a'
,
'1'
,
self
.
problem_x1a_2
)),
(
self
.
chapter_x
,
(
course_key
,
"Chapter_x"
,
None
,
None
)),
(
course_key
,
"Chapter_x"
,
None
,
None
,
None
,
self
.
chapter_x
)),
)
for
location
,
expected
in
should_work
:
# each iteration has different find count, pop this iter's find count
with
check_mongo_calls
(
num_finds
.
pop
(
0
),
num_sends
):
self
.
assertEqual
(
path_to_location
(
self
.
store
,
location
),
expected
)
path
=
path_to_location
(
self
.
store
,
location
)
self
.
assertEqual
(
path
,
expected
)
not_found
=
(
course_key
.
make_usage_key
(
'video'
,
'WelcomeX'
),
...
...
@@ -1259,11 +1260,13 @@ class TestMixedModuleStore(CommonMixedModuleStoreSetup):
# only needs course_locations set
self
.
initdb
(
'draft'
)
course_key
=
self
.
course_locations
[
self
.
XML_COURSEID1
]
.
course_key
video_key
=
course_key
.
make_usage_key
(
'video'
,
'Welcome'
)
chapter_key
=
course_key
.
make_usage_key
(
'chapter'
,
'Overview'
)
should_work
=
(
(
course_key
.
make_usage_key
(
'video'
,
'Welcome'
)
,
(
course_key
,
"Overview"
,
"Welcome"
,
None
)),
(
c
ourse_key
.
make_usage_key
(
'chapter'
,
'Overview'
)
,
(
course_key
,
"Overview"
,
None
,
None
)),
(
video_key
,
(
course_key
,
"Overview"
,
"Welcome"
,
None
,
None
,
video_key
)),
(
c
hapter_key
,
(
course_key
,
"Overview"
,
None
,
None
,
None
,
chapter_key
)),
)
for
location
,
expected
in
should_work
:
...
...
lms/djangoapps/courseware/tests/test_views.py
View file @
a6ae44a0
...
...
@@ -83,10 +83,11 @@ class TestJumpTo(ModuleStoreTestCase):
course
=
CourseFactory
.
create
()
chapter
=
ItemFactory
.
create
(
category
=
'chapter'
,
parent_location
=
course
.
location
)
section
=
ItemFactory
.
create
(
category
=
'sequential'
,
parent_location
=
chapter
.
location
)
expected
=
'courses/{course_id}/courseware/{chapter_id}/{section_id}/'
.
format
(
expected
=
'courses/{course_id}/courseware/{chapter_id}/{section_id}/
?activate_block_id={section_key}
'
.
format
(
course_id
=
unicode
(
course
.
id
),
chapter_id
=
chapter
.
url_name
,
section_id
=
section
.
url_name
,
section_key
=
unicode
(
section
.
location
)
)
jumpto_url
=
'{0}/{1}/jump_to/{2}'
.
format
(
'/courses'
,
...
...
@@ -105,10 +106,11 @@ class TestJumpTo(ModuleStoreTestCase):
module1
=
ItemFactory
.
create
(
category
=
'html'
,
parent_location
=
vertical1
.
location
)
module2
=
ItemFactory
.
create
(
category
=
'html'
,
parent_location
=
vertical2
.
location
)
expected
=
'courses/{course_id}/courseware/{chapter_id}/{section_id}/1'
.
format
(
expected
=
'courses/{course_id}/courseware/{chapter_id}/{section_id}/1
?activate_block_id={module_key}
'
.
format
(
course_id
=
unicode
(
course
.
id
),
chapter_id
=
chapter
.
url_name
,
section_id
=
section
.
url_name
,
module_key
=
unicode
(
module1
.
location
)
)
jumpto_url
=
'{0}/{1}/jump_to/{2}'
.
format
(
'/courses'
,
...
...
@@ -118,10 +120,11 @@ class TestJumpTo(ModuleStoreTestCase):
response
=
self
.
client
.
get
(
jumpto_url
)
self
.
assertRedirects
(
response
,
expected
,
status_code
=
302
,
target_status_code
=
302
)
expected
=
'courses/{course_id}/courseware/{chapter_id}/{section_id}/2'
.
format
(
expected
=
'courses/{course_id}/courseware/{chapter_id}/{section_id}/2
?activate_block_id={module_key}
'
.
format
(
course_id
=
unicode
(
course
.
id
),
chapter_id
=
chapter
.
url_name
,
section_id
=
section
.
url_name
,
module_key
=
unicode
(
module2
.
location
),
)
jumpto_url
=
'{0}/{1}/jump_to/{2}'
.
format
(
'/courses'
,
...
...
@@ -145,10 +148,11 @@ class TestJumpTo(ModuleStoreTestCase):
# internal position of module2 will be 1_2 (2nd item withing 1st item)
expected
=
'courses/{course_id}/courseware/{chapter_id}/{section_id}/1'
.
format
(
expected
=
'courses/{course_id}/courseware/{chapter_id}/{section_id}/1
?activate_block_id={module_key}
'
.
format
(
course_id
=
unicode
(
course
.
id
),
chapter_id
=
chapter
.
url_name
,
section_id
=
section
.
url_name
,
module_key
=
unicode
(
module2
.
location
)
)
jumpto_url
=
'{0}/{1}/jump_to/{2}'
.
format
(
'/courses'
,
...
...
@@ -1084,6 +1088,23 @@ class GenerateUserCertTests(ModuleStoreTestCase):
),
resp
.
content
)
class
ActivateIDCheckerBlock
(
XBlock
):
"""
XBlock for checking for an activate_block_id entry in the render context.
"""
# We don't need actual children to test this.
has_children
=
False
def
student_view
(
self
,
context
):
"""
A student view that displays the activate_block_id context variable.
"""
result
=
Fragment
()
if
'activate_block_id'
in
context
:
result
.
add_content
(
u"Activate Block ID: {block_id}</p>"
.
format
(
block_id
=
context
[
'activate_block_id'
]))
return
result
class
ViewCheckerBlock
(
XBlock
):
"""
XBlock for testing user state in views.
...
...
@@ -1117,7 +1138,7 @@ class TestIndexView(ModuleStoreTestCase):
@XBlock.register_temp_plugin
(
ViewCheckerBlock
,
'view_checker'
)
@ddt.data
(
ModuleStoreEnum
.
Type
.
mongo
,
ModuleStoreEnum
.
Type
.
split
)
def
test_student_state
(
self
,
default_store
):
def
test_student_state
(
self
,
default_store
,
):
"""
Verify that saved student state is loaded for xblocks rendered in the index view.
"""
...
...
@@ -1157,6 +1178,33 @@ class TestIndexView(ModuleStoreTestCase):
response
=
views
.
index
(
request
,
unicode
(
course
.
id
),
chapter
=
chapter
.
url_name
,
section
=
section
.
url_name
)
self
.
assertEquals
(
response
.
content
.
count
(
"ViewCheckerPassed"
),
3
)
@XBlock.register_temp_plugin
(
ActivateIDCheckerBlock
,
'id_checker'
)
def
test_activate_block_id
(
self
):
user
=
UserFactory
()
course
=
CourseFactory
.
create
()
chapter
=
ItemFactory
.
create
(
parent
=
course
,
category
=
'chapter'
)
section
=
ItemFactory
.
create
(
parent
=
chapter
,
category
=
'sequential'
,
display_name
=
"Sequence"
)
vertical
=
ItemFactory
.
create
(
parent
=
section
,
category
=
'vertical'
,
display_name
=
"Vertical"
)
ItemFactory
.
create
(
parent
=
vertical
,
category
=
'id_checker'
,
display_name
=
"ID Checker"
)
CourseEnrollmentFactory
(
user
=
user
,
course_id
=
course
.
id
)
request
=
RequestFactory
()
.
get
(
reverse
(
'courseware_section'
,
kwargs
=
{
'course_id'
:
unicode
(
course
.
id
),
'chapter'
:
chapter
.
url_name
,
'section'
:
section
.
url_name
,
}
)
+
'?activate_block_id=test_block_id'
)
request
.
user
=
user
mako_middleware_process_request
(
request
)
response
=
views
.
index
(
request
,
unicode
(
course
.
id
),
chapter
=
chapter
.
url_name
,
section
=
section
.
url_name
)
self
.
assertIn
(
"Activate Block ID: test_block_id"
,
response
.
content
)
class
TestRenderXBlock
(
RenderXBlockTestMixin
,
ModuleStoreTestCase
):
"""
...
...
lms/djangoapps/courseware/url_helpers.py
View file @
a6ae44a0
...
...
@@ -20,7 +20,10 @@ def get_redirect_url(course_key, usage_key):
Redirect url string
"""
(
course_key
,
chapter
,
section
,
position
)
=
path_to_location
(
modulestore
(),
usage_key
)
(
course_key
,
chapter
,
section
,
vertical_unused
,
position
,
final_target_id
)
=
path_to_location
(
modulestore
(),
usage_key
)
# choose the appropriate view (and provide the necessary args) based on the
# args provided by the redirect.
...
...
@@ -43,4 +46,8 @@ def get_redirect_url(course_key, usage_key):
'courseware_position'
,
args
=
(
unicode
(
course_key
),
chapter
,
section
,
navigation_index
(
position
))
)
if
final_target_id
:
redirect_url
+=
"?activate_block_id={final_target_id}"
.
format
(
final_target_id
=
final_target_id
)
return
redirect_url
lms/djangoapps/courseware/views.py
View file @
a6ae44a0
...
...
@@ -550,7 +550,8 @@ def _index_bulk_op(request, course_key, chapter, section, position):
# Save where we are in the chapter.
save_child_position
(
chapter_module
,
section
)
context
[
'fragment'
]
=
section_module
.
render
(
STUDENT_VIEW
)
section_render_context
=
{
'activate_block_id'
:
request
.
GET
.
get
(
'activate_block_id'
)}
context
[
'fragment'
]
=
section_module
.
render
(
STUDENT_VIEW
,
section_render_context
)
context
[
'section_title'
]
=
section_descriptor
.
display_name_with_default
else
:
# section is none, so display a message
...
...
lms/djangoapps/open_ended_grading/utils.py
View file @
a6ae44a0
...
...
@@ -43,7 +43,7 @@ def generate_problem_url(problem_url_parts, base_course_url):
# This is placed between the course id and the rest of the url.
if
i
==
1
:
problem_url
+=
"courseware/"
problem_url
+=
part
+
"/"
problem_url
+=
unicode
(
part
)
+
"/"
return
problem_url
...
...
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