2019-05-19 10:31:45 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
import erpnext.education.utils as utils
|
|
|
|
import frappe
|
2019-06-05 14:13:51 +00:00
|
|
|
from frappe import _
|
2019-05-19 10:31:45 +00:00
|
|
|
|
|
|
|
no_cache = 1
|
|
|
|
|
|
|
|
def get_context(context):
|
2019-06-12 10:31:02 +00:00
|
|
|
try:
|
|
|
|
program = frappe.form_dict['program']
|
|
|
|
except KeyError:
|
|
|
|
frappe.local.flags.redirect_location = '/lms'
|
|
|
|
raise frappe.Redirect
|
|
|
|
|
2019-05-19 10:31:45 +00:00
|
|
|
context.education_settings = frappe.get_single("Education Settings")
|
2019-06-12 10:31:02 +00:00
|
|
|
context.program = get_program(program)
|
2019-06-05 07:38:53 +00:00
|
|
|
context.courses = [frappe.get_doc("Course", course.course) for course in context.program.courses]
|
2019-06-12 10:31:02 +00:00
|
|
|
context.has_access = utils.allowed_program_access(program)
|
2019-06-05 07:38:53 +00:00
|
|
|
context.progress = get_course_progress(context.courses, context.program)
|
2019-05-19 10:31:45 +00:00
|
|
|
|
|
|
|
def get_program(program_name):
|
|
|
|
try:
|
|
|
|
return frappe.get_doc('Program', program_name)
|
|
|
|
except frappe.DoesNotExistError:
|
2020-01-29 09:36:18 +00:00
|
|
|
frappe.throw(_("Program {0} does not exist.").format(program_name))
|
2019-06-05 07:38:53 +00:00
|
|
|
|
|
|
|
def get_course_progress(courses, program):
|
2019-06-05 11:59:48 +00:00
|
|
|
progress = {course.name: utils.get_course_progress(course, program) for course in courses}
|
2019-06-05 07:38:53 +00:00
|
|
|
return progress
|