Commit fb976024 by Will Daly

Save randomization seed if it is not already set,

so that the same problem loads when the user
checks/saves/resets
parent 7f004872
...@@ -150,6 +150,16 @@ class CapaModule(CapaFields, XModule): ...@@ -150,6 +150,16 @@ class CapaModule(CapaFields, XModule):
# TODO (vshnayder): move as much as possible of this work and error # TODO (vshnayder): move as much as possible of this work and error
# checking to descriptor load time # checking to descriptor load time
self.lcp = self.new_lcp(self.get_state_for_lcp()) self.lcp = self.new_lcp(self.get_state_for_lcp())
# At this point, we need to persist the randomization seed
# so that when the problem is re-loaded (to check/view/save)
# it stays the same.
# However, we do not want to write to the database
# every time the module is loaded.
# So we set the seed ONLY when there is not one set already
if self.seed is None:
self.seed = self.lcp.seed
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)
......
...@@ -868,10 +868,8 @@ class CapaModuleTest(unittest.TestCase): ...@@ -868,10 +868,8 @@ class CapaModuleTest(unittest.TestCase):
module = CapaFactory.create(rerandomize=rerandomize) module = CapaFactory.create(rerandomize=rerandomize)
# Get the seed # Get the seed
# This isn't stored in the XModule until # By this point, the module should have persisted the seed
# we check/save/reset the problem, so we seed = module.seed
# access the lcp seed directly
seed = module.lcp.seed
self.assertTrue(seed is not None) self.assertTrue(seed is not None)
# If we're not rerandomizing, the seed is always set # If we're not rerandomizing, the seed is always set
...@@ -931,10 +929,9 @@ class CapaModuleTest(unittest.TestCase): ...@@ -931,10 +929,9 @@ class CapaModuleTest(unittest.TestCase):
module = CapaFactory.create(rerandomize=rerandomize) module = CapaFactory.create(rerandomize=rerandomize)
# Get the seed # Get the seed
# This isn't stored in the XModule until # By this point, the module should have persisted the seed
# we check/save/reset the problem, so we seed = module.seed
# access the lcp seed directly self.assertTrue(seed is not None)
seed = module.lcp.seed
# We do NOT want the seed to reset if rerandomize # We do NOT want the seed to reset if rerandomize
# is set to 'never' -- it should still be 1 # is set to 'never' -- it should still be 1
......
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