feat: added ability to find the batch of a student

Added the course field and member_email fields to LMS Batch Membership
to allow the possibility of querying if a user is a student of a course.

Closes #101
This commit is contained in:
Anand Chitipothu
2021-05-24 09:52:59 +05:30
parent 4a2ecff15d
commit 38938ac14b
2 changed files with 33 additions and 23 deletions

View File

@@ -6,11 +6,13 @@
"engine": "InnoDB",
"field_order": [
"batch",
"role",
"column_break_3",
"member",
"member_name",
"member_type"
"member_email",
"column_break_3",
"course",
"member_type",
"role"
],
"fields": [
{
@@ -30,6 +32,7 @@
"options": "Community Member"
},
{
"default": "Student",
"fieldname": "member_type",
"fieldtype": "Select",
"in_list_view": 1,
@@ -37,6 +40,7 @@
"options": "\nStudent\nMentor\nStaff"
},
{
"default": "Member",
"fieldname": "role",
"fieldtype": "Select",
"in_standard_filter": 1,
@@ -54,11 +58,28 @@
{
"fieldname": "column_break_3",
"fieldtype": "Column Break"
},
{
"fetch_from": "member.email",
"fieldname": "member_email",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Member Email",
"read_only": 1,
"read_only_depends_on": "member.email"
},
{
"fetch_from": "batch.course",
"fieldname": "course",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Course",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-04-26 12:52:59.826509",
"modified": "2021-05-24 09:32:04.128620",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Batch Membership",

View File

@@ -109,28 +109,17 @@ class LMSCourse(Document):
Returns None if the student is not part of any batch.
"""
if not email:
return False
member = self.get_community_member(email)
result = frappe.db.get_all(
"LMS Batch Membership",
filters={
"member": member,
"member_type": "Student",
},
fields=['batch']
)
batches = [row['batch'] for row in result]
return
# filter the batches that are for this course
result = frappe.db.get_all(
"LMS Batch",
batch_name = frappe.get_value(
doctype="LMS Batch Membership",
filters={
"course": self.name,
"name": ["IN", batches]
})
batches = [row['name'] for row in result]
if batches:
return frappe.get_doc("LMS Batch", batches[0])
"member_type": "Student",
"member_email": email
},
fieldname="batch")
return batch_name and frappe.get_doc("LMS Batch", batch_name)
def get_instructor(self):
member_name = self.get_community_member(self.owner)