Commit 476b1d16 by Justin Riley

choose last item in history when choices are exhausted

Raising an exception in the case that all choices have been exhausted in
the randomize module breaks things so set it to the last seen problem
instead.
parent ba9ba6c6
...@@ -83,14 +83,16 @@ class RandomizeModule(RandomizeFields, XModule): ...@@ -83,14 +83,16 @@ class RandomizeModule(RandomizeFields, XModule):
log.debug('using randrange for %s' % str(self.location)) log.debug('using randrange for %s' % str(self.location))
self.choice = choice self.choice = choice
else: else:
# we're in a bad state - possible solution below tries to # Student has seen all problems. Ideally we autogenerate a fake
# restore last failed problem from history (raise exc for now) # CapaModule problem and leave it until history gets wiped by
# try: # an instructor/TA but for now we use the last seen choice from
# last_failed = json.loads(self.history or '[]')[-1] # history.
# self.choice = last_failed log.error("No choices left!!! Attempting to use last "
# except IndexError: "item in history")
# raise Exception('No choices left!!!') try:
raise Exception('No choices left!!!') self.choice = self.history[-1]
except IndexError:
log.error("Failed to load last item in history")
if self.choice is not None: if self.choice is not None:
self.child_descriptor = all_choices.get(self.choice) self.child_descriptor = all_choices.get(self.choice)
...@@ -126,14 +128,14 @@ class RandomizeModule(RandomizeFields, XModule): ...@@ -126,14 +128,14 @@ class RandomizeModule(RandomizeFields, XModule):
return [self.child_descriptor] return [self.child_descriptor]
def student_view(self, context): def student_view(self, context):
if self.choice is not None: if self.child is None:
# raise error instead? In fact, could complain on descriptor load
return Fragment(content=u"<div>Nothing to randomize between</div>")
else:
child_loc = self.child.location.url() child_loc = self.child.location.url()
if child_loc not in self.history: if child_loc not in self.history:
self.history.append(child_loc) self.history.append(child_loc)
self.save() self.save()
if self.child is None:
# raise error instead? In fact, could complain on descriptor load
return Fragment(content=u"<div>Nothing to randomize between</div>")
child_html = self.child.render('student_view', context) child_html = self.child.render('student_view', context)
if self.system.user_is_staff: if self.system.user_is_staff:
choices = self.get_choices().keys() choices = self.get_choices().keys()
......
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