Merge pull request #7219 from edx/mjames/SOL-289
Addresses problem with 'up' and 'down' errors within SOL-289
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
''' useful functions for finding content and its position '''
|
||||
from logging import getLogger
|
||||
|
||||
from .exceptions import (ItemNotFoundError, NoPathToItem)
|
||||
|
||||
LOGGER = getLogger(__name__)
|
||||
|
||||
|
||||
def path_to_location(modulestore, usage_key):
|
||||
'''
|
||||
@@ -105,3 +110,30 @@ def path_to_location(modulestore, usage_key):
|
||||
position = "_".join(position_list)
|
||||
|
||||
return (course_id, chapter, section, position)
|
||||
|
||||
|
||||
def navigation_index(position):
|
||||
"""
|
||||
Get the navigation index from the position argument (where the position argument was recieved from a call to
|
||||
path_to_location)
|
||||
|
||||
Argument:
|
||||
position - result of position returned from call to path_to_location. This is an underscore (_) separated string of
|
||||
vertical 1-indexed positions. If the course is built in Studio then you'll never see verticals as children of
|
||||
verticals, and so extremely often one will only see the first vertical as an integer position. This specific action
|
||||
is to allow navigation / breadcrumbs to locate the topmost item because this is the location actually required by
|
||||
the LMS code
|
||||
|
||||
Returns:
|
||||
1-based integer of the position of the desired item within the vertical
|
||||
"""
|
||||
if position is None:
|
||||
return None
|
||||
|
||||
try:
|
||||
navigation_position = int(position.split('_', 1)[0])
|
||||
except (ValueError, TypeError):
|
||||
LOGGER.exception(u'Bad position %r passed to navigation_index, will assume first position', position)
|
||||
navigation_position = 1
|
||||
|
||||
return navigation_position
|
||||
|
||||
@@ -38,7 +38,7 @@ from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.draft_and_published import UnsupportedRevisionError, DIRECT_ONLY_CATEGORIES
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateCourseError, ReferentialIntegrityError, NoPathToItem
|
||||
from xmodule.modulestore.mixed import MixedModuleStore
|
||||
from xmodule.modulestore.search import path_to_location
|
||||
from xmodule.modulestore.search import path_to_location, navigation_index
|
||||
from xmodule.modulestore.tests.factories import check_mongo_calls, check_exact_number_of_calls, \
|
||||
mongo_uses_error_check
|
||||
from xmodule.modulestore.tests.utils import create_modulestore_instance, LocationMixin
|
||||
@@ -1153,6 +1153,18 @@ class TestMixedModuleStore(CourseComparisonTest):
|
||||
with self.assertRaises(ItemNotFoundError):
|
||||
path_to_location(self.store, location)
|
||||
|
||||
def test_navigation_index(self):
|
||||
"""
|
||||
Make sure that navigation_index correctly parses the various position values that we might get from calls to
|
||||
path_to_location
|
||||
"""
|
||||
self.assertEqual(1, navigation_index("1"))
|
||||
self.assertEqual(10, navigation_index("10"))
|
||||
self.assertEqual(None, navigation_index(None))
|
||||
self.assertEqual(1, navigation_index("1_2"))
|
||||
self.assertEqual(5, navigation_index("5_2"))
|
||||
self.assertEqual(7, navigation_index("7_3_5_6_"))
|
||||
|
||||
@ddt.data('draft', 'split')
|
||||
def test_revert_to_published_root_draft(self, default_ms):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user