Skip to content
Snippets Groups Projects
Commit c2a668de authored by Ben Adida's avatar Ben Adida
Browse files

made pretty_results and datatypes more robust in the face of nulls

parent 431a6b33
No related branches found
No related tags found
No related merge requests found
...@@ -171,7 +171,10 @@ class LDObject(object): ...@@ -171,7 +171,10 @@ class LDObject(object):
self.structured_fields[f] = sub_ld_object self.structured_fields[f] = sub_ld_object
# set the field on the wrapped object too # set the field on the wrapped object too
if sub_ld_object != None:
self._setattr_wrapped(f, sub_ld_object.wrapped_obj) self._setattr_wrapped(f, sub_ld_object.wrapped_obj)
else:
self._setattr_wrapped(f, None)
else: else:
# a simple type # a simple type
new_val = self.process_value_in(f, d[f]) new_val = self.process_value_in(f, d[f])
...@@ -203,6 +206,10 @@ class LDObject(object): ...@@ -203,6 +206,10 @@ class LDObject(object):
@classmethod @classmethod
def fromDict(cls, d, type_hint=None): def fromDict(cls, d, type_hint=None):
# null objects
if d == None:
return None
# the LD type is either in d or in type_hint # the LD type is either in d or in type_hint
# FIXME: get this from the dictionary itself # FIXME: get this from the dictionary itself
ld_type = type_hint ld_type = type_hint
......
...@@ -480,9 +480,12 @@ class Election(HeliosModel): ...@@ -480,9 +480,12 @@ class Election(HeliosModel):
counts = sorted(enumerate(result), key=lambda(x): x[1]) counts = sorted(enumerate(result), key=lambda(x): x[1])
counts.reverse() counts.reverse()
the_max = question['max'] or 1
the_min = question['min'] or 0
# if there's a max > 1, we assume that the top MAX win # if there's a max > 1, we assume that the top MAX win
if question['max'] > 1: if the_max > 1:
return [c[0] for c in counts[:question['max']]] return [c[0] for c in counts[:the_max]]
# if max = 1, then depends on absolute or relative # if max = 1, then depends on absolute or relative
if question['result_type'] == 'absolute': if question['result_type'] == 'absolute':
...@@ -490,8 +493,8 @@ class Election(HeliosModel): ...@@ -490,8 +493,8 @@ class Election(HeliosModel):
return [counts[0][0]] return [counts[0][0]]
else: else:
return [] return []
else:
if question['result_type'] == 'relative': # assumes that anything non-absolute is relative
return [counts[0][0]] return [counts[0][0]]
@property @property
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment