feat: redirect the course page to learn page when the visitor is a student of a batch

This commit is contained in:
Anand Chitipothu
2021-05-14 12:06:37 +05:30
parent 5cfb72a731
commit 1cf57c4823
2 changed files with 34 additions and 0 deletions

View File

@@ -114,6 +114,35 @@ class LMSCourse(Document):
"mentor": member
})
def get_student_batch(self, email):
"""Returns the batch the given student is part of.
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]
# filter the batches that are for this course
result = frappe.db.get_all(
"LMS Batch",
filters={
"course": self.name,
"name": ["IN", batches]
})
batches = [row['name'] for row in result]
if batches:
return frappe.get_doc("LMS Batch", batches[0])
def get_instructor(self):
member_name = self.get_community_member(self.owner)
return frappe.get_doc("Community Member", member_name)

View File

@@ -19,3 +19,8 @@ def get_context(context):
context.course = course
batch = course.get_student_batch(frappe.session.user)
if batch:
frappe.local.flags.redirect_location = f"/courses/{course.name}/{batch.name}/learn"
raise frappe.Redirect