From bd2b558154ed1ea50950bfa0d6b8e30ee98e97b2 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Mon, 6 Jan 2025 12:05:29 +0530 Subject: [PATCH] refactor: fetch minimal information for batch cards --- lms/lms/utils.py | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/lms/lms/utils.py b/lms/lms/utils.py index 4438a81a..75b7da13 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -1030,6 +1030,7 @@ def get_course_details(course): course_details.tags = course_details.tags.split(",") if course_details.tags else [] course_details.instructors = get_instructors(course_details.name) + # course_details.is_instructor = is_instructor(course_details.name) if course_details.paid_course: """course_details.course_price, course_details.currency = check_multicurrency( course_details.course_price, course_details.currency, None, course_details.amount_usd @@ -1048,7 +1049,6 @@ def get_course_details(course): ["name", "course", "current_lesson", "progress", "member"], as_dict=1, ) - course_details.is_instructor = is_instructor(course_details.name) if course_details.membership and course_details.membership.current_lesson: course_details.current_lesson = get_lesson_index( @@ -1219,12 +1219,49 @@ def get_batches(): batch_list = frappe.get_all("LMS Batch", filters) for batch in batch_list: - batches.append(get_batch_details(batch.name)) + batches.append(get_batch_card_details(batch.name)) batches = categorize_batches(batches) return batches +def get_batch_card_details(batchname): + batch = frappe.db.get_value( + "LMS Batch", + batchname, + [ + "name", + "title", + "description", + "seat_count", + "paid_batch", + "amount", + "amount_usd", + "currency", + "start_date", + "start_time", + "end_time", + "timezone", + "published", + ], + as_dict=True, + ) + + batch.instructors = get_instructors(batchname) + students_count = frappe.db.count("Batch Student", {"parent": batchname}) + + if batch.seat_count: + batch.seats_left = batch.seat_count - students_count + + if batch.paid_batch and batch.start_date >= getdate(): + batch.amount, batch.currency = check_multicurrency( + batch.amount, batch.currency, None, batch.amount_usd + ) + batch.price = fmt_money(batch.amount, 0, batch.currency) + + return batch + + @frappe.whitelist(allow_guest=True) def get_batch_details(batch): batch_details = frappe.db.get_value(