2019-06-05 14:12:30 +00:00
|
|
|
import frappe
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
import erpnext.education.utils as utils
|
|
|
|
|
2019-06-05 14:12:30 +00:00
|
|
|
no_cache = 1
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2019-06-05 14:12:30 +00:00
|
|
|
def get_context(context):
|
2019-06-12 10:31:02 +00:00
|
|
|
try:
|
2022-03-28 13:22:46 +00:00
|
|
|
course = frappe.form_dict["course"]
|
|
|
|
program = frappe.form_dict["program"]
|
|
|
|
topic = frappe.form_dict["topic"]
|
2019-06-12 10:31:02 +00:00
|
|
|
except KeyError:
|
2022-03-28 13:22:46 +00:00
|
|
|
frappe.local.flags.redirect_location = "/lms"
|
2019-06-12 10:31:02 +00:00
|
|
|
raise frappe.Redirect
|
2019-06-05 14:12:30 +00:00
|
|
|
|
|
|
|
context.program = program
|
|
|
|
context.course = course
|
|
|
|
context.topic = frappe.get_doc("Topic", topic)
|
|
|
|
context.contents = get_contents(context.topic, course, program)
|
2022-03-28 13:22:46 +00:00
|
|
|
context.has_access = utils.allowed_program_access(program)
|
|
|
|
|
2019-06-05 14:12:30 +00:00
|
|
|
|
|
|
|
def get_contents(topic, course, program):
|
|
|
|
student = utils.get_current_student()
|
2019-06-06 08:32:49 +00:00
|
|
|
if student:
|
|
|
|
course_enrollment = utils.get_or_create_course_enrollment(course, program)
|
2019-06-05 14:12:30 +00:00
|
|
|
contents = topic.get_contents()
|
|
|
|
progress = []
|
|
|
|
if contents:
|
|
|
|
for content in contents:
|
2022-03-28 13:22:46 +00:00
|
|
|
if content.doctype in ("Article", "Video"):
|
2019-06-06 08:32:49 +00:00
|
|
|
if student:
|
|
|
|
status = utils.check_content_completion(content.name, content.doctype, course_enrollment.name)
|
|
|
|
else:
|
|
|
|
status = True
|
2022-03-28 13:22:46 +00:00
|
|
|
progress.append({"content": content, "content_type": content.doctype, "completed": status})
|
|
|
|
elif content.doctype == "Quiz":
|
2019-06-06 08:32:49 +00:00
|
|
|
if student:
|
2022-03-28 13:22:46 +00:00
|
|
|
status, score, result, time_taken = utils.check_quiz_completion(
|
|
|
|
content, course_enrollment.name
|
|
|
|
)
|
2019-06-06 08:32:49 +00:00
|
|
|
else:
|
|
|
|
status = False
|
|
|
|
score = None
|
|
|
|
result = None
|
2022-03-28 13:22:46 +00:00
|
|
|
progress.append(
|
|
|
|
{
|
|
|
|
"content": content,
|
|
|
|
"content_type": content.doctype,
|
|
|
|
"completed": status,
|
|
|
|
"score": score,
|
|
|
|
"result": result,
|
|
|
|
}
|
|
|
|
)
|
2019-06-05 14:12:30 +00:00
|
|
|
|
2021-08-19 08:11:10 +00:00
|
|
|
return progress
|