diff --git a/lms/lib/courseware_search/lms_filter_generator.py b/lms/lib/courseware_search/lms_filter_generator.py index c2e33ab18b60..db599d999fae 100644 --- a/lms/lib/courseware_search/lms_filter_generator.py +++ b/lms/lib/courseware_search/lms_filter_generator.py @@ -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() diff --git a/lms/lib/courseware_search/test/test_lms_filter_generator.py b/lms/lib/courseware_search/test/test_lms_filter_generator.py index 2f88a8bbd4b3..26a3ab619d52 100644 --- a/lms/lib/courseware_search/test/test_lms_filter_generator.py +++ b/lms/lib/courseware_search/test/test_lms_filter_generator.py @@ -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 @@ -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): """ @@ -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): """ diff --git a/openedx/stanford/lms/envs/common.py b/openedx/stanford/lms/envs/common.py index cd35fd3ebdf3..2c46b1ebd61b 100644 --- a/openedx/stanford/lms/envs/common.py +++ b/openedx/stanford/lms/envs/common.py @@ -114,6 +114,7 @@ # The following fields are available in the URL: {course_id} {student_id} PROGRESS_SUCCESS_BUTTON_URL = 'http:////{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. diff --git a/openedx/stanford/lms/lib/__init__.py b/openedx/stanford/lms/lib/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/openedx/stanford/lms/lib/courseware_search/__init__.py b/openedx/stanford/lms/lib/courseware_search/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/openedx/stanford/lms/lib/courseware_search/lms_filter_generator.py b/openedx/stanford/lms/lib/courseware_search/lms_filter_generator.py new file mode 100644 index 000000000000..42ed8ef984e5 --- /dev/null +++ b/openedx/stanford/lms/lib/courseware_search/lms_filter_generator.py @@ -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 diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index dfd276786f86..10ed55fc9c42 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -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