diff --git a/erpnext/education/doctype/course_enrollment/course_enrollment.py b/erpnext/education/doctype/course_enrollment/course_enrollment.py index 2a2837dcf86..b57745f392c 100644 --- a/erpnext/education/doctype/course_enrollment/course_enrollment.py +++ b/erpnext/education/doctype/course_enrollment/course_enrollment.py @@ -20,7 +20,7 @@ class CourseEnrollment(Document): topics = course.get_topics() progress = [] for topic in topics: - progress.append(student.get_topic_progress(self.name, topic)) + progress.append(student.get_topic_progress(self.name, topic)) return reduce(lambda x,y: x+y, progress) # Flatten out the List def validate_duplication(self): diff --git a/erpnext/education/utils.py b/erpnext/education/utils.py index 7a61ae51519..93b44e92bde 100644 --- a/erpnext/education/utils.py +++ b/erpnext/education/utils.py @@ -68,7 +68,7 @@ def get_current_student(): student_id = frappe.get_all("Student", {"student_email_id": email}, ["name"])[0].name return frappe.get_doc("Student", student_id) except (IndexError, frappe.DoesNotExistError): - frappe.throw(_("Student with email {0} does not exist.".format(email))) + return None def check_super_access(): current_user = frappe.get_doc('User', frappe.session.user) @@ -83,7 +83,7 @@ def get_program_enrollment(program_name): if not student: return None else: - enrollment = frappe.get_all("Program Enrollment", filters={'student':student, 'program': program_name}) + enrollment = frappe.get_all("Program Enrollment", filters={'student':student.name, 'program': program_name}) if enrollment: return enrollment[0].name else: @@ -96,7 +96,7 @@ def get_program_and_enrollment_status(program_name): def get_course_enrollment(course_name): student = get_current_student() - enrollment_name = frappe.get_all("Course Enrollment", filters={'student': student, 'course':course_name}) + enrollment_name = frappe.get_all("Course Enrollment", filters={'student': student.name, 'course':course_name}) try: name = enrollment_name[0].name enrollment = frappe.get_doc("Course Enrollment", name) @@ -118,8 +118,7 @@ def create_student_from_current_user(): return student def enroll_in_course(course_name, program_name): - student_id = get_current_student() - student = frappe.get_doc("Student", student_id) + student = get_current_student() return student.enroll_in_course(course_name=course_name, program_enrollment=get_program_enrollment(program_name)) def check_activity_exists(enrollment, content_type, content): diff --git a/erpnext/www/lms.py b/erpnext/www/lms.py index 85a4c58c99e..f6695439c59 100644 --- a/erpnext/www/lms.py +++ b/erpnext/www/lms.py @@ -91,15 +91,17 @@ def get_quiz_without_answers(quiz_name, course_name): return None enrollment = utils.get_course_enrollment(course_name).name - quiz_status = {} - quiz_status['is_complete'], quiz_status['score'], quiz_status['result'] = utils.check_quiz_completion(quiz, enrollment) + quiz_progress = {} + quiz_progress['is_complete'], quiz_progress['score'], quiz_progress['result'] = utils.check_quiz_completion(quiz, enrollment) quiz_output = [{'name':question.name, 'question':question.question, 'type': question.type, 'options':[{'name': option.name, 'option':option.option} for option in question.options]} for question in questions] - return { 'quizData': quiz_output, 'status': quiz_status} + return { 'quizData': quiz_output, 'status': quiz_progress} @frappe.whitelist() def evaluate_quiz(course, quiz_response, quiz_name): """LMS Function: Evaluates a simple multiple choice quiz. + :param course: name of the course :param quiz_response: contains user selected choices for a quiz in the form of a string formatted as a dictionary. The function uses `json.loads()` to convert it to a python dictionary. + :param quiz_name: Name of the quiz attempted """ import json quiz_response = json.loads(quiz_response)