From 484735bf034d5190a3e8064eb51e4b4ea252f4fd Mon Sep 17 00:00:00 2001 From: Victor Shnayder Date: Thu, 30 Aug 2012 18:55:38 -0400 Subject: [PATCH] make jump_to go to right position in a sequence. --- common/lib/xmodule/xmodule/modulestore/search.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/search.py b/common/lib/xmodule/xmodule/modulestore/search.py index a1ed407ee2..87f1cbf825 100644 --- a/common/lib/xmodule/xmodule/modulestore/search.py +++ b/common/lib/xmodule/xmodule/modulestore/search.py @@ -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)