Commit 2aa24350 by Calen Pennington

Migrate the randomize module to the new storage model

parent 222aca70
...@@ -36,29 +36,25 @@ class RandomizeModule(XModule): ...@@ -36,29 +36,25 @@ class RandomizeModule(XModule):
modules. modules.
""" """
def __init__(self, system, location, definition, descriptor, choice = Integer(help="Which random child was chosen", scope=Scope.student_state)
instance_state=None, shared_state=None, **kwargs):
XModule.__init__(self, system, location, definition, descriptor, def __init__(self, *args, **kwargs):
instance_state, shared_state, **kwargs) XModule.__init__(self, *args, **kwargs)
# NOTE: calling self.get_children() creates a circular reference-- # NOTE: calling self.get_children() creates a circular reference--
# it calls get_child_descriptors() internally, but that doesn't work until # it calls get_child_descriptors() internally, but that doesn't work until
# we've picked a choice # we've picked a choice
num_choices = len(self.descriptor.get_children()) num_choices = len(self.descriptor.get_children())
self.choice = None if self.choice > num_choices:
if instance_state is not None: # Oops. Children changed. Reset.
state = json.loads(instance_state) self.choice = None
self.choice = state.get('choice', None)
if self.choice > num_choices:
# Oops. Children changed. Reset.
self.choice = None
if self.choice is None: if self.choice is None:
# choose one based on the system seed, or randomly if that's not available # choose one based on the system seed, or randomly if that's not available
if num_choices > 0: if num_choices > 0:
if system.seed is not None: if self.system.seed is not None:
self.choice = system.seed % num_choices self.choice = self.system.seed % num_choices
else: else:
self.choice = random.randrange(0, num_choices) self.choice = random.randrange(0, num_choices)
...@@ -73,10 +69,6 @@ class RandomizeModule(XModule): ...@@ -73,10 +69,6 @@ class RandomizeModule(XModule):
self.child = None self.child = None
def get_instance_state(self):
return json.dumps({'choice': self.choice})
def get_child_descriptors(self): def get_child_descriptors(self):
""" """
For grading--return just the chosen child. For grading--return just the chosen child.
......
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