Commit 13b95eb0 by Calen Pennington

Make progress handle extra credit by capping at 100%, and handle malformed…

Make progress handle extra credit by capping at 100%, and handle malformed progress stuff by ignoring any changes
parent f9306757
......@@ -322,10 +322,16 @@ class CapaModule(XModule):
before = self.get_progress()
d = handlers[dispatch](get)
after = self.get_progress()
d.update({
'progress_changed': after != before,
'progress_status': Progress.to_js_status_str(after),
try:
after = self.get_progress()
d.update({
'progress_changed': after != before,
'progress_status': Progress.to_js_status_str(after),
})
except ValueError:
d.update({
'progress_changed': False,
'progress_status': Progress.to_js_status(before),
})
return json.dumps(d, cls=ComplexEncoder)
......
......@@ -39,9 +39,11 @@ class Progress(object):
isinstance(b, numbers.Number)):
raise TypeError('a and b must be numbers. Passed {0}/{1}'.format(a, b))
if not (0 <= a <= b and b > 0):
raise ValueError(
'fraction a/b = {0}/{1} must have 0 <= a <= b and b > 0'.format(a, b))
if a > b:
a = b
if b <= 0:
raise ValueError('fraction a/b = {0}/{1} must have b > 0'.format(a, b))
self._a = a
self._b = b
......
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