Quiz is now submittable
diff --git a/erpnext/public/js/education/web-academy/components/ContentQuiz.vue b/erpnext/public/js/education/web-academy/components/ContentQuiz.vue
index 3828cdf..b9edb5a 100644
--- a/erpnext/public/js/education/web-academy/components/ContentQuiz.vue
+++ b/erpnext/public/js/education/web-academy/components/ContentQuiz.vue
@@ -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 @@
methods: {
updateResponse(res) {
this.quizResponse[res.question] = (res.option)
+ },
+ submitQuiz() {
+ frappe.call({
+ method: "erpnext.www.academy.evaluate_quiz",
+ args: {
+ quiz_response: this.quizResponse;
+ }
+ })
}
}
};
diff --git a/erpnext/www/academy.py b/erpnext/www/academy.py
index 9a87463..551a60b 100644
--- a/erpnext/www/academy.py
+++ b/erpnext/www/academy.py
@@ -79,4 +79,29 @@
return quiz_output
except:
frappe.throw("Quiz {0} does not exist".format(quiz_name))
- return None
\ No newline at end of file
+ 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
\ No newline at end of file