feat: quiz marks and passing percentage

This commit is contained in:
Jannat Patel
2023-10-17 20:06:04 +05:30
parent 12bec14c92
commit 0111ff9c99
15 changed files with 210 additions and 47 deletions

View File

@@ -7,7 +7,7 @@ def get_context(context):
context.no_cache = 1
if frappe.session.user == "Guest":
raise frappe.PermissionError(_("You don't have permission to access this page."))
raise frappe.PermissionError(_("Please login to submit the assignment."))
context.is_moderator = has_course_moderator_role()
submission = frappe.form_dict["submission"]

View File

@@ -429,9 +429,9 @@ class Quiz {
}
render_quiz(quiz) {
return `<div class="common-card-style p-2 my-2 bold-heading">
return `<a class="common-card-style p-20 my-2 justify-center bold-heading" target="_blank" href=/quizzes/${quiz}>
Quiz: ${quiz}
</div>`;
</a>`;
}
validate(savedData) {

View File

@@ -21,11 +21,12 @@
<div class="field-label mb-1">
{{ _("Questions") }}
</div>
<div class="common-card-style column-card px-3 py-0">
<div class="questions-table"></div>
<!-- <div class="common-card-style column-card px-3 py-0">
{% for question in quiz.questions %}
{{ Question(question, loop.index) }}
{% endfor %}
</div>
</div> -->
<button class="btn btn-secondary btn-sm btn-add-question mt-4">
{{ _("Add Question") }}
</button>
@@ -109,7 +110,7 @@
<input type="checkbox" id="show-answers" {% if show_answers %} checked {% endif %}>
{{ _("Show Answers") }}
</label>
<label for="upcoming" class="vertically-center mb-0 ml-20">
<label for="show-submission-history" class="vertically-center mb-0 ml-20">
<input type="checkbox" id="show-submission-history" {% if quiz.show_submission_history %} checked {% endif %}>
{{ _("Show Submission History") }}
</label>
@@ -151,5 +152,9 @@
{%- block script %}
{{ super() }}
{{ include_script('controls.bundle.js') }}
{% if has_course_instructor_role() or has_course_moderator_role() %}
<script>
const quiz_questions = {{ quiz.questions }}
</script>
{% endif %}
{% endblock %}

View File

@@ -1,4 +1,10 @@
frappe.ready(() => {
if ($(".questions-table").length) {
frappe.require("controls.bundle.js", () => {
create_questions_table();
});
}
$(".btn-save-quiz").click((e) => {
save_quiz({
quiz_title: $("#quiz-title").val(),
@@ -177,3 +183,52 @@ const save_question = (values) => {
},
});
};
const create_questions_table = () => {
this.table = new frappe.ui.FieldGroup({
fields: [
{
fieldname: "questions",
fieldtype: "Table",
in_place_edit: 1,
fields: [
{
fieldname: "question",
fieldtype: "Link",
label: "Question",
options: "LMS Question",
in_list_view: 1,
only_select: 1,
},
{
fieldname: "marks",
fieldtype: "Int",
label: "Marks",
in_list_view: 1,
},
],
},
],
body: $(".questions-table").get(0),
});
this.table.make();
$(".questions-table .form-section:last").removeClass("empty-section");
$(".questions-table .frappe-control").removeClass("hide-control");
$(".questions-table .form-column").addClass("p-0");
add_question_rows();
};
const add_question_rows = () => {
console.log("add rows");
/* let questions_rows = []
quiz_questions.forEach((question, idx) => {
let row = {};
this.table.fields_dict["questions"].grid.add_new_row();
row["question"] = question.question;
row["marks"] = question.marks;
questions_rows.push(row)
});
console.log(questions_rows) */
this.table.set_value("questions", quiz_questions);
this.table.refresh();
};

View File

@@ -18,7 +18,6 @@ def get_context(context):
if quizname == "new-quiz":
context.quiz = frappe._dict()
else:
fields_arr = ["name", "question", "type"]
context.quiz = frappe.db.get_value(
"LMS Quiz",
@@ -26,6 +25,8 @@ def get_context(context):
["title", "name", "max_attempts", "show_answers", "show_submission_history"],
as_dict=1,
)
fields_arr = ["name", "question", "marks"]
context.quiz.questions = frappe.get_all(
"LMS Quiz Question", {"parent": quizname}, fields_arr, order_by="idx"
)