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
439ddfa9
Commit
439ddfa9
authored
Sep 10, 2015
by
Andy Armstrong
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9668 from edx/andya/team-search-i18n-bug
Improve support for Chinese characters in team search
parents
d1d44e7b
321a0ea6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
13 deletions
+38
-13
lms/djangoapps/teams/search_indexes.py
+9
-6
lms/djangoapps/teams/tests/test_views.py
+28
-6
lms/djangoapps/teams/views.py
+1
-1
No files found.
lms/djangoapps/teams/search_indexes.py
View file @
439ddfa9
...
@@ -6,6 +6,7 @@ from requests import ConnectionError
...
@@ -6,6 +6,7 @@ from requests import ConnectionError
from
django.conf
import
settings
from
django.conf
import
settings
from
django.db.models.signals
import
post_save
from
django.db.models.signals
import
post_save
from
django.dispatch
import
receiver
from
django.dispatch
import
receiver
from
django.utils
import
translation
from
search.search_engine_base
import
SearchEngine
from
search.search_engine_base
import
SearchEngine
...
@@ -49,12 +50,14 @@ class CourseTeamIndexer(object):
...
@@ -49,12 +50,14 @@ class CourseTeamIndexer(object):
"""
"""
Generate the text field used for general search.
Generate the text field used for general search.
"""
"""
return
"{name}
\n
{description}
\n
{country}
\n
{language}"
.
format
(
# Always use the English version of any localizable strings (see TNL-3239)
name
=
self
.
course_team
.
name
.
encode
(
'utf-8'
),
with
translation
.
override
(
'en'
):
description
=
self
.
course_team
.
description
.
encode
(
'utf-8'
),
return
u"{name}
\n
{description}
\n
{country}
\n
{language}"
.
format
(
country
=
self
.
course_team
.
country
.
name
.
format
(),
name
=
self
.
course_team
.
name
,
language
=
self
.
_language_name
()
description
=
self
.
course_team
.
description
,
)
country
=
self
.
course_team
.
country
.
name
.
format
(),
language
=
self
.
_language_name
()
)
def
_language_name
(
self
):
def
_language_name
(
self
):
"""
"""
...
...
lms/djangoapps/teams/tests/test_views.py
View file @
439ddfa9
...
@@ -9,6 +9,7 @@ import ddt
...
@@ -9,6 +9,7 @@ import ddt
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.conf
import
settings
from
django.conf
import
settings
from
django.db.models.signals
import
post_save
from
django.db.models.signals
import
post_save
from
django.utils
import
translation
from
nose.plugins.attrib
import
attr
from
nose.plugins.attrib
import
attr
from
rest_framework.test
import
APITestCase
,
APIClient
from
rest_framework.test
import
APITestCase
,
APIClient
...
@@ -223,6 +224,14 @@ class TeamAPITestCase(APITestCase, SharedModuleStoreTestCase):
...
@@ -223,6 +224,14 @@ class TeamAPITestCase(APITestCase, SharedModuleStoreTestCase):
course_id
=
self
.
test_course_2
.
id
,
course_id
=
self
.
test_course_2
.
id
,
topic_id
=
'topic_7'
topic_id
=
'topic_7'
)
)
self
.
chinese_team
=
CourseTeamFactory
.
create
(
name
=
u'著文企臺個'
,
description
=
u'共樣地面較,件展冷不護者這與民教過住意,國制銀產物助音是勢一友'
,
country
=
'CN'
,
language
=
'zh_HANS'
,
course_id
=
self
.
test_course_2
.
id
,
topic_id
=
'topic_7'
)
self
.
test_team_name_id_map
=
{
team
.
name
:
team
for
team
in
(
self
.
test_team_name_id_map
=
{
team
.
name
:
team
for
team
in
(
self
.
solar_team
,
self
.
solar_team
,
...
@@ -231,6 +240,7 @@ class TeamAPITestCase(APITestCase, SharedModuleStoreTestCase):
...
@@ -231,6 +240,7 @@ class TeamAPITestCase(APITestCase, SharedModuleStoreTestCase):
self
.
another_team
,
self
.
another_team
,
self
.
public_profile_team
,
self
.
public_profile_team
,
self
.
search_team
,
self
.
search_team
,
self
.
chinese_team
,
)}
)}
for
user
,
course
in
[(
'staff'
,
self
.
test_course_1
),
(
'course_staff'
,
self
.
test_course_1
)]:
for
user
,
course
in
[(
'staff'
,
self
.
test_course_1
),
(
'course_staff'
,
self
.
test_course_1
)]:
...
@@ -437,7 +447,7 @@ class TestListTeamsAPI(EventTestMixin, TeamAPITestCase):
...
@@ -437,7 +447,7 @@ class TestListTeamsAPI(EventTestMixin, TeamAPITestCase):
self
.
verify_names
(
self
.
verify_names
(
{
'course_id'
:
self
.
test_course_2
.
id
},
{
'course_id'
:
self
.
test_course_2
.
id
},
200
,
200
,
[
'Another Team'
,
'Public Profile Team'
,
'Search'
],
[
'Another Team'
,
'Public Profile Team'
,
'Search'
,
u'著文企臺個'
],
user
=
'staff'
user
=
'staff'
)
)
...
@@ -516,15 +526,17 @@ class TestListTeamsAPI(EventTestMixin, TeamAPITestCase):
...
@@ -516,15 +526,17 @@ class TestListTeamsAPI(EventTestMixin, TeamAPITestCase):
(
'Island'
,
[
'Search'
]),
(
'Island'
,
[
'Search'
]),
(
'not-a-query'
,
[]),
(
'not-a-query'
,
[]),
(
'team'
,
[
'Another Team'
,
'Public Profile Team'
]),
(
'team'
,
[
'Another Team'
,
'Public Profile Team'
]),
(
u'著文企臺個'
,
[
u'著文企臺個'
]),
)
)
@ddt.unpack
@ddt.unpack
def
test_text_search
(
self
,
text_search
,
expected_team_names
):
def
test_text_search
(
self
,
text_search
,
expected_team_names
):
# clear out the teams search index before reindexing
def
reset_search_index
():
CourseTeamIndexer
.
engine
()
.
destroy
()
"""Clear out the search index and reindex the teams."""
CourseTeamIndexer
.
engine
()
.
destroy
()
for
team
in
self
.
test_team_name_id_map
.
values
():
for
team
in
self
.
test_team_name_id_map
.
values
():
CourseTeamIndexer
.
index
(
team
)
CourseTeamIndexer
.
index
(
team
)
reset_search_index
()
self
.
verify_names
(
self
.
verify_names
(
{
'course_id'
:
self
.
test_course_2
.
id
,
'text_search'
:
text_search
},
{
'course_id'
:
self
.
test_course_2
.
id
,
'text_search'
:
text_search
},
200
,
200
,
...
@@ -540,6 +552,16 @@ class TestListTeamsAPI(EventTestMixin, TeamAPITestCase):
...
@@ -540,6 +552,16 @@ class TestListTeamsAPI(EventTestMixin, TeamAPITestCase):
number_of_results
=
len
(
expected_team_names
)
number_of_results
=
len
(
expected_team_names
)
)
)
# Verify that the searches still work for a user from a different locale
with
translation
.
override
(
'ar'
):
reset_search_index
()
self
.
verify_names
(
{
'course_id'
:
self
.
test_course_2
.
id
,
'text_search'
:
text_search
},
200
,
expected_team_names
,
user
=
'student_enrolled_public_profile'
)
@ddt.ddt
@ddt.ddt
class
TestCreateTeamAPI
(
EventTestMixin
,
TeamAPITestCase
):
class
TestCreateTeamAPI
(
EventTestMixin
,
TeamAPITestCase
):
...
...
lms/djangoapps/teams/views.py
View file @
439ddfa9
...
@@ -361,7 +361,7 @@ class TeamsListView(ExpandableFieldViewMixin, GenericAPIView):
...
@@ -361,7 +361,7 @@ class TeamsListView(ExpandableFieldViewMixin, GenericAPIView):
result_filter
.
update
({
'course_id'
:
course_id_string
})
result_filter
.
update
({
'course_id'
:
course_id_string
})
search_results
=
search_engine
.
search
(
search_results
=
search_engine
.
search
(
query_string
=
text_search
.
encode
(
'utf-8'
)
,
query_string
=
text_search
,
field_dictionary
=
result_filter
,
field_dictionary
=
result_filter
,
size
=
MAXIMUM_SEARCH_SIZE
,
size
=
MAXIMUM_SEARCH_SIZE
,
)
)
...
...
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