-
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
6 changed files
with
191 additions
and
3 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,64 @@ | ||
"""Courses details collectors""" | ||
from __future__ import annotations | ||
|
||
from typing import List | ||
|
||
from common.djangoapps.student.models import CourseAccessRole, CourseEnrollment, UserSignupSource | ||
from django.db.models import Count, Exists, OuterRef, Q, Subquery | ||
from django.db.models.query import QuerySet | ||
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=1 | ||
).annotate( | ||
enrolled_count=Count( | ||
CourseEnrollment.objects.filter( | ||
course_id=OuterRef('id'), | ||
is_active=True, | ||
) | ||
) | ||
).annotate( | ||
active_count=Count( | ||
CourseEnrollment.objects.filter( | ||
course_id=OuterRef('id'), | ||
is_active=True, | ||
) | ||
) | ||
).annotate( | ||
certificates_count=Count( | ||
GeneratedCertificate.objects.filter( | ||
course_id=OuterRef('id'), | ||
status='downloadable' | ||
) | ||
) | ||
) | ||
|
||
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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
"""Pagination helpers and classes for the API views.""" | ||
from rest_framework.filters import OrderingFilter | ||
from rest_framework.pagination import PageNumberPagination | ||
|
||
|
||
class DefaultPagination(PageNumberPagination): | ||
page_size = 20 | ||
page_size_query_param = 'page_size' | ||
max_page_size = 100 | ||
|
||
|
||
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