From ddcfec15157e86f39a70cdf38dd12ef95a0e9e6b Mon Sep 17 00:00:00 2001 From: Muhammad Faraz Maqsood Date: Fri, 12 Jul 2024 19:52:03 +0500 Subject: [PATCH] fix: no of programs, it will match the dashboard now --- .../course_progress/api/v1/views.py | 35 +++---------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/openedx/features/sdaia_features/course_progress/api/v1/views.py b/openedx/features/sdaia_features/course_progress/api/v1/views.py index ead7bcff26cf..7ebf415d3d5b 100644 --- a/openedx/features/sdaia_features/course_progress/api/v1/views.py +++ b/openedx/features/sdaia_features/course_progress/api/v1/views.py @@ -19,14 +19,11 @@ UserBasedRole, ) from common.djangoapps.util.disable_rate_limit import can_disable_rate_limit -from lms.djangoapps.program_enrollments.rest_api.v1.views import ( - UserProgramReadOnlyAccessView, -) -from openedx.core.djangoapps.catalog.utils import get_programs, get_programs_by_type from openedx.core.djangoapps.cors_csrf.decorators import ensure_csrf_cookie_cross_domain from openedx.core.djangoapps.enrollments.errors import CourseEnrollmentError from openedx.core.djangoapps.enrollments.data import get_course_enrollments from openedx.core.djangoapps.enrollments.views import EnrollmentCrossDomainSessionAuth +from openedx.core.djangoapps.programs.utils import ProgramProgressMeter from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser from openedx.core.lib.api.permissions import ApiKeyHeaderPermissionIsAuthenticated @@ -81,30 +78,9 @@ def get(self, request): raise HTTPException(status_code=500, detail=str(e)) ############ PROGRAMS COUNT ############ - programs = [] - requested_program_type = "masters" - if user.is_staff: - programs = get_programs_by_type(request.site, requested_program_type) - else: - program_dict = {} - # Check if the user is a course staff of any course which is a part of a program. - programs_user_is_staff_for = ( - UserProgramReadOnlyAccessView().get_programs_user_is_course_staff_for( - user, requested_program_type - ) - ) - for staff_program in programs_user_is_staff_for: - program_dict.setdefault(staff_program["uuid"], staff_program) - - # Now get the program enrollments for user purely as a learner add to the list - enrolled_programs = ( - UserProgramReadOnlyAccessView()._get_enrolled_programs_from_model(user) - ) - for learner_program in enrolled_programs: - program_dict.setdefault(learner_program["uuid"], learner_program) - - programs = list(program_dict.values()) - enrolled_programs = len(programs) + meter = ProgramProgressMeter(request.site, user, mobile_only=False) + engaged_programs = meter.engaged_programs + no_of_programs = len(meter.engaged_programs) ############ COURSES COUNT ############ username = user.username @@ -124,7 +100,6 @@ def get(self, request): data={ "watch_hours": watch_time, "enrolled_courses": enrolled_courses, - "enrolled_programs": enrolled_programs, + "enrolled_programs": no_of_programs, }, ) -