Commit 03582928 by Calen Pennington

Parse weight as a float when reading from a string

parent e3f7e602
......@@ -29,9 +29,21 @@ class StringyInteger(Integer):
A model type that converts from strings to integers when reading from json
"""
def from_json(self, value):
if isinstance(value, basestring):
try:
return int(value)
return value
except:
return value
class StringyFloat(Float):
"""
A model type that converts from string to floats when reading from json
"""
def from_json(self, value):
try:
return float(value)
except:
return value
# Generated this many different variants of problems with rerandomize=per_student
......@@ -781,7 +793,7 @@ class CapaDescriptor(RawDescriptor):
module_class = CapaModule
weight = Float(help="How much to weight this problem by", scope=Scope.settings)
weight = StringyFloat(help="How much to weight this problem by", scope=Scope.settings)
markdown = String(help="Markdown source of this module", scope=Scope.settings, default='')
stores_state = True
......
......@@ -395,7 +395,7 @@ def get_score(course_id, user, problem_descriptor, module_creator, model_data_ca
return (None, None)
#Now we re-weight the problem, if specified
weight = getattr(problem_descriptor, 'weight', None)
weight = problem_descriptor.weight
if weight is not None:
if total == 0:
log.exception("Cannot reweight a problem with zero total points. Problem: " + str(student_module))
......
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