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

View File

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