From b7d93c1b50b4851111f87ad43a07c000a504069a Mon Sep 17 00:00:00 2001 From: pateljannat Date: Tue, 4 May 2021 16:50:39 +0530 Subject: [PATCH] fix: get_mentors in batch --- community/lms/doctype/lms_batch/lms_batch.py | 11 +++++++++++ community/lms/doctype/lms_course/lms_course.py | 16 +--------------- community/www/courses/course.html | 2 +- community/www/courses/learn/index.py | 2 -- 4 files changed, 13 insertions(+), 18 deletions(-) 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 @@
Starting {{frappe.utils.format_date(batch.start_date, "medium")}}
mentors
- {% for m in batch.mentors %} + {% for m in batch.get_mentors() %}
{% if m.photo_url %} diff --git a/community/www/courses/learn/index.py b/community/www/courses/learn/index.py index b69083d4..6219b647 100644 --- a/community/www/courses/learn/index.py +++ b/community/www/courses/learn/index.py @@ -6,5 +6,3 @@ def get_context(context): context.course = frappe.form_dict["course"] context.batch_code = frappe.form_dict["batch"] redirect_if_not_a_member(context.course, context.batch_code) - - print(context) \ No newline at end of file