diff --git a/common/lib/xmodule/xmodule/capa_module.py b/common/lib/xmodule/xmodule/capa_module.py index da366a21cc..1b93bb4ec4 100644 --- a/common/lib/xmodule/xmodule/capa_module.py +++ b/common/lib/xmodule/xmodule/capa_module.py @@ -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 diff --git a/lms/djangoapps/courseware/grades.py b/lms/djangoapps/courseware/grades.py index e007a37493..eab612e34a 100644 --- a/lms/djangoapps/courseware/grades.py +++ b/lms/djangoapps/courseware/grades.py @@ -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))