Save randomization seed if it is not already set,

so that the same problem loads when the user
checks/saves/resets
This commit is contained in:
Will Daly
2013-04-01 12:08:53 -04:00
parent 7f00487203
commit fb97602442
2 changed files with 15 additions and 8 deletions

View File

@@ -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)

View File

@@ -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