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
06c152c1
Commit
06c152c1
authored
May 07, 2015
by
Martyn James
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7914 from edx/mjames/SOL-825_6
Exclude filtering for microsite orgs
parents
6577bb3b
fb51c6ab
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
6 deletions
+71
-6
cms/djangoapps/contentstore/courseware_index.py
+2
-2
lms/lib/courseware_search/lms_filter_generator.py
+17
-0
lms/lib/courseware_search/test/test_lms_filter_generator.py
+51
-3
requirements/edx/github.txt
+1
-1
No files found.
cms/djangoapps/contentstore/courseware_index.py
View file @
06c152c1
...
...
@@ -106,7 +106,7 @@ class SearchIndexerBase(object):
response
=
searcher
.
search
(
doc_type
=
cls
.
DOCUMENT_TYPE
,
field_dictionary
=
cls
.
_get_location_info
(
structure_key
),
exclude_
ids
=
exclude_items
exclude_
dictionary
=
{
"id"
:
list
(
exclude_items
)}
)
result_ids
=
[
result
[
"data"
][
"id"
]
for
result
in
response
[
"results"
]]
for
result_id
in
result_ids
:
...
...
@@ -298,7 +298,7 @@ class CoursewareSearchIndexer(SearchIndexerBase):
@classmethod
def
_get_location_info
(
cls
,
normalized_structure_key
):
""" Builds location info dictionary """
return
{
"course"
:
unicode
(
normalized_structure_key
)}
return
{
"course"
:
unicode
(
normalized_structure_key
)
,
"org"
:
normalized_structure_key
.
org
}
@classmethod
def
do_course_reindex
(
cls
,
modulestore
,
course_key
):
...
...
lms/lib/courseware_search/lms_filter_generator.py
View file @
06c152c1
...
...
@@ -2,6 +2,7 @@
This file contains implementation override of SearchFilterGenerator which will allow
* Filter by all courses in which the user is enrolled in
"""
from
microsite_configuration
import
microsite
from
student.models
import
CourseEnrollment
from
search.filter_generator
import
SearchFilterGenerator
...
...
@@ -19,4 +20,20 @@ class LmsSearchFilterGenerator(SearchFilterGenerator):
user_enrollments
=
CourseEnrollment
.
enrollments_for_user
(
kwargs
[
'user'
])
field_dictionary
[
'course'
]
=
[
unicode
(
enrollment
.
course_id
)
for
enrollment
in
user_enrollments
]
# if we have an org filter, only include results for this org filter
course_org_filter
=
microsite
.
get_value
(
'course_org_filter'
)
if
course_org_filter
:
field_dictionary
[
'org'
]
=
course_org_filter
return
field_dictionary
def
exclude_dictionary
(
self
,
**
kwargs
):
""" If we are not on a microsite, then exclude any microsites that are defined """
exclude_dictionary
=
super
(
LmsSearchFilterGenerator
,
self
)
.
exclude_dictionary
(
**
kwargs
)
course_org_filter
=
microsite
.
get_value
(
'course_org_filter'
)
# If we have a course filter we are ensuring that we only get those courses above
org_filter_out_set
=
microsite
.
get_all_orgs
()
if
not
course_org_filter
and
org_filter_out_set
:
exclude_dictionary
[
'org'
]
=
list
(
org_filter_out_set
)
return
exclude_dictionary
lms/lib/courseware_search/test/test_lms_filter_generator.py
View file @
06c152c1
"""
Tests for the lms_filter_generator
"""
from
mock
import
patch
,
Mock
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
student.tests.factories
import
UserFactory
...
...
@@ -44,7 +46,7 @@ class LmsSearchFilterGeneratorTestCase(ModuleStoreTestCase):
"""
Tests that we get the list of IDs of courses the user is enrolled in when the course ID is null or not provided
"""
field_dictionary
,
filter_dictionary
=
LmsSearchFilterGenerator
.
generate_field_filters
(
user
=
self
.
user
)
field_dictionary
,
filter_dictionary
,
_
=
LmsSearchFilterGenerator
.
generate_field_filters
(
user
=
self
.
user
)
self
.
assertTrue
(
'start_date'
in
filter_dictionary
)
self
.
assertIn
(
unicode
(
self
.
courses
[
0
]
.
id
),
field_dictionary
[
'course'
])
...
...
@@ -54,7 +56,7 @@ class LmsSearchFilterGeneratorTestCase(ModuleStoreTestCase):
"""
Tests that we get the course ID when the course ID is provided
"""
field_dictionary
,
filter_dictionary
=
LmsSearchFilterGenerator
.
generate_field_filters
(
field_dictionary
,
filter_dictionary
,
_
=
LmsSearchFilterGenerator
.
generate_field_filters
(
user
=
self
.
user
,
course_id
=
unicode
(
self
.
courses
[
0
]
.
id
)
)
...
...
@@ -66,7 +68,53 @@ class LmsSearchFilterGeneratorTestCase(ModuleStoreTestCase):
"""
Tests that we get empty list of courses in case the user is not provided
"""
field_dictionary
,
filter_dictionary
=
LmsSearchFilterGenerator
.
generate_field_filters
()
field_dictionary
,
filter_dictionary
,
_
=
LmsSearchFilterGenerator
.
generate_field_filters
()
self
.
assertTrue
(
'start_date'
in
filter_dictionary
)
self
.
assertEqual
(
0
,
len
(
field_dictionary
[
'course'
]))
def
test_excludes_microsite
(
self
):
""" By default there is the test microsite to exclude """
_
,
_
,
exclude_dictionary
=
LmsSearchFilterGenerator
.
generate_field_filters
(
user
=
self
.
user
)
self
.
assertIn
(
'org'
,
exclude_dictionary
)
exclude_orgs
=
exclude_dictionary
[
'org'
]
self
.
assertEqual
(
1
,
len
(
exclude_orgs
))
self
.
assertEqual
(
'TestMicrositeX'
,
exclude_orgs
[
0
])
@patch
(
'microsite_configuration.microsite.get_all_orgs'
,
Mock
(
return_value
=
[]))
def
test_excludes_no_microsite
(
self
):
""" Test when no microsite is present - nothing to exclude """
_
,
_
,
exclude_dictionary
=
LmsSearchFilterGenerator
.
generate_field_filters
(
user
=
self
.
user
)
self
.
assertNotIn
(
'org'
,
exclude_dictionary
)
@patch
(
'microsite_configuration.microsite.get_value'
,
Mock
(
return_value
=
'TestMicrositeX'
))
def
test_excludes_microsite_within
(
self
):
field_dictionary
,
_
,
exclude_dictionary
=
LmsSearchFilterGenerator
.
generate_field_filters
(
user
=
self
.
user
)
self
.
assertNotIn
(
'org'
,
exclude_dictionary
)
self
.
assertIn
(
'org'
,
field_dictionary
)
self
.
assertEqual
(
'TestMicrositeX'
,
field_dictionary
[
'org'
])
@patch
(
'microsite_configuration.microsite.get_all_orgs'
,
Mock
(
return_value
=
[
"TestMicrosite1"
,
"TestMicrosite2"
,
"TestMicrosite3"
,
"TestMicrosite4"
])
)
def
test_excludes_multi_microsites
(
self
):
_
,
_
,
exclude_dictionary
=
LmsSearchFilterGenerator
.
generate_field_filters
(
user
=
self
.
user
)
self
.
assertIn
(
'org'
,
exclude_dictionary
)
exclude_orgs
=
exclude_dictionary
[
'org'
]
self
.
assertEqual
(
4
,
len
(
exclude_orgs
))
self
.
assertIn
(
'TestMicrosite1'
,
exclude_orgs
)
self
.
assertIn
(
'TestMicrosite2'
,
exclude_orgs
)
self
.
assertIn
(
'TestMicrosite3'
,
exclude_orgs
)
self
.
assertIn
(
'TestMicrosite4'
,
exclude_orgs
)
@patch
(
'microsite_configuration.microsite.get_all_orgs'
,
Mock
(
return_value
=
[
"TestMicrosite1"
,
"TestMicrosite2"
,
"TestMicrosite3"
,
"TestMicrosite4"
])
)
@patch
(
'microsite_configuration.microsite.get_value'
,
Mock
(
return_value
=
'TestMicrosite3'
))
def
test_excludes_multi_microsites_within
(
self
):
field_dictionary
,
_
,
exclude_dictionary
=
LmsSearchFilterGenerator
.
generate_field_filters
(
user
=
self
.
user
)
self
.
assertNotIn
(
'org'
,
exclude_dictionary
)
self
.
assertIn
(
'org'
,
field_dictionary
)
self
.
assertEqual
(
'TestMicrosite3'
,
field_dictionary
[
'org'
])
requirements/edx/github.txt
View file @
06c152c1
...
...
@@ -43,7 +43,7 @@ git+https://github.com/pmitros/pyfs.git@96e1922348bfe6d99201b9512a9ed946c87b7e0b
-e git+https://github.com/edx/edx-val.git@d6087908aa3dd05ceaa7f56a21284f86c53cb3f0#egg=edx-val
-e git+https://github.com/pmitros/RecommenderXBlock.git@9b07e807c89ba5761827d0387177f71aa57ef056#egg=recommender-xblock
-e git+https://github.com/edx/edx-milestones.git@547f2250ee49e73ce8d7ff4e78ecf1b049892510#egg=edx-milestones
-e git+https://github.com/edx/edx-search.git@
9d566b88fd80cb0b60c052eee2bee30eb9f35b9c
#egg=edx-search
-e git+https://github.com/edx/edx-search.git@
59c7b4a8b61e8f7c4607669ea48e070555cca2fe
#egg=edx-search
git+https://github.com/edx/edx-lint.git@8bf82a32ecb8598c415413df66f5232ab8d974e9#egg=edx_lint==0.2.1
-e git+https://github.com/edx/xblock-utils.git@581ed636c862b286002bb9a3724cc883570eb54c#egg=xblock-utils
-e git+https://github.com/edx-solutions/xblock-google-drive.git@138e6fa0bf3a2013e904a085b9fed77dab7f3f21#egg=xblock-google-drive
...
...
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