diff --git a/futurex_openedx_extensions/dashboard/details/courses.py b/futurex_openedx_extensions/dashboard/details/courses.py index 700816b..671036e 100644 --- a/futurex_openedx_extensions/dashboard/details/courses.py +++ b/futurex_openedx_extensions/dashboard/details/courses.py @@ -23,6 +23,7 @@ from django.db.models.functions import Coalesce from django.db.models.query import QuerySet from eox_nelp.course_experience.models import FeedbackCourse +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from lms.djangoapps.certificates.models import GeneratedCertificate from futurex_openedx_extensions.helpers.querysets import ( @@ -106,11 +107,11 @@ def get_courses_queryset( queryset = annotate_courses_rating_queryset(queryset) if include_staff: - is_staff_queryset = Q(Value(False, output_field=BooleanField())) - else: is_staff_queryset = check_staff_exist_queryset( ref_user_id='user_id', ref_org='course__org', ref_course_id='course_id', ) + else: + is_staff_queryset = Q(Value(False, output_field=BooleanField())) queryset = queryset.annotate( enrolled_count=Coalesce(Subquery( @@ -143,6 +144,12 @@ def get_courses_queryset( GeneratedCertificate.objects.filter( course_id=OuterRef('id'), status='downloadable' + ).annotate( + course__org=Subquery( + CourseOverview.objects.filter(id=OuterRef('course_id')).values('org') + ) + ).filter( + ~is_staff_queryset ).values('course_id').annotate(count=Count('id')).values('count'), output_field=IntegerField(), ), 0), diff --git a/futurex_openedx_extensions/dashboard/views.py b/futurex_openedx_extensions/dashboard/views.py index 1a17833..a86e8eb 100644 --- a/futurex_openedx_extensions/dashboard/views.py +++ b/futurex_openedx_extensions/dashboard/views.py @@ -254,7 +254,7 @@ class CoursesView(ExportCSVMixin, FXViewRoleInfoMixin, ListAPIView): def get_queryset(self) -> QuerySet: """Get the list of learners""" search_text = self.request.query_params.get('search_text') - include_staff = self.request.query_params.get('include_staff', '0') == '1' + include_staff = self.request.query_params.get('include_staff') return get_courses_queryset( fx_permission_info=self.fx_permission_info,