diff --git a/community/lms/doctype/lms_batch/lms_batch.py b/community/lms/doctype/lms_batch/lms_batch.py index 5d26ef49..7fc547f3 100644 --- a/community/lms/doctype/lms_batch/lms_batch.py +++ b/community/lms/doctype/lms_batch/lms_batch.py @@ -17,6 +17,17 @@ class LMSBatch(Document): course_batches = frappe.get_all("LMS Batch",{"course":self.course}) self.code = short_code + str(len(course_batches) + 1) + def get_mentors(self): + mentors = [] + memberships = frappe.get_all( + "LMS Batch Membership", + {"batch": self.name, "member_type": "Mentor"}, + ["member"]) + for membership in memberships: + member = frappe.db.get_value("Community Member", membership.member, ["full_name", "photo", "abbr"], as_dict=1) + mentors.append(member) + return mentors + @frappe.whitelist() def get_messages(batch): messages = frappe.get_all("LMS Message", {"batch": batch}, ["*"], order_by="creation") diff --git a/community/lms/doctype/lms_course/lms_course.py b/community/lms/doctype/lms_course/lms_course.py index 6ff80f45..51e8b381 100644 --- a/community/lms/doctype/lms_course/lms_course.py +++ b/community/lms/doctype/lms_course/lms_course.py @@ -133,27 +133,13 @@ class LMSCourse(Document): {"member": member}, ["batch"]) batch_names = {m.batch for m in memberships} - mentor_batches = [b for b in batches if b.name in batch_names] - return self.get_batch_mentors(mentor_batches) + return [b for b in batches if b.name in batch_names] def get_upcoming_batches(self): now = frappe.utils.nowdate() batches = find_all("LMS Batch", course=self.name, start_date=[">", now]) - batches = self.get_batch_mentors(batches) - return batches - - def get_batch_mentors(self, batches): - for batch in batches: - batch.mentors = [] - mentors = frappe.get_all( - "LMS Batch Membership", - {"batch": batch.name, "member_type": "Mentor"}, - ["member"]) - for mentor in mentors: - member = frappe.db.get_value("Community Member", mentor.member, ["full_name", "photo", "abbr"], as_dict=1) - batch.mentors.append(member) return batches def find_all(doctype, order_by=None, **filters): diff --git a/community/www/courses/course.html b/community/www/courses/course.html index 23e82643..3c08fc97 100644 --- a/community/www/courses/course.html +++ b/community/www/courses/course.html @@ -74,7 +74,7 @@