From 38938ac14b7e301413384466ab96cf5edb7882f5 Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Mon, 24 May 2021 09:52:59 +0530 Subject: [PATCH 1/2] 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 --- .../lms_batch_membership.json | 29 ++++++++++++++++--- .../lms/doctype/lms_course/lms_course.py | 27 +++++------------ 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/community/lms/doctype/lms_batch_membership/lms_batch_membership.json b/community/lms/doctype/lms_batch_membership/lms_batch_membership.json index 02352fdc..67c41497 100644 --- a/community/lms/doctype/lms_batch_membership/lms_batch_membership.json +++ b/community/lms/doctype/lms_batch_membership/lms_batch_membership.json @@ -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", diff --git a/community/lms/doctype/lms_course/lms_course.py b/community/lms/doctype/lms_course/lms_course.py index 07e29145..495efaf2 100644 --- a/community/lms/doctype/lms_course/lms_course.py +++ b/community/lms/doctype/lms_course/lms_course.py @@ -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) From 8d7963fc60111dceb5e1d623d9a0c11b000b4804 Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Mon, 24 May 2021 09:55:35 +0530 Subject: [PATCH 2/2] feat: added "Resume Course" button to course teaser Closes #102 --- community/lms/widgets/CourseTeaser.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/community/lms/widgets/CourseTeaser.html b/community/lms/widgets/CourseTeaser.html index 029db9ae..64ecb5ec 100644 --- a/community/lms/widgets/CourseTeaser.html +++ b/community/lms/widgets/CourseTeaser.html @@ -6,6 +6,10 @@