Move location identifying strings into index
This commit is contained in:
@@ -13,8 +13,6 @@ from xmodule.modulestore.search import path_to_location, navigation_index
|
||||
|
||||
from courseware.access import has_access
|
||||
|
||||
UNNAMED_MODULE_NAME = _("(Unnamed)")
|
||||
|
||||
|
||||
class LmsSearchResultProcessor(SearchResultProcessor):
|
||||
|
||||
@@ -62,51 +60,6 @@ class LmsSearchResultProcessor(SearchResultProcessor):
|
||||
kwargs={"course_id": self._results_fields["course"], "location": self._results_fields["id"]}
|
||||
)
|
||||
|
||||
@property
|
||||
def course_name(self):
|
||||
"""
|
||||
Display the course name when searching multiple courses - retain result for subsequent uses
|
||||
"""
|
||||
if self._course_name is None:
|
||||
course = self.get_module_store().get_course(self.get_course_key())
|
||||
self._course_name = course.display_name_with_default
|
||||
return self._course_name
|
||||
|
||||
@property
|
||||
def location(self):
|
||||
"""
|
||||
Blend "location" property into the resultset, so that the path to the found component can be shown within the UI
|
||||
"""
|
||||
# TODO: update whern changes to "cohorted-courseware" branch are merged in
|
||||
(course_key, chapter, section, position) = path_to_location(self.get_module_store(), self.get_usage_key())
|
||||
|
||||
def get_display_name(item_key):
|
||||
""" gets display name from object's key """
|
||||
item = self.get_item(item_key)
|
||||
display_name = getattr(item, "display_name", None)
|
||||
return display_name if display_name else UNNAMED_MODULE_NAME
|
||||
|
||||
def get_position_name(section, position):
|
||||
""" helper to fetch name corresponding to the position therein """
|
||||
if position:
|
||||
section_item = self.get_item(course_key.make_usage_key("sequential", section))
|
||||
if section_item.has_children and len(section_item.children) >= position:
|
||||
return get_display_name(section_item.children[position - 1])
|
||||
return None
|
||||
|
||||
location_description = []
|
||||
if chapter:
|
||||
location_description.append(get_display_name(course_key.make_usage_key("chapter", chapter)))
|
||||
if section:
|
||||
location_description.append(get_display_name(course_key.make_usage_key("sequential", section)))
|
||||
if position:
|
||||
# We're only wanting to show the first vertical, so we use the
|
||||
# navigation_index function to display the same location to which one
|
||||
# would be sent if navigating
|
||||
location_description.append(get_position_name(section, navigation_index(position)))
|
||||
|
||||
return location_description
|
||||
|
||||
def should_remove(self, user):
|
||||
""" Test to see if this result should be removed due to access restriction """
|
||||
return not has_access(
|
||||
|
||||
@@ -6,7 +6,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
|
||||
from courseware.tests.factories import UserFactory
|
||||
|
||||
from lms.lib.courseware_search.lms_result_processor import LmsSearchResultProcessor, UNNAMED_MODULE_NAME
|
||||
from lms.lib.courseware_search.lms_result_processor import LmsSearchResultProcessor
|
||||
|
||||
|
||||
class LmsSearchResultProcessorTestCase(ModuleStoreTestCase):
|
||||
@@ -85,71 +85,6 @@ class LmsSearchResultProcessorTestCase(ModuleStoreTestCase):
|
||||
self.assertEqual(
|
||||
srp.url, "/courses/{}/jump_to/{}".format(unicode(self.course.id), unicode(self.html.scope_ids.usage_id)))
|
||||
|
||||
def test_course_name_parameter(self):
|
||||
srp = LmsSearchResultProcessor(
|
||||
{
|
||||
"course": unicode(self.course.id),
|
||||
"id": unicode(self.html.scope_ids.usage_id),
|
||||
"content": {"text": "This is the html text"}
|
||||
},
|
||||
"test"
|
||||
)
|
||||
self.assertEqual(srp.course_name, self.course.display_name)
|
||||
|
||||
def test_location_parameter(self):
|
||||
srp = LmsSearchResultProcessor(
|
||||
{
|
||||
"course": unicode(self.course.id),
|
||||
"id": unicode(self.html.scope_ids.usage_id),
|
||||
"content": {"text": "This is html test text"}
|
||||
},
|
||||
"test"
|
||||
)
|
||||
|
||||
self.assertEqual(len(srp.location), 3)
|
||||
self.assertEqual(srp.location[0], 'Test Section')
|
||||
self.assertEqual(srp.location[1], 'Test Subsection')
|
||||
self.assertEqual(srp.location[2], 'Test Unit')
|
||||
|
||||
srp = LmsSearchResultProcessor(
|
||||
{
|
||||
"course": unicode(self.course.id),
|
||||
"id": unicode(self.vertical.scope_ids.usage_id),
|
||||
"content": {"text": "This is html test text"}
|
||||
},
|
||||
"test"
|
||||
)
|
||||
|
||||
self.assertEqual(len(srp.location), 3)
|
||||
self.assertEqual(srp.location[0], 'Test Section')
|
||||
self.assertEqual(srp.location[1], 'Test Subsection')
|
||||
self.assertEqual(srp.location[2], 'Test Unit')
|
||||
|
||||
srp = LmsSearchResultProcessor(
|
||||
{
|
||||
"course": unicode(self.course.id),
|
||||
"id": unicode(self.subsection.scope_ids.usage_id),
|
||||
"content": {"text": "This is html test text"}
|
||||
},
|
||||
"test"
|
||||
)
|
||||
|
||||
self.assertEqual(len(srp.location), 2)
|
||||
self.assertEqual(srp.location[0], 'Test Section')
|
||||
self.assertEqual(srp.location[1], 'Test Subsection')
|
||||
|
||||
srp = LmsSearchResultProcessor(
|
||||
{
|
||||
"course": unicode(self.course.id),
|
||||
"id": unicode(self.section.scope_ids.usage_id),
|
||||
"content": {"text": "This is html test text"}
|
||||
},
|
||||
"test"
|
||||
)
|
||||
|
||||
self.assertEqual(len(srp.location), 1)
|
||||
self.assertEqual(srp.location[0], 'Test Section')
|
||||
|
||||
def test_should_remove(self):
|
||||
"""
|
||||
Tests that "visible_to_staff_only" overrides start date.
|
||||
@@ -164,22 +99,3 @@ class LmsSearchResultProcessorTestCase(ModuleStoreTestCase):
|
||||
)
|
||||
|
||||
self.assertEqual(srp.should_remove(self.global_staff), False)
|
||||
|
||||
def test_missing_display_name(self):
|
||||
"""
|
||||
Tests that we get the correct name to include when there is an empty or null display name
|
||||
"""
|
||||
srp = LmsSearchResultProcessor(
|
||||
{
|
||||
"course": unicode(self.course.id),
|
||||
"id": unicode(self.ghost_html.scope_ids.usage_id),
|
||||
"content": {"text": "This is html test text"}
|
||||
},
|
||||
"test"
|
||||
)
|
||||
|
||||
location = srp.location
|
||||
self.assertEqual(len(location), 3)
|
||||
self.assertEqual(location[0], self.section.display_name)
|
||||
self.assertEqual(location[1], UNNAMED_MODULE_NAME)
|
||||
self.assertEqual(location[2], UNNAMED_MODULE_NAME)
|
||||
|
||||
Reference in New Issue
Block a user