915b34391c
* chore: Added isort to pre-commit config * chore: Sort imports with isort * chore: Clean up imports with pycln * chore: Sort imports with isort * chore: Fix import issues * chore: Clean up sider issues * chore: Remove import errors from flake8 ignore list * chore: Clean up lint issues
32 lines
988 B
Python
32 lines
988 B
Python
from __future__ import unicode_literals
|
|
|
|
import frappe
|
|
from frappe import _
|
|
|
|
import erpnext.education.utils as utils
|
|
|
|
no_cache = 1
|
|
|
|
def get_context(context):
|
|
try:
|
|
program = frappe.form_dict['program']
|
|
except KeyError:
|
|
frappe.local.flags.redirect_location = '/lms'
|
|
raise frappe.Redirect
|
|
|
|
context.education_settings = frappe.get_single("Education Settings")
|
|
context.program = get_program(program)
|
|
context.courses = [frappe.get_doc("Course", course.course) for course in context.program.courses]
|
|
context.has_access = utils.allowed_program_access(program)
|
|
context.progress = get_course_progress(context.courses, context.program)
|
|
|
|
def get_program(program_name):
|
|
try:
|
|
return frappe.get_doc('Program', program_name)
|
|
except frappe.DoesNotExistError:
|
|
frappe.throw(_("Program {0} does not exist.").format(program_name))
|
|
|
|
def get_course_progress(courses, program):
|
|
progress = {course.name: utils.get_course_progress(course, program) for course in courses}
|
|
return progress or {}
|