fix: get_mentors in batch

This commit is contained in:
pateljannat
2021-05-04 16:50:39 +05:30
parent e931ead270
commit b7d93c1b50
4 changed files with 13 additions and 18 deletions

View File

@@ -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")

View File

@@ -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):

View File

@@ -74,7 +74,7 @@
<div>Starting {{frappe.utils.format_date(batch.start_date, "medium")}}</div>
<div class="course-type" style="color: #888; padding: 10px 0px;">mentors</div>
{% for m in batch.mentors %}
{% for m in batch.get_mentors() %}
<div>
{% if m.photo_url %}
<img class="profile-photo" src="{{m.photo_url}}">

View File

@@ -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)