Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
b4ba5cba
Commit
b4ba5cba
authored
Mar 10, 2015
by
Martyn James
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7242 from edx/mjames/SOL-290
Addresses SOL-290.
parents
3359d6e3
15965c13
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
10 deletions
+48
-10
lms/lib/courseware_search/lms_result_processor.py
+11
-8
lms/lib/courseware_search/test/test_lms_result_processor.py
+37
-2
No files found.
lms/lib/courseware_search/lms_result_processor.py
View file @
b4ba5cba
...
...
@@ -4,6 +4,7 @@ This file contains implementation override of SearchResultProcessor which will a
* Confirms user access to object
"""
from
django.core.urlresolvers
import
reverse
from
django.utils.translation
import
ugettext
as
_
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
search.result_processor
import
SearchResultProcessor
...
...
@@ -12,6 +13,8 @@ from xmodule.modulestore.search import path_to_location
from
courseware.access
import
has_access
UNNAMED_MODULE_NAME
=
_
(
"(Unnamed)"
)
class
LmsSearchResultProcessor
(
SearchResultProcessor
):
...
...
@@ -66,25 +69,25 @@ class LmsSearchResultProcessor(SearchResultProcessor):
# 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
(
category
,
item_id
):
""" helper to get display name from object """
item
=
self
.
get_item
(
course_key
.
make_usage_key
(
category
,
item_id
))
return
getattr
(
item
,
"display_name"
,
None
)
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 """
pos
=
int
(
position
)
section_item
=
self
.
get_item
(
course_key
.
make_usage_key
(
"sequential"
,
section
))
if
section_item
.
has_children
and
len
(
section_item
.
children
)
>=
pos
:
item
=
self
.
get_item
(
section_item
.
children
[
pos
-
1
])
return
getattr
(
item
,
"display_name"
,
None
)
return
get_display_name
(
section_item
.
children
[
pos
-
1
])
return
None
location_description
=
[]
if
chapter
:
location_description
.
append
(
get_display_name
(
"chapter"
,
chapter
))
location_description
.
append
(
get_display_name
(
course_key
.
make_usage_key
(
"chapter"
,
chapter
)
))
if
section
:
location_description
.
append
(
get_display_name
(
"sequential"
,
section
))
location_description
.
append
(
get_display_name
(
course_key
.
make_usage_key
(
"sequential"
,
section
)
))
if
position
:
location_description
.
append
(
get_position_name
(
section
,
position
))
...
...
lms/lib/courseware_search/test/test_lms_result_processor.py
View file @
b4ba5cba
...
...
@@ -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
from
lms.lib.courseware_search.lms_result_processor
import
LmsSearchResultProcessor
,
UNNAMED_MODULE_NAME
class
LmsSearchResultProcessorTestCase
(
ModuleStoreTestCase
):
...
...
@@ -40,9 +40,25 @@ class LmsSearchResultProcessorTestCase(ModuleStoreTestCase):
display_name
=
'Test Unit'
,
)
self
.
html
=
ItemFactory
.
create
(
parent
=
self
.
vertical
,
category
=
'html'
,
parent
=
self
.
vertical
,
category
=
'html'
,
display_name
=
'Test Html control'
,
)
self
.
ghost_subsection
=
ItemFactory
.
create
(
parent
=
self
.
section
,
category
=
'sequential'
,
display_name
=
None
,
)
self
.
ghost_vertical
=
ItemFactory
.
create
(
parent
=
self
.
ghost_subsection
,
category
=
'vertical'
,
display_name
=
None
,
)
self
.
ghost_html
=
ItemFactory
.
create
(
parent
=
self
.
ghost_vertical
,
category
=
'html'
,
display_name
=
'Ghost Html control'
,
)
def
setUp
(
self
):
# from nose.tools import set_trace
...
...
@@ -137,3 +153,22 @@ 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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment