From 5ad89189c1cb6df5f00865ad8a20b218d0f6a24a Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 29 May 2025 16:09:51 +0530 Subject: [PATCH] fix: changed certified members count based on filters --- frontend/src/pages/CertifiedParticipants.vue | 12 ++++++++---- lms/lms/api.py | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/frontend/src/pages/CertifiedParticipants.vue b/frontend/src/pages/CertifiedParticipants.vue index b7d0de83..3fca3407 100644 --- a/frontend/src/pages/CertifiedParticipants.vue +++ b/frontend/src/pages/CertifiedParticipants.vue @@ -127,6 +127,7 @@ const memberCount = ref(0) const dayjs = inject('$dayjs') onMounted(() => { + getMemberCount() updateParticipants() }) @@ -138,11 +139,13 @@ const participants = createListResource({ pageLength: 30, }) -const count = call('lms.lms.api.get_count_of_certified_members').then( - (data) => { +const getMemberCount = () => { + call('lms.lms.api.get_count_of_certified_members', { + filters: filters.value, + }).then((data) => { memberCount.value = data - } -) + }) +} const categories = createListResource({ doctype: 'LMS Certificate', @@ -157,6 +160,7 @@ const categories = createListResource({ const updateParticipants = () => { updateFilters() + getMemberCount() participants.update({ filters: filters.value, }) diff --git a/lms/lms/api.py b/lms/lms/api.py index 7e540a4d..12c122cb 100644 --- a/lms/lms/api.py +++ b/lms/lms/api.py @@ -457,7 +457,7 @@ class CountDistinct(DistinctOptionFunction): @frappe.whitelist(allow_guest=True) -def get_count_of_certified_members(): +def get_count_of_certified_members(filters=None): Certificate = DocType("LMS Certificate") query = ( @@ -466,6 +466,14 @@ def get_count_of_certified_members(): .where(Certificate.published == 1) ) + if filters: + for field, value in filters.items(): + if field == "category": + query = query.where( + Certificate.course_title.like(f"%{value}%") + | Certificate.batch_title.like(f"%{value}%") + ) + result = query.run(as_dict=True) return result[0]["total"] if result else 0 @@ -691,13 +699,13 @@ def get_categories(doctype, filters): @frappe.whitelist() def get_members(start=0, search=""): """Get members for the given search term and start index. - Args: start (int): Start index for the query. + Args: start (int): Start index for the query. <<<<<<< HEAD - search (str): Search term to filter the results. + search (str): Search term to filter the results. ======= - search (str): Search term to filter the results. + search (str): Search term to filter the results. >>>>>>> 4869bba7bbb2fb38477d6fc29fb3b5838e075577 - Returns: List of members. + Returns: List of members. """ filters = {"enabled": 1, "name": ["not in", ["Administrator", "Guest"]]}