Commit 756e4057 by Victor Shnayder

Revert "Lazily loading capa problems (for faster grading)."

We don't want lazyness, and will save the proper fix (moving work into descriptor load for later)
parent f5aa46a1
...@@ -15,7 +15,6 @@ from capa.capa_problem import LoncapaProblem ...@@ -15,7 +15,6 @@ from capa.capa_problem import LoncapaProblem
from capa.responsetypes import StudentInputError from capa.responsetypes import StudentInputError
from capa.util import convert_files_to_filenames from capa.util import convert_files_to_filenames
from progress import Progress from progress import Progress
from xmodule.util.decorators import lazyproperty
from xmodule.x_module import XModule from xmodule.x_module import XModule
from xmodule.raw_module import RawDescriptor from xmodule.raw_module import RawDescriptor
from xmodule.exceptions import NotFoundError from xmodule.exceptions import NotFoundError
...@@ -119,11 +118,9 @@ class CapaModule(XModule): ...@@ -119,11 +118,9 @@ class CapaModule(XModule):
if self.show_answer == "": if self.show_answer == "":
self.show_answer = "closed" self.show_answer = "closed"
if instance_state is not None: if instance_state is not None:
instance_state = json.loads(instance_state) instance_state = json.loads(instance_state)
self._instance_state = instance_state # We will need this later to lazily load lcp
if instance_state is not None and 'attempts' in instance_state: if instance_state is not None and 'attempts' in instance_state:
self.attempts = instance_state['attempts'] self.attempts = instance_state['attempts']
...@@ -135,27 +132,18 @@ class CapaModule(XModule): ...@@ -135,27 +132,18 @@ class CapaModule(XModule):
else: else:
self.weight = None self.weight = None
@lazyproperty
def lcp(self):
"""
Loading the problem can be fairly expensive, so we do this lazily.
This can throw errors. Always be sure to use try/catch before
displaying modules to a user.
"""
if self.rerandomize == 'never': if self.rerandomize == 'never':
seed = 1 seed = 1
elif self.rerandomize == "per_student" and hasattr(self.system, 'id'): elif self.rerandomize == "per_student" and hasattr(self.system, 'id'):
seed = system.id seed = system.id
else: else:
seed = None seed = None
try: try:
return LoncapaProblem(self.definition['data'], self.location.html_id(), # TODO (vshnayder): move as much as possible of this work and error
self._instance_state, seed=seed, system=self.system) # checking to descriptor load time
self.lcp = LoncapaProblem(self.definition['data'], self.location.html_id(),
instance_state, seed=seed, system=self.system)
except Exception as err: except Exception as err:
msg = 'cannot create LoncapaProblem {loc}: {err}'.format( msg = 'cannot create LoncapaProblem {loc}: {err}'.format(
loc=self.location.url(), err=err) loc=self.location.url(), err=err)
...@@ -172,13 +160,12 @@ class CapaModule(XModule): ...@@ -172,13 +160,12 @@ class CapaModule(XModule):
problem_text = ('<problem><text><font color="red" size="+2">' problem_text = ('<problem><text><font color="red" size="+2">'
'Problem %s has an error:</font>%s</text></problem>' % 'Problem %s has an error:</font>%s</text></problem>' %
(self.location.url(), msg)) (self.location.url(), msg))
return LoncapaProblem( self.lcp = LoncapaProblem(
problem_text, self.location.html_id(), problem_text, self.location.html_id(),
self._instance_state, seed=seed, system=self.system) instance_state, seed=seed, system=self.system)
else: else:
# add extra info and raise # add extra info and raise
raise Exception(msg), None, sys.exc_info()[2] raise Exception(msg), None, sys.exc_info()[2]
@property @property
def rerandomize(self): def rerandomize(self):
...@@ -441,7 +428,7 @@ class CapaModule(XModule): ...@@ -441,7 +428,7 @@ class CapaModule(XModule):
event_info = dict() event_info = dict()
event_info['state'] = self.lcp.get_state() event_info['state'] = self.lcp.get_state()
event_info['problem_id'] = self.location.url() event_info['problem_id'] = self.location.url()
answers = self.make_dict_of_responses(get) answers = self.make_dict_of_responses(get)
event_info['answers'] = convert_files_to_filenames(answers) event_info['answers'] = convert_files_to_filenames(answers)
...@@ -577,7 +564,7 @@ class CapaDescriptor(RawDescriptor): ...@@ -577,7 +564,7 @@ class CapaDescriptor(RawDescriptor):
""" """
module_class = CapaModule module_class = CapaModule
stores_state = True stores_state = True
has_score = True has_score = True
......
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