Commit 484735bf by Victor Shnayder

make jump_to go to right position in a sequence.

parent 021ccde1
......@@ -26,7 +26,7 @@ def path_to_location(modulestore, course_id, location):
A location may be accessible via many paths. This method may
return any valid path.
If the section is a sequence, position will be the position
If the section is a sequential or vertical, position will be the position
of this location in that sequence. Otherwise, position will
be None. TODO (vshnayder): Not true yet.
'''
......@@ -83,15 +83,21 @@ def path_to_location(modulestore, course_id, location):
path = find_path_to_course()
if path is None:
raise(NoPathToItem(location))
raise NoPathToItem(location)
n = len(path)
course_id = CourseDescriptor.location_to_id(path[0])
# pull out the location names
chapter = path[1].name if n > 1 else None
section = path[2].name if n > 2 else None
# TODO (vshnayder): not handling position at all yet...
# Figure out the position
position = None
if n > 3:
section_desc = modulestore.get_instance(course_id, path[2])
child_locs = [c.location for c in section_desc.get_children()]
# positions are 1-indexed, and should be strings to be consistent with
# url parsing.
position = str(child_locs.index(path[3]) + 1)
return (course_id, chapter, section, position)
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