From c4a2f7dcdc52d28988fca6dc54b4820ece22bcc7 Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Fri, 9 Aug 2013 17:01:07 -0400 Subject: [PATCH] Fix invalid state --- .../combined_open_ended_modulev1.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py b/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py index 933eb0b5bb..ba36e1e2ee 100644 --- a/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py +++ b/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py @@ -135,8 +135,50 @@ class CombinedOpenEndedV1Module(): self.task_xml = definition['task_xml'] self.location = location + self.fix_invalid_state() self.setup_next_task() + def fix_invalid_state(self): + """ + Sometimes a teacher will change the xml definition of a problem in Studio. + This means that the state passed to the module is invalid. + If that is the case, delete it. + """ + + #If we are on a task that is greater than the number of available tasks, it is an invalid state + if self.current_task_number>len(self.task_states): + self.task_states = [] + self.current_task_number = 0 + #If the current task number is greater than the number of tasks we have in the xml definition, our state is invalid. + elif self.current_task_number>len(self.task_xml): + self.task_states = [] + self.current_task_number = 0 + #if the length of the task xml is less than the length of the task states, state is invalid + elif len(self.task_xml)