Quiz is now submittable

This commit is contained in:
scmmishra 2018-11-02 13:15:49 +05:30 committed by Aditya Hase
parent cfc35f4424
commit f7029f084c
2 changed files with 35 additions and 3 deletions

View File

@ -6,7 +6,6 @@
<h2>{{ content }}</h2>
</div>
</div>
{{ quizResponse }}
<div class="content">
<hr>
<form id="quiz" :name="content">
@ -16,7 +15,7 @@
<div class="mt-3">
<div id="quiz-actions" class="text-right">
<button class='btn btn-outline-secondary' type="reset">Reset</button>
<button class='btn btn-primary' type="button">Submit</button>
<button class='btn btn-primary' @click="submitQuiz" type="button">Submit</button>
</div>
<div id="post-quiz-actions" class="row" hidden="hidden">
<div class="col-md-8 text-left">
@ -64,6 +63,14 @@ export default {
methods: {
updateResponse(res) {
this.quizResponse[res.question] = (res.option)
},
submitQuiz() {
frappe.call({
method: "erpnext.www.academy.evaluate_quiz",
args: {
quiz_response: this.quizResponse;
}
})
}
}
};

View File

@ -79,4 +79,29 @@ def get_quiz_without_answers(quiz_name):
return quiz_output
except:
frappe.throw("Quiz {0} does not exist".format(quiz_name))
return None
return None
@frappe.whitelist()
def evaluate_quiz(quiz_response):
"""LMS Function: Evaluates a simple multiple choice quiz. It recieves arguments from `www/lms/course.js` as dictionary using FormData[1].
: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.
[1]: https://developer.mozilla.org/en-US/docs/Web/API/FormData
"""
import json
print("---------------------------")
print(quiz_response)
quiz_response = json.loads(quiz_response)
print(type(quiz_response))
# quiz_name = kwargs.get('quiz')
# course_name = kwargs.get('course')
# enrollment = get_course_enrollment(course_name, frappe.session.user)
# try:
# quiz = frappe.get_doc("Quiz", quiz_name)
# answers, score = quiz.evaluate(quiz_response, enrollment, quiz_name)
# add_quiz_activity(enrollment, quiz_name, score, answers, quiz_response)
# return score
# except frappe.DoesNotExistError:
# frappe.throw("Quiz {0} does not exist".format(quiz_name))
# return None