From 39cf5c7cdd1b5eac2ea3820b5ca79e6446426878 Mon Sep 17 00:00:00 2001 From: mostafanasser2000 Date: Sat, 4 May 2024 23:52:45 +0300 Subject: [PATCH 1/2] Fix issue when user select incorrect answer --- courses/views/homework.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/courses/views/homework.py b/courses/views/homework.py index 4f36ee6..8221fd0 100644 --- a/courses/views/homework.py +++ b/courses/views/homework.py @@ -70,6 +70,7 @@ def process_question_options_multiple_choice_or_checkboxes( if homework.is_scored: correct_indices = question.get_correct_answer_indices() + user_select_choice = True if len(selected_options) > 0 else False for zero_based_index, option in enumerate(possible_answers): index = zero_based_index + 1 is_selected = index in selected_options @@ -84,7 +85,7 @@ def process_question_options_multiple_choice_or_checkboxes( is_correct = index in correct_indices correctly_selected = determine_answer_class( - is_selected, is_correct + is_selected, is_correct, user_select_choice ) processed_answer["correctly_selected_class"] = ( @@ -122,10 +123,10 @@ def extract_selected_options(answer): return result -def determine_answer_class(is_selected: bool, is_correct: bool) -> str: +def determine_answer_class(is_selected: bool, is_correct: bool, user_select_choice) -> str: if is_selected and is_correct: return "option-answer-correct" - if not is_selected and is_correct: + if not is_selected and not user_select_choice and is_correct: return "option-answer-correct" if is_selected and not is_correct: return "option-answer-incorrect" From 75d34b502783ba506970e5796527610b0fc20e66 Mon Sep 17 00:00:00 2001 From: mostafanasser2000 Date: Wed, 15 May 2024 14:28:28 +0300 Subject: [PATCH 2/2] display warning label if user not answer a question --- courses/templates/homework/homework.html | 10 ++++------ courses/views/homework.py | 10 +++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/courses/templates/homework/homework.html b/courses/templates/homework/homework.html index 423da1c..a2ff9df 100644 --- a/courses/templates/homework/homework.html +++ b/courses/templates/homework/homework.html @@ -66,13 +66,11 @@

Questions

Question {{ forloop.counter }}. {{ question.text }} - {% if question.scores_for_correct_answer > 1 %} - ({{ question.scores_for_correct_answer }} points) - {% else %} - ({{ question.scores_for_correct_answer }} point) - {% endif %} + ({{ question.scores_for_correct_answer|pluralize }} point)

- + {% if is_authenticated and disabled and question.question_type == 'MC' and not answer.is_answered%} +

Question not answered

+ {% endif %} {% if question.question_type == 'MC' %} {% for option in answer.options %}
diff --git a/courses/views/homework.py b/courses/views/homework.py index 8221fd0..e3fedd0 100644 --- a/courses/views/homework.py +++ b/courses/views/homework.py @@ -70,7 +70,7 @@ def process_question_options_multiple_choice_or_checkboxes( if homework.is_scored: correct_indices = question.get_correct_answer_indices() - user_select_choice = True if len(selected_options) > 0 else False + is_answered = True if len(selected_options) > 0 else False for zero_based_index, option in enumerate(possible_answers): index = zero_based_index + 1 is_selected = index in selected_options @@ -85,7 +85,7 @@ def process_question_options_multiple_choice_or_checkboxes( is_correct = index in correct_indices correctly_selected = determine_answer_class( - is_selected, is_correct, user_select_choice + is_selected, is_correct ) processed_answer["correctly_selected_class"] = ( @@ -94,7 +94,7 @@ def process_question_options_multiple_choice_or_checkboxes( options.append(processed_answer) - return {"options": options} + return {"options": options, "is_answered": is_answered} def extract_selected_options(answer): @@ -123,10 +123,10 @@ def extract_selected_options(answer): return result -def determine_answer_class(is_selected: bool, is_correct: bool, user_select_choice) -> str: +def determine_answer_class(is_selected: bool, is_correct: bool) -> str: if is_selected and is_correct: return "option-answer-correct" - if not is_selected and not user_select_choice and is_correct: + if not is_selected and is_correct: return "option-answer-correct" if is_selected and not is_correct: return "option-answer-incorrect"