Commit 66cb1bc2 by Jonathan Piacenti

Add ability to activate a child block via jump_to_id.

parent 0166729a
...@@ -81,6 +81,7 @@ def path_to_location(modulestore, usage_key): ...@@ -81,6 +81,7 @@ def path_to_location(modulestore, usage_key):
# pull out the location names # pull out the location names
chapter = path[1].name if n > 1 else None chapter = path[1].name if n > 1 else None
section = path[2].name if n > 2 else None section = path[2].name if n > 2 else None
vertical = path[3].name if n > 3 else None
# Figure out the position # Figure out the position
position = None position = None
...@@ -104,4 +105,4 @@ def path_to_location(modulestore, usage_key): ...@@ -104,4 +105,4 @@ def path_to_location(modulestore, usage_key):
position_list.append(str(child_locs.index(path[path_index + 1]) + 1)) position_list.append(str(child_locs.index(path[path_index + 1]) + 1))
position = "_".join(position_list) position = "_".join(position_list)
return (course_id, chapter, section, position) return (course_id, chapter, section, vertical, position, path[-1])
...@@ -60,6 +60,7 @@ from util.milestones_helpers import get_prerequisite_courses_display ...@@ -60,6 +60,7 @@ from util.milestones_helpers import get_prerequisite_courses_display
from microsite_configuration import microsite from microsite_configuration import microsite
from opaque_keys.edx.locations import SlashSeparatedCourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey
from opaque_keys.edx.locations import BlockUsageLocator
from instructor.enrollment import uses_shib from instructor.enrollment import uses_shib
from util.db import commit_on_success_with_read_committed from util.db import commit_on_success_with_read_committed
...@@ -492,7 +493,8 @@ def _index_bulk_op(request, course_key, chapter, section, position): ...@@ -492,7 +493,8 @@ def _index_bulk_op(request, course_key, chapter, section, position):
# Save where we are in the chapter # Save where we are in the chapter
save_child_position(chapter_module, section) 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 context['section_title'] = section_descriptor.display_name_with_default
else: else:
# section is none, so display a message # section is none, so display a message
...@@ -600,7 +602,7 @@ def jump_to(request, course_id, location): ...@@ -600,7 +602,7 @@ def jump_to(request, course_id, location):
except InvalidKeyError: except InvalidKeyError:
raise Http404(u"Invalid course_key or usage_key") raise Http404(u"Invalid course_key or usage_key")
try: try:
(course_key, chapter, section, position) = path_to_location(modulestore(), usage_key) (course_key, chapter, section, position, final_target_id) = path_to_location(modulestore(), usage_key)
except ItemNotFoundError: except ItemNotFoundError:
raise Http404(u"No data at this location: {0}".format(usage_key)) raise Http404(u"No data at this location: {0}".format(usage_key))
except NoPathToItem: except NoPathToItem:
...@@ -609,14 +611,29 @@ def jump_to(request, course_id, location): ...@@ -609,14 +611,29 @@ def jump_to(request, course_id, location):
# choose the appropriate view (and provide the necessary args) based on the # choose the appropriate view (and provide the necessary args) based on the
# args provided by the redirect. # args provided by the redirect.
# Rely on index to do all error handling and access control. # Rely on index to do all error handling and access control.
if chapter is None: if chapter is None:
return redirect('courseware', course_id=course_key.to_deprecated_string()) redirect_url = reverse('courseware', args=(unicode(course_key), ))
elif section is None: elif section is None:
return redirect('courseware_chapter', course_id=course_key.to_deprecated_string(), chapter=chapter) redirect_url = reverse('courseware_chapter', args=(unicode(course_key), chapter))
elif position is None: elif position is None:
return redirect('courseware_section', course_id=course_key.to_deprecated_string(), chapter=chapter, section=section) redirect_url = reverse(
'courseware_section',
args=(unicode(course_key), chapter, section)
)
else: else:
return redirect('courseware_position', course_id=course_key.to_deprecated_string(), chapter=chapter, section=section, position=position) # Here we use the navigation_index from the position returned from
# path_to_location - we can only navigate to the topmost vertical at the
# moment
redirect_url = reverse(
'courseware_position',
args=(unicode(course_key), chapter, section, position)
)
redirect_url += "?{}".format(urllib.urlencode({'activate_block_id': unicode(final_target_id)}))
return redirect(redirect_url)
@ensure_csrf_cookie @ensure_csrf_cookie
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment