From c8817d29b16f2111abf8961cf8e141027187df17 Mon Sep 17 00:00:00 2001 From: Shadi Naif Date: Sat, 16 Nov 2024 20:04:16 +0300 Subject: [PATCH] feat: apply removable annotations on applicable querysets --- futurex_openedx_extensions/dashboard/details/courses.py | 9 +++++++++ futurex_openedx_extensions/dashboard/details/learners.py | 7 +++++++ futurex_openedx_extensions/helpers/querysets.py | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/futurex_openedx_extensions/dashboard/details/courses.py b/futurex_openedx_extensions/dashboard/details/courses.py index 30cdf574..116998a3 100644 --- a/futurex_openedx_extensions/dashboard/details/courses.py +++ b/futurex_openedx_extensions/dashboard/details/courses.py @@ -29,6 +29,7 @@ check_staff_exist_queryset, get_base_queryset_courses, get_one_user_queryset, + update_removable_annotations, ) @@ -62,6 +63,8 @@ def annotate_courses_rating_queryset( ), 0), ) + update_removable_annotations(queryset, removable=['rating_count', 'rating_total']) + return queryset @@ -144,6 +147,10 @@ def get_courses_queryset( ) ) + update_removable_annotations(queryset, removable=[ + 'enrolled_count', 'active_count', 'certificates_count', 'completion_rate', + ]) + return queryset @@ -216,4 +223,6 @@ def get_learner_courses_info_queryset( ) ) + update_removable_annotations(queryset, removable=['related_user_id', 'enrollment_date', 'last_activity']) + return queryset diff --git a/futurex_openedx_extensions/dashboard/details/learners.py b/futurex_openedx_extensions/dashboard/details/learners.py index 78bb666c..2608c155 100644 --- a/futurex_openedx_extensions/dashboard/details/learners.py +++ b/futurex_openedx_extensions/dashboard/details/learners.py @@ -17,6 +17,7 @@ get_learners_search_queryset, get_one_user_queryset, get_permitted_learners_queryset, + update_removable_annotations, ) @@ -141,6 +142,8 @@ def get_learners_queryset( ) ).select_related('profile', 'extrainfo').order_by('id') + update_removable_annotations(queryset, removable=['courses_count', 'certificates_count']) + return queryset @@ -202,6 +205,8 @@ def get_learners_by_course_queryset( ) ).select_related('profile').order_by('id') + update_removable_annotations(queryset, removable=['certificate_available', 'course_score', 'active_in_course']) + return queryset @@ -249,4 +254,6 @@ def get_learner_info_queryset( ) ).select_related('profile') + update_removable_annotations(queryset, removable=['courses_count', 'certificates_count']) + return queryset diff --git a/futurex_openedx_extensions/helpers/querysets.py b/futurex_openedx_extensions/helpers/querysets.py index fadf21b6..46bac78b 100644 --- a/futurex_openedx_extensions/helpers/querysets.py +++ b/futurex_openedx_extensions/helpers/querysets.py @@ -173,11 +173,15 @@ def get_base_queryset_courses( ), ) + update_removable_annotations(q_set, removable=['course_is_active', 'course_is_visible']) + if active_filter is not None: q_set = q_set.filter(course_is_active=active_filter) + update_removable_annotations(q_set, not_removable=['course_is_active']) if visible_filter is not None: q_set = q_set.filter(course_is_visible=visible_filter) + update_removable_annotations(q_set, not_removable=['course_is_visible']) return q_set