brotherton-erpnext/erpnext/www/lms/profile.py

38 lines
960 B
Python
Raw Normal View History

2019-06-05 11:59:48 +00:00
import frappe
import erpnext.education.utils as utils
2019-06-05 11:59:48 +00:00
no_cache = 1
2022-03-28 13:22:46 +00:00
2019-06-05 11:59:48 +00:00
def get_context(context):
if frappe.session.user == "Guest":
2022-03-28 13:22:46 +00:00
frappe.local.flags.redirect_location = "/lms"
raise frappe.Redirect
2019-06-05 11:59:48 +00:00
context.student = utils.get_current_student()
if not context.student:
2022-03-28 13:22:46 +00:00
context.student = frappe.get_doc("User", frappe.session.user)
2019-06-05 11:59:48 +00:00
context.progress = get_program_progress(context.student.name)
2022-03-28 13:22:46 +00:00
2019-06-05 11:59:48 +00:00
def get_program_progress(student):
2022-03-28 13:22:46 +00:00
enrolled_programs = frappe.get_all(
"Program Enrollment", filters={"student": student}, fields=["program"]
)
2019-06-05 11:59:48 +00:00
student_progress = []
for list_item in enrolled_programs:
program = frappe.get_doc("Program", list_item.program)
progress = utils.get_program_progress(program)
completion = utils.get_program_completion(program)
2022-03-28 13:22:46 +00:00
student_progress.append(
{
"program": program.program_name,
"name": program.name,
"progress": progress,
"completion": completion,
}
)
2019-06-05 11:59:48 +00:00
return student_progress