Skip to content

Commit

Permalink
Fixed converting values.
Browse files Browse the repository at this point in the history
Only return a list of values if the selection can actually have multiple
values. This fixes a former change.
  • Loading branch information
toirl committed Nov 1, 2017
1 parent 338b1ce commit 79f22be
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions formbar/fields.py
Expand Up @@ -775,20 +775,18 @@ def _from_python(self, value):
# '2']" will be converted into the _string_ "{1,2,''}". In
# this case we need to convert the value back into a list.
serialized = []
if value.startswith("{") and value.endswith("}"):
value = value.strip("{").strip("}")
elif value.startswith("[") and value.endswith("]"):
value = value.strip("[").strip("]")

for v in value.split(","):
if isinstance(self, IntSelectionField):
value = int(v)
elif isinstance(self, BooleanSelectionField):
value = bool(v)
else:
value = unicode(v)
serialized.append(value)
value = serialized
if ((value.startswith("{") and value.endswith("}")) or
(value.startswith("[") and value.endswith("]"))):
value = value.strip("[").strip("]").strip("{").strip("}")
for v in value.split(","):
if isinstance(self, IntSelectionField):
value = int(v)
elif isinstance(self, BooleanSelectionField):
value = bool(v)
else:
value = unicode(v)
serialized.append(value)
value = serialized
return value

def _to_python(self, value):
Expand Down

0 comments on commit 79f22be

Please sign in to comment.