Skip to content

Commit

Permalink
Merge pull request #879 from kluo/search-tile-filter
Browse files Browse the repository at this point in the history
Use custom filter generator for course discovery search
  • Loading branch information
kluo authored Feb 27, 2019
2 parents 1fdd5b3 + 4f23ed3 commit 8674364
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 9 deletions.
9 changes: 4 additions & 5 deletions lms/lib/courseware_search/lms_filter_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ def _enrollments_for_user(self, user):
def field_dictionary(self, **kwargs):
""" add course if provided otherwise add courses in which the user is enrolled in """
field_dictionary = super(LmsSearchFilterGenerator, self).field_dictionary(**kwargs)
if not kwargs.get('user'):
field_dictionary['course'] = []
elif not kwargs.get('course_id'):
user_enrollments = self._enrollments_for_user(kwargs['user'])
field_dictionary['course'] = [unicode(enrollment.course_id) for enrollment in user_enrollments]
if kwargs.get('user'):
if not kwargs.get('course_id'):
user_enrollments = self._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 = configuration_helpers.get_current_site_orgs()
Expand Down
8 changes: 5 additions & 3 deletions lms/lib/courseware_search/test/test_lms_filter_generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests for the lms_filter_generator
"""
from django.test.utils import override_settings
from mock import Mock, patch

from lms.lib.courseware_search.lms_filter_generator import LmsSearchFilterGenerator
Expand All @@ -10,8 +11,9 @@
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory


@override_settings(SEARCH_FILTER_GENERATOR="lms.lib.courseware_search.lms_filter_generator.LmsSearchFilterGenerator")
class LmsSearchFilterGeneratorTestCase(ModuleStoreTestCase):
""" Tests for search result processor """
""" Tests for search filter generator """

def build_courses(self):
"""
Expand Down Expand Up @@ -80,12 +82,12 @@ def test_course_id_provided(self):

def test_user_not_provided(self):
"""
Tests that we get empty list of courses in case the user is not provided
Tests that we get empty dict in case the user is not provided
"""
field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters()

self.assertIn('start_date', filter_dictionary)
self.assertEqual(0, len(field_dictionary['course']))
self.assertEqual({}, field_dictionary)

def test_excludes_site_org(self):
"""
Expand Down
1 change: 1 addition & 0 deletions openedx/stanford/lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
# The following fields are available in the URL: {course_id} {student_id}
PROGRESS_SUCCESS_BUTTON_URL = 'http://<domain>/<path>/{course_id}'
PROGRESS_SUCCESS_BUTTON_TEXT_OVERRIDE = None
SEARCH_FILTER_GENERATOR = 'openedx.stanford.lms.lib.courseware_search.lms_filter_generator.TileSearchFilterGenerator'
SHIB_REDIRECT_DOMAIN_WHITELIST = {
# Mapping of hosts to a list of safe redirect domains from that host
# (not including itself); e.g.
Expand Down
Empty file.
Empty file.
27 changes: 27 additions & 0 deletions openedx/stanford/lms/lib/courseware_search/lms_filter_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Custom override of SearchFilterGenerator to use course tiles for
discovery search.
"""
from search.filter_generator import SearchFilterGenerator

from branding_stanford.models import TileConfiguration
from lms.lib.courseware_search.lms_filter_generator import LmsSearchFilterGenerator


class TileSearchFilterGenerator(LmsSearchFilterGenerator):
"""
SearchFilterGenerator for LMS Search.
"""

def field_dictionary(self, **kwargs):
"""
Return field filter dictionary for search.
"""
field_dictionary = super(TileSearchFilterGenerator, self).field_dictionary(**kwargs)
if not kwargs.get('user'):
# Adds tile courses for discovery search
course_tiles_ids = TileConfiguration.objects.filter(
enabled=True,
).values_list('course_id', flat=True).order_by('-change_date')
field_dictionary['course'] = list(course_tiles_ids)
return field_dictionary
2 changes: 1 addition & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ edx-oauth2-provider==1.2.0
edx-opaque-keys==0.4.0
edx-organizations==0.4.4
edx-rest-api-client==1.7.1
edx-search==1.0.1
git+https://github.com/Stanford-Online/edx-search.git@e2aba4a30cf2dc6aa901799596161a59fa3e3baa#egg=edx-search==1.2.1
facebook-sdk==0.4.0
feedparser==5.1.3
firebase-token-generator==1.3.2
Expand Down

0 comments on commit 8674364

Please sign in to comment.