From 866399ba05cbd2522aac40c98f286586c4cf37b0 Mon Sep 17 00:00:00 2001 From: "Albert St. Aubin" Date: Mon, 7 Nov 2016 09:56:51 -0500 Subject: [PATCH] Changes for ui correctness state when saving a problem TNL-1955 --- common/lib/capa/capa/capa_problem.py | 15 +++- .../lib/capa/capa/templates/choicegroup.html | 17 +--- .../lib/capa/capa/templates/choicetext.html | 16 +--- .../capa/capa/tests/test_input_templates.py | 4 +- common/lib/capa/capa/tests/test_inputtypes.py | 14 ++- common/lib/xmodule/xmodule/capa_base.py | 14 +++ .../xmodule/xmodule/js/src/capa/display.js | 9 +- common/test/acceptance/pages/lms/problem.py | 29 ++++++ .../tests/lms/test_lms_courseware.py | 6 +- .../acceptance/tests/lms/test_lms_problems.py | 88 +++++++++++++++++++ lms/templates/problem.html | 6 +- lms/templates/problem_notifications.html | 4 +- 12 files changed, 174 insertions(+), 48 deletions(-) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index 8ee50b1c6a..312a6fcfc3 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -143,6 +143,7 @@ class LoncapaProblem(object): state (dict): containing the following keys: - `seed` (int) random number generator seed - `student_answers` (dict) maps input id to the stored answer for that input + - 'has_saved_answers' (Boolean) True if the answer has been saved since last submit. - `correct_map` (CorrectMap) a map of each input to their 'correctness' - `done` (bool) indicates whether or not this problem is considered done - `input_state` (dict) maps input_id to a dictionary that holds the state for that input @@ -165,6 +166,7 @@ class LoncapaProblem(object): assert self.seed is not None, "Seed must be provided for LoncapaProblem." self.student_answers = state.get('student_answers', {}) + self.has_saved_answers = state.get('has_saved_answers', False) if 'correct_map' in state: self.correct_map.set_dict(state['correct_map']) self.done = state.get('done', False) @@ -257,6 +259,7 @@ class LoncapaProblem(object): Reset internal state to unfinished, with no answers """ self.student_answers = dict() + self.has_saved_answers = False self.correct_map = CorrectMap() self.done = False @@ -283,6 +286,7 @@ class LoncapaProblem(object): return {'seed': self.seed, 'student_answers': self.student_answers, + 'has_saved_answers': self.has_saved_answers, 'correct_map': self.correct_map.get_dict(), 'input_state': self.input_state, 'done': self.done} @@ -789,8 +793,14 @@ class LoncapaProblem(object): answervariable = None if problemid in self.correct_map: pid = input_id - status = self.correct_map.get_correctness(pid) - msg = self.correct_map.get_msg(pid) + + # If the the problem has not been saved since the last submit set the status to the + # current correctness value and set the message as expected. Otherwise we do not want to + # display correctness because the answer may have changed since the problem was graded. + if not self.has_saved_answers: + status = self.correct_map.get_correctness(pid) + msg = self.correct_map.get_msg(pid) + hint = self.correct_map.get_hint(pid) hintmode = self.correct_map.get_hintmode(pid) answervariable = self.correct_map.get_property(pid, 'answervariable') @@ -810,6 +820,7 @@ class LoncapaProblem(object): 'input_state': self.input_state[input_id], 'answervariable': answervariable, 'response_data': response_data, + 'has_saved_answers': self.has_saved_answers, 'feedback': { 'message': msg, 'hint': hint, diff --git a/common/lib/capa/capa/templates/choicegroup.html b/common/lib/capa/capa/templates/choicegroup.html index 685713be01..d750187fa0 100644 --- a/common/lib/capa/capa/templates/choicegroup.html +++ b/common/lib/capa/capa/templates/choicegroup.html @@ -19,21 +19,13 @@ <% label_class = 'response-label field-label label-inline' %> +