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):
# TODO (vshnayder): move as much as possible of this work and error
# checking to descriptor load time
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:
msg = 'cannot create LoncapaProblem {loc}: {err}'.format(
loc=self.location.url(), err=err)
......
......@@ -868,10 +868,8 @@ class CapaModuleTest(unittest.TestCase):
module = CapaFactory.create(rerandomize=rerandomize)
# Get the seed
# This isn't stored in the XModule until
# we check/save/reset the problem, so we
# access the lcp seed directly
seed = module.lcp.seed
# By this point, the module should have persisted the seed
seed = module.seed
self.assertTrue(seed is not None)
# If we're not rerandomizing, the seed is always set
......@@ -931,10 +929,9 @@ class CapaModuleTest(unittest.TestCase):
module = CapaFactory.create(rerandomize=rerandomize)
# Get the seed
# This isn't stored in the XModule until
# we check/save/reset the problem, so we
# access the lcp seed directly
seed = module.lcp.seed
# By this point, the module should have persisted the seed
seed = module.seed
self.assertTrue(seed is not None)
# We do NOT want the seed to reset if rerandomize
# 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