Skip to content

Commit

Permalink
filtering the passed language on the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
arslanashraf7 committed Jan 24, 2025
1 parent cfa66d8 commit f5630e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 6 additions & 1 deletion cms/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from wagtail.models import Page, Site

from cms import models as cms_models
from cms.constants import CERTIFICATE_INDEX_SLUG, ENTERPRISE_PAGE_SLUG, CatalogSorting
from cms.constants import (
CERTIFICATE_INDEX_SLUG,
ENTERPRISE_PAGE_SLUG,
CatalogSorting,
)

log = logging.getLogger(__name__)
DEFAULT_HOMEPAGE_PROPS = dict(title="Home Page", subhead="This is the home page") # noqa: C408
Expand Down Expand Up @@ -47,6 +51,7 @@ def filter_and_sort_catalog_pages(
external_course_pages (iterable of ExternalCoursePage): ExternalCoursePages to filter and sort
external_program_pages (iterable of ExternalProgramPage): ExternalProgramPages to filter and sort
sort_by (str): Sorting applicable.
language_filter (str): Language filter applicable.
Returns:
tuple of (list of Pages): A tuple containing a list of combined ProgramPages, CoursePages, ExternalCoursePages and ExternalProgramPages, a list of
Expand Down
12 changes: 11 additions & 1 deletion cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ def get_context(self, request, *args, **kwargs): # noqa: ARG002
Populate the context with live programs, courses and programs + courses
"""
topic_filter = request.GET.get("topic", ALL_TOPICS)
language_filter = request.GET.get("language", ALL_LANGUAGES)

is_language_filter_enabled = is_enabled(CATALOG_LANGUAGE_FILTER, default=False)

Expand Down Expand Up @@ -562,10 +563,19 @@ def get_context(self, request, *args, **kwargs): # noqa: ARG002
.order_by("title")
)

if language_filter != ALL_LANGUAGES:
program_page_qset = program_page_qset.filter(language__name=language_filter)
external_program_qset = external_program_qset.filter(
language__name=language_filter
)
course_page_qset = course_page_qset.filter(language__name=language_filter)
external_course_qset = external_course_qset.filter(
language__name=language_filter
)

if topic_filter != ALL_TOPICS:
program_page_qset = program_page_qset.related_pages(topic_filter)
external_program_qset = external_program_qset.related_pages(topic_filter)

course_page_qset = course_page_qset.related_pages(topic_filter)
external_course_qset = external_course_qset.related_pages(topic_filter)

Expand Down

0 comments on commit f5630e1

Please sign in to comment.