refactor: refactored the about page

This commit is contained in:
Anand Chitipothu
2021-05-06 06:48:37 +05:30
parent dc5b637ada
commit 761f36519e
5 changed files with 61 additions and 36 deletions

View File

@@ -1,21 +1,21 @@
import frappe
from community.www.courses.utils import redirect_if_not_a_member, get_course, get_instructor, get_batch
from community.lms.models import Course
def get_context(context):
context.no_cache = 1
context.course_slug = frappe.form_dict["course"]
context.course = get_course(context.course_slug)
context.batch_code = frappe.form_dict["batch"]
redirect_if_not_a_member(context.course_slug, context.batch_code)
context.instructor = get_instructor(context.course.owner)
context.batch = get_batch(context.batch_code)
context.mentors = get_mentors(context.batch.name)
course_name = frappe.form_dict["course"]
batch_name = frappe.form_dict["batch"]
def get_mentors(batch):
mentors = []
memberships = frappe.get_all("LMS Batch Membership", {"batch": batch, "member_type": "Mentor"}, ["member"])
for membership in memberships:
member = frappe.get_doc("Community Member", membership.member)
mentors.append(member)
return mentors
course = Course.find(course_name)
if not course:
context.template = "www/404.html"
return
batch = course.get_batch(batch_name)
if not batch:
frappe.local.flags.redirect_location = "/courses/" + course_name
raise frappe.Redirect
context.course = course
context.batch = batch