refactor: fetch minimal information for batch cards

This commit is contained in:
Jannat Patel
2025-01-06 12:05:29 +05:30
parent 4d8b2eb5b4
commit bd2b558154

View File

@@ -1030,6 +1030,7 @@ def get_course_details(course):
course_details.tags = course_details.tags.split(",") if course_details.tags else [] course_details.tags = course_details.tags.split(",") if course_details.tags else []
course_details.instructors = get_instructors(course_details.name) course_details.instructors = get_instructors(course_details.name)
# course_details.is_instructor = is_instructor(course_details.name)
if course_details.paid_course: if course_details.paid_course:
"""course_details.course_price, course_details.currency = check_multicurrency( """course_details.course_price, course_details.currency = check_multicurrency(
course_details.course_price, course_details.currency, None, course_details.amount_usd 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"], ["name", "course", "current_lesson", "progress", "member"],
as_dict=1, as_dict=1,
) )
course_details.is_instructor = is_instructor(course_details.name)
if course_details.membership and course_details.membership.current_lesson: if course_details.membership and course_details.membership.current_lesson:
course_details.current_lesson = get_lesson_index( course_details.current_lesson = get_lesson_index(
@@ -1219,12 +1219,49 @@ def get_batches():
batch_list = frappe.get_all("LMS Batch", filters) batch_list = frappe.get_all("LMS Batch", filters)
for batch in batch_list: for batch in batch_list:
batches.append(get_batch_details(batch.name)) batches.append(get_batch_card_details(batch.name))
batches = categorize_batches(batches) batches = categorize_batches(batches)
return 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) @frappe.whitelist(allow_guest=True)
def get_batch_details(batch): def get_batch_details(batch):
batch_details = frappe.db.get_value( batch_details = frappe.db.get_value(