Allow FieldAttribute lists and sets to be set from a comma separated string

pull/14967/head
Toshio Kuratomi 9 years ago
parent 88772b6003
commit d665911bab

@ -334,7 +334,10 @@ class Base:
if value is None: if value is None:
value = [] value = []
elif not isinstance(value, list): elif not isinstance(value, list):
value = [ value ] if isinstance(value, string_types):
value = value.split(',')
else:
value = [ value ]
if attribute.listof is not None: if attribute.listof is not None:
for item in value: for item in value:
if not isinstance(item, attribute.listof): if not isinstance(item, attribute.listof):
@ -346,11 +349,15 @@ class Base:
elif attribute.isa == 'set': elif attribute.isa == 'set':
if value is None: if value is None:
value = set() value = set()
else: elif not isinstance(value, (list, set)):
if not isinstance(value, (list, set)): if isinstance(value, string_types):
value = value.split(',')
else:
# Making a list like this handles strings of
# text and bytes properly
value = [ value ] value = [ value ]
if not isinstance(value, set): if not isinstance(value, set):
value = set(value) value = set(value)
elif attribute.isa == 'dict': elif attribute.isa == 'dict':
if value is None: if value is None:
value = dict() value = dict()

Loading…
Cancel
Save