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): ...@@ -322,10 +322,16 @@ class CapaModule(XModule):
before = self.get_progress() before = self.get_progress()
d = handlers[dispatch](get) d = handlers[dispatch](get)
after = self.get_progress() try:
d.update({ after = self.get_progress()
'progress_changed': after != before, d.update({
'progress_status': Progress.to_js_status_str(after), '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) return json.dumps(d, cls=ComplexEncoder)
......
...@@ -39,9 +39,11 @@ class Progress(object): ...@@ -39,9 +39,11 @@ class Progress(object):
isinstance(b, numbers.Number)): isinstance(b, numbers.Number)):
raise TypeError('a and b must be numbers. Passed {0}/{1}'.format(a, b)) raise TypeError('a and b must be numbers. Passed {0}/{1}'.format(a, b))
if not (0 <= a <= b and b > 0): if a > b:
raise ValueError( a = b
'fraction a/b = {0}/{1} must have 0 <= a <= b and b > 0'.format(a, b))
if b <= 0:
raise ValueError('fraction a/b = {0}/{1} must have b > 0'.format(a, b))
self._a = a self._a = a
self._b = b 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