-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
411 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"""Courses details collectors""" | ||
from __future__ import annotations | ||
|
||
from typing import List | ||
|
||
from common.djangoapps.student.models import CourseEnrollment | ||
from django.db.models import Count, OuterRef, Q, Subquery, Sum | ||
from django.db.models.query import QuerySet | ||
from eox_nelp.course_experience.models import FeedbackCourse | ||
from lms.djangoapps.certificates.models import GeneratedCertificate | ||
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview | ||
|
||
from futurex_openedx_extensions.helpers.tenants import get_course_org_filter_list, get_tenant_site | ||
|
||
|
||
def get_courses_queryset(tenant_ids: List, search_text: str = None) -> QuerySet: | ||
""" | ||
Get the courses queryset for the given tenant IDs and search text. | ||
:param tenant_ids: List of tenant IDs to get the courses for | ||
:type tenant_ids: List | ||
:param search_text: Search text to filter the courses by | ||
:type search_text: str | ||
""" | ||
course_org_filter_list = get_course_org_filter_list(tenant_ids)['course_org_filter_list'] | ||
tenant_sites = [] | ||
for tenant_id in tenant_ids: | ||
if site := get_tenant_site(tenant_id): | ||
tenant_sites.append(site) | ||
|
||
queryset = CourseOverview.objects.filter( | ||
org__in=course_org_filter_list | ||
) | ||
search_text = (search_text or '').strip() | ||
if search_text: | ||
queryset = queryset.filter( | ||
Q(display_name__icontains=search_text) | | ||
Q(id__icontains=search_text) | ||
) | ||
queryset = queryset.annotate( | ||
rating_count=Count(Subquery( | ||
FeedbackCourse.objects.filter( | ||
course_id=OuterRef('id'), | ||
rating_content__gt=0, | ||
).values('id') | ||
)) | ||
).annotate( | ||
rating_total=Sum( | ||
FeedbackCourse.objects.filter( | ||
course_id=OuterRef('id'), | ||
rating_content__gt=0, | ||
).values_list('rating_content', flat=True) | ||
) | ||
).annotate( | ||
enrolled_count=Count(Subquery( | ||
CourseEnrollment.objects.filter( | ||
course_id=OuterRef('id'), | ||
is_active=True, | ||
).values('id') | ||
)) | ||
).annotate( | ||
active_count=Count(Subquery( | ||
CourseEnrollment.objects.filter( | ||
course_id=OuterRef('id'), | ||
is_active=True, | ||
).values('id') | ||
)) | ||
).annotate( | ||
certificates_count=Count(Subquery( | ||
GeneratedCertificate.objects.filter( | ||
course_id=OuterRef('id'), | ||
status='downloadable' | ||
).values('id') | ||
)) | ||
) | ||
|
||
return queryset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""Filters helpers and classes for the API views.""" | ||
from rest_framework.filters import OrderingFilter | ||
|
||
|
||
class DefaultOrderingFilter(OrderingFilter): | ||
ordering_param = 'sort' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
test_utils/edx_platform_mocks/eox_nelp/course_experience/models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"""edx-platform Mocks""" | ||
from fake_models.models import FeedbackCourse # pylint: disable=unused-import |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
"""eox_tenant test settings.""" | ||
GET_SITE_CONFIGURATION_MODULE = 'eox_tenant.edxapp_wrapper.backends.site_configuration_module_i_v1' | ||
"""EOX test settings.""" | ||
|
||
# eox-tenant settings | ||
EOX_TENANT_USERS_BACKEND = 'eox_tenant.edxapp_wrapper.backends.users_l_v1' | ||
GET_BRANDING_API = 'eox_tenant.edxapp_wrapper.backends.branding_api_l_v1' | ||
GET_SITE_CONFIGURATION_MODULE = 'eox_tenant.edxapp_wrapper.backends.site_configuration_module_i_v1' | ||
GET_THEMING_HELPERS = 'eox_tenant.edxapp_wrapper.backends.theming_helpers_h_v1' | ||
EOX_TENANT_USERS_BACKEND = 'eox_tenant.edxapp_wrapper.backends.users_l_v1' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Tests for courses details collectors""" | ||
import pytest | ||
|
||
from futurex_openedx_extensions.dashboard.details.courses import get_courses_queryset | ||
|
||
|
||
@pytest.mark.django_db | ||
@pytest.mark.parametrize('tenant_ids, search_text, expected_count', [ | ||
([7, 8], None, 5), | ||
([7], None, 3), | ||
([8], None, 2), | ||
([7], 'Course 1', 1), | ||
([7], 'Course 3', 1), | ||
([7], 'course 3', 1), | ||
([7], 'course 4', 0), | ||
([4], None, 0), | ||
]) | ||
def test_get_courses_queryset(base_data, tenant_ids, search_text, expected_count): # pylint: disable=unused-argument | ||
"""Verify that get_courses_queryset returns the correct QuerySet.""" | ||
assert get_courses_queryset(tenant_ids, search_text).count() == expected_count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.