Commit 7ea3d70c by Vik Paruchuri

Caching attribute values from child module

parent b7c6f7ca
...@@ -12,12 +12,16 @@ from xmodule.open_ended_grading_classes.combined_open_ended_modulev1 import Comb ...@@ -12,12 +12,16 @@ from xmodule.open_ended_grading_classes.combined_open_ended_modulev1 import Comb
log = logging.getLogger("mitx.courseware") log = logging.getLogger("mitx.courseware")
V1_ATTRIBUTES = ["display_name", "current_task_number", "task_states", "state", V1_SETTINGS_ATTRIBUTES = ["display_name", "attempts", "is_graded", "accept_file_upload",
"attempts", "ready_to_reset", "max_attempts", "is_graded", "accept_file_upload",
"skip_spelling_checks", "due", "graceperiod", "max_score"] "skip_spelling_checks", "due", "graceperiod", "max_score"]
V1_STUDENT_ATTRIBUTES = ["current_task_number", "task_states", "state",
"student_attempts", "ready_to_reset"]
V1_ATTRIBUTES = V1_SETTINGS_ATTRIBUTES + V1_STUDENT_ATTRIBUTES
VERSION_TUPLES = ( VERSION_TUPLES = (
('1', CombinedOpenEndedV1Descriptor, CombinedOpenEndedV1Module, V1_ATTRIBUTES), ('1', CombinedOpenEndedV1Descriptor, CombinedOpenEndedV1Module, V1_SETTINGS_ATTRIBUTES, V1_STUDENT_ATTRIBUTES),
) )
DEFAULT_VERSION = 1 DEFAULT_VERSION = 1
...@@ -56,13 +60,13 @@ class CombinedOpenEndedModule(XModule): ...@@ -56,13 +60,13 @@ class CombinedOpenEndedModule(XModule):
icon_class = 'problem' icon_class = 'problem'
display_name = String(help="Display name for this module", scope=Scope.settings) display_name = String(help="Display name for this module", default="Open Ended Grading", scope=Scope.settings)
current_task_number = Integer(help="Current task that the student is on.", default=0, scope=Scope.student_state) current_task_number = Integer(help="Current task that the student is on.", default=0, scope=Scope.student_state)
task_states = Object(help="State dictionaries of each task within this module.", default=[], scope=Scope.student_state) task_states = Object(help="State dictionaries of each task within this module.", default=[], scope=Scope.student_state)
state = String(help="Which step within the current task that the student is on.", default="initial", scope=Scope.student_state) state = String(help="Which step within the current task that the student is on.", default="initial", scope=Scope.student_state)
attempts = Integer(help="Number of attempts taken by the student on this problem", default=0, scope=Scope.student_state) student_attempts = Integer(help="Number of attempts taken by the student on this problem", default=0, scope=Scope.student_state)
ready_to_reset = Boolean(help="If the problem is ready to be reset or not.", default=False, scope=Scope.student_state) ready_to_reset = Boolean(help="If the problem is ready to be reset or not.", default=False, scope=Scope.student_state)
max_attempts = Integer(help="Maximum number of attempts that a student is allowed.", default=1, scope=Scope.settings) attempts = Integer(help="Maximum number of attempts that a student is allowed.", default=1, scope=Scope.settings)
is_graded = Boolean(help="Whether or not the problem is graded.", default=False, scope=Scope.settings) is_graded = Boolean(help="Whether or not the problem is graded.", default=False, scope=Scope.settings)
accept_file_upload = Boolean(help="Whether or not the problem accepts file uploads.", default=False, scope=Scope.settings) accept_file_upload = Boolean(help="Whether or not the problem accepts file uploads.", default=False, scope=Scope.settings)
skip_spelling_checks = Boolean(help="Whether or not to skip initial spelling checks.", default=True, scope=Scope.settings) skip_spelling_checks = Boolean(help="Whether or not to skip initial spelling checks.", default=True, scope=Scope.settings)
...@@ -124,7 +128,8 @@ class CombinedOpenEndedModule(XModule): ...@@ -124,7 +128,8 @@ class CombinedOpenEndedModule(XModule):
versions = [i[0] for i in VERSION_TUPLES] versions = [i[0] for i in VERSION_TUPLES]
descriptors = [i[1] for i in VERSION_TUPLES] descriptors = [i[1] for i in VERSION_TUPLES]
modules = [i[2] for i in VERSION_TUPLES] modules = [i[2] for i in VERSION_TUPLES]
attributes = [i[3] for i in VERSION_TUPLES] settings_attributes = [i[3] for i in VERSION_TUPLES]
student_attributes = [i[4] for i in VERSION_TUPLES]
try: try:
version_index = versions.index(self.version) version_index = versions.index(self.version)
...@@ -134,20 +139,26 @@ class CombinedOpenEndedModule(XModule): ...@@ -134,20 +139,26 @@ class CombinedOpenEndedModule(XModule):
self.version = DEFAULT_VERSION self.version = DEFAULT_VERSION
version_index = versions.index(self.version) version_index = versions.index(self.version)
self.student_attributes = student_attributes[version_index]
self.settings_attributes = settings_attributes[version_index]
attributes = self.student_attributes + self.settings_attributes
static_data = { static_data = {
'rewrite_content_links' : self.rewrite_content_links, 'rewrite_content_links' : self.rewrite_content_links,
} }
instance_state = { k: getattr(self,k) for k in attributes[version_index]} instance_state = { k: getattr(self,k) for k in attributes}
instance_state.update({'data' : self.data})
self.child_descriptor = descriptors[version_index](self.system) self.child_descriptor = descriptors[version_index](self.system)
self.child_definition = descriptors[version_index].definition_from_xml(etree.fromstring(self.data), self.system) self.child_definition = descriptors[version_index].definition_from_xml(etree.fromstring(self.data), self.system)
self.child_module = modules[version_index](self.system, location, self.child_definition, self.child_descriptor, self.child_module = modules[version_index](self.system, location, self.child_definition, self.child_descriptor,
instance_state = instance_state, static_data= static_data, model_data=model_data) instance_state = instance_state, static_data= static_data, model_data=model_data, attributes=attributes)
def get_html(self): def get_html(self):
self.save_instance_data()
return self.child_module.get_html() return self.child_module.get_html()
def handle_ajax(self, dispatch, get): def handle_ajax(self, dispatch, get):
self.save_instance_data()
return self.child_module.handle_ajax(dispatch, get) return self.child_module.handle_ajax(dispatch, get)
def get_instance_state(self): def get_instance_state(self):
...@@ -166,6 +177,10 @@ class CombinedOpenEndedModule(XModule): ...@@ -166,6 +177,10 @@ class CombinedOpenEndedModule(XModule):
def due_date(self): def due_date(self):
return self.child_module.due_date return self.child_module.due_date
def save_instance_date(self):
for attribute in self.student_attributes:
setattr(self,k, getattr(self.child_module,k))
class CombinedOpenEndedDescriptor(RawDescriptor): class CombinedOpenEndedDescriptor(RawDescriptor):
""" """
......
...@@ -131,11 +131,11 @@ class CombinedOpenEndedV1Module(): ...@@ -131,11 +131,11 @@ class CombinedOpenEndedV1Module():
#Overall state of the combined open ended module #Overall state of the combined open ended module
self.state = instance_state.get('state', self.INITIAL) self.state = instance_state.get('state', self.INITIAL)
self.attempts = instance_state.get('attempts', 0) self.student_attempts = instance_state.get('student_attempts', 0)
#Allow reset is true if student has failed the criteria to move to the next child task #Allow reset is true if student has failed the criteria to move to the next child task
self.allow_reset = instance_state.get('ready_to_reset', False) self.allow_reset = instance_state.get('ready_to_reset', False)
self.max_attempts = self.instance_state.get('attempts', MAX_ATTEMPTS) self.attempts = self.instance_state.get('attempts', MAX_ATTEMPTS)
self.is_scored = self.instance_state.get('is_graded', IS_SCORED) in TRUE_DICT self.is_scored = self.instance_state.get('is_graded', IS_SCORED) in TRUE_DICT
self.accept_file_upload = self.instance_state.get('accept_file_upload', ACCEPT_FILE_UPLOAD) in TRUE_DICT self.accept_file_upload = self.instance_state.get('accept_file_upload', ACCEPT_FILE_UPLOAD) in TRUE_DICT
self.skip_basic_checks = self.instance_state.get('skip_spelling_checks', SKIP_BASIC_CHECKS) self.skip_basic_checks = self.instance_state.get('skip_spelling_checks', SKIP_BASIC_CHECKS)
...@@ -161,7 +161,7 @@ class CombinedOpenEndedV1Module(): ...@@ -161,7 +161,7 @@ class CombinedOpenEndedV1Module():
#Static data is passed to the child modules to render #Static data is passed to the child modules to render
self.static_data = { self.static_data = {
'max_score': self._max_score, 'max_score': self._max_score,
'max_attempts': self.max_attempts, 'max_attempts': self.attempts,
'prompt': definition['prompt'], 'prompt': definition['prompt'],
'rubric': definition['rubric'], 'rubric': definition['rubric'],
'display_name': self.display_name, 'display_name': self.display_name,
...@@ -195,7 +195,6 @@ class CombinedOpenEndedV1Module(): ...@@ -195,7 +195,6 @@ class CombinedOpenEndedV1Module():
last_response = last_response_data['response'] last_response = last_response_data['response']
loaded_task_state = json.loads(current_task_state) loaded_task_state = json.loads(current_task_state)
log.debug(loaded_task_state)
if loaded_task_state['child_state'] == self.INITIAL: if loaded_task_state['child_state'] == self.INITIAL:
loaded_task_state['child_state'] = self.ASSESSING loaded_task_state['child_state'] = self.ASSESSING
loaded_task_state['child_created'] = True loaded_task_state['child_created'] = True
...@@ -276,7 +275,6 @@ class CombinedOpenEndedV1Module(): ...@@ -276,7 +275,6 @@ class CombinedOpenEndedV1Module():
instance_state=current_task_state) instance_state=current_task_state)
self.task_states.append(self.current_task.get_instance_state()) self.task_states.append(self.current_task.get_instance_state())
self.state = self.ASSESSING self.state = self.ASSESSING
log.debug(self.task_states)
else: else:
if self.current_task_number > 0 and not reset: if self.current_task_number > 0 and not reset:
current_task_state = self.overwrite_state(current_task_state) current_task_state = self.overwrite_state(current_task_state)
...@@ -638,13 +636,13 @@ class CombinedOpenEndedV1Module(): ...@@ -638,13 +636,13 @@ class CombinedOpenEndedV1Module():
if not self.allow_reset: if not self.allow_reset:
return self.out_of_sync_error(get) return self.out_of_sync_error(get)
if self.attempts > self.max_attempts: if self.student_attempts > self.attempts:
return { return {
'success': False, 'success': False,
#This is a student_facing_error #This is a student_facing_error
'error': ('You have attempted this question {0} times. ' 'error': ('You have attempted this question {0} times. '
'You are only allowed to attempt it {1} times.').format( 'You are only allowed to attempt it {1} times.').format(
self.attempts, self.max_attempts) self.student_attempts, self.attempts)
} }
self.state = self.INITIAL self.state = self.INITIAL
self.allow_reset = False self.allow_reset = False
...@@ -670,7 +668,7 @@ class CombinedOpenEndedV1Module(): ...@@ -670,7 +668,7 @@ class CombinedOpenEndedV1Module():
'current_task_number': self.current_task_number, 'current_task_number': self.current_task_number,
'state': self.state, 'state': self.state,
'task_states': self.task_states, 'task_states': self.task_states,
'attempts': self.attempts, 'student_attempts': self.student_attempts,
'ready_to_reset': self.allow_reset, 'ready_to_reset': self.allow_reset,
} }
......
...@@ -579,6 +579,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild): ...@@ -579,6 +579,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
'check_for_score': self.check_for_score, 'check_for_score': self.check_for_score,
} }
log.debug(dispatch)
if dispatch not in handlers: if dispatch not in handlers:
#This is a dev_facing_error #This is a dev_facing_error
log.error("Cannot find {0} in handlers in handle_ajax function for open_ended_module.py".format(dispatch)) log.error("Cannot find {0} in handlers in handle_ajax function for open_ended_module.py".format(dispatch))
......
...@@ -454,11 +454,13 @@ class PeerGradingModule(XModule): ...@@ -454,11 +454,13 @@ class PeerGradingModule(XModule):
except GradingServiceError: except GradingServiceError:
#This is a student_facing_error #This is a student_facing_error
error_text = EXTERNAL_GRADER_NO_CONTACT_ERROR error_text = EXTERNAL_GRADER_NO_CONTACT_ERROR
log.error(error_text)
success = False success = False
# catch error if if the json loads fails # catch error if if the json loads fails
except ValueError: except ValueError:
#This is a student_facing_error #This is a student_facing_error
error_text = "Could not get list of problems to peer grade. Please notify course staff." error_text = "Could not get list of problems to peer grade. Please notify course staff."
log.error(error_text)
success = False success = False
...@@ -553,7 +555,7 @@ class PeerGradingModule(XModule): ...@@ -553,7 +555,7 @@ class PeerGradingModule(XModule):
class PeerGradingDescriptor(RawDescriptor): class PeerGradingDescriptor(RawDescriptor):
""" """
Module for adding peer grading questions Module for adding combined open ended questions
""" """
mako_template = "widgets/raw-edit.html" mako_template = "widgets/raw-edit.html"
module_class = PeerGradingModule module_class = PeerGradingModule
...@@ -562,3 +564,4 @@ class PeerGradingDescriptor(RawDescriptor): ...@@ -562,3 +564,4 @@ class PeerGradingDescriptor(RawDescriptor):
stores_state = True stores_state = True
has_score = True has_score = True
template_dir_name = "peer_grading" template_dir_name = "peer_grading"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment