diff --git a/cms/api.py b/cms/api.py index d0577f7ea..083d132a8 100644 --- a/cms/api.py +++ b/cms/api.py @@ -32,33 +32,27 @@ def filter_and_sort_catalog_pages( tuple of (list of Pages): A tuple containing a list of combined ProgramPages, CoursePages, ExternalCoursePages and ExternalProgramPages, a list of ProgramPages and ExternalProgramPages, and a list of CoursePages and ExternalCoursePages, all sorted by the next course/program run date and title """ + all_program_pages = program_pages + external_program_pages + all_course_pages = course_pages + external_course_pages + valid_program_pages = [ - page for page in program_pages if page.product.is_catalog_visible + page for page in all_program_pages if page.product.is_catalog_visible ] valid_course_pages = [ - page for page in course_pages if page.product.is_catalog_visible + page for page in all_course_pages if page.product.is_catalog_visible ] - valid_external_course_pages = list(external_course_pages) - - valid_external_program_pages = list(external_program_pages) - page_run_dates = { page: page.product.next_run_date or datetime(year=MAXYEAR, month=1, day=1, tzinfo=timezone.utc) for page in itertools.chain( valid_program_pages, valid_course_pages, - valid_external_course_pages, - valid_external_program_pages, ) } return ( sorted( - valid_program_pages - + valid_external_program_pages - + valid_course_pages - + valid_external_course_pages, + valid_program_pages + valid_course_pages, # ProgramPages with the same next run date as a CoursePage should be sorted first key=lambda page: ( page_run_dates[page], @@ -67,11 +61,11 @@ def filter_and_sort_catalog_pages( ), ), sorted( - valid_program_pages + valid_external_program_pages, + valid_program_pages, key=lambda page: (page_run_dates[page], page.title), ), sorted( - valid_course_pages + valid_external_course_pages, + valid_course_pages, key=lambda page: (page_run_dates[page], page.title), ), ) diff --git a/cms/api_test.py b/cms/api_test.py index faa591923..95808c476 100644 --- a/cms/api_test.py +++ b/cms/api_test.py @@ -6,7 +6,6 @@ from cms.api import filter_and_sort_catalog_pages from cms.factories import ExternalCoursePageFactory, ExternalProgramPageFactory -from cms.models import ExternalCoursePage from courses.factories import CourseRunFactory, ProgramRunFactory from mitxpro.utils import now_in_utc @@ -84,14 +83,14 @@ def test_filter_and_sort_catalog_pages(): + len(initial_course_pages) + len(external_course_pages) + len(external_program_pages) - - 1 + - 2 ) assert len(course_pages) == ( len(initial_course_pages) + len(external_course_pages) - 1 ) assert len(program_pages) == ( - len(initial_program_pages) + len(external_program_pages) + len(initial_program_pages) + len(external_program_pages) - 1 ) # Filtered out external course page because it does not have a `course` attribute @@ -104,7 +103,6 @@ def test_filter_and_sort_catalog_pages(): first_program_run.course.program, second_program_run.course.program, later_external_program_page.program, - earlier_external_program_page.program, ] expected_course_run_sort = [ non_program_run, @@ -116,9 +114,6 @@ def test_filter_and_sort_catalog_pages(): ] # The sort should also include external course pages as expected - assert [ - page if page.is_external_course_page else page.course for page in course_pages - ] == [ - run if isinstance(run, ExternalCoursePage) else run.course - for run in expected_course_run_sort + assert [page.course for page in course_pages] == [ + run.course for run in expected_course_run_sort ]