feat: Quizzes fixed

This commit is contained in:
scmmishra 2019-02-28 16:42:25 +05:30
parent 3726f8a7f6
commit ab8fc8c2bf
2 changed files with 4 additions and 3 deletions

View File

@ -73,9 +73,9 @@ export default {
submitQuiz() { submitQuiz() {
lms.call("evaluate_quiz", lms.call("evaluate_quiz",
{ {
enrollment: lms.store.enrolledCourses[this.$route.params.course],
quiz_response: this.quizResponse, quiz_response: this.quizResponse,
quiz_name: this.content quiz_name: this.content,
course: this.$route.params.course_name
} }
).then(data => { ).then(data => {
this.score = data, this.score = data,

View File

@ -101,13 +101,14 @@ def get_quiz_without_answers(quiz_name):
return None return None
@frappe.whitelist() @frappe.whitelist()
def evaluate_quiz(enrollment, quiz_response, quiz_name): def evaluate_quiz(course, quiz_response, quiz_name):
"""LMS Function: Evaluates a simple multiple choice quiz. """LMS Function: Evaluates a simple multiple choice quiz.
: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_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.
""" """
import json import json
quiz_response = json.loads(quiz_response) quiz_response = json.loads(quiz_response)
quiz = frappe.get_doc("Quiz", quiz_name) quiz = frappe.get_doc("Quiz", quiz_name)
enrollment = utils.get_course_enrollment(course).name
answers, score, status = quiz.evaluate(quiz_response, quiz_name) answers, score, status = quiz.evaluate(quiz_response, quiz_name)
result = {k: ('Correct' if v else 'Wrong') for k,v in answers.items()} result = {k: ('Correct' if v else 'Wrong') for k,v in answers.items()}