fields: correctly check data source tuple size (#8719)

This commit is contained in:
Frédéric Péters 2015-10-20 18:06:38 +02:00
parent 704c420c0f
commit 2126931d33
2 changed files with 20 additions and 1 deletions

View File

@ -193,3 +193,22 @@ def test_data_source_slug_name():
data_source = NamedDataSource(name='foo bar')
data_source.store()
assert data_source.slug == 'foo_bar'
def test_optional_item_field_with_data_source():
NamedDataSource.wipe()
data_source = NamedDataSource(name='foobar')
data_source.data_source = {'type': 'formula',
'value': repr([('1', 'un'), ('2', 'deux')])}
data_source.store()
field = fields.ItemField()
field.id = 1
field.required = False
field.data_source = {
'type': 'foobar', # use the named data source defined earlier
}
form = Form()
field.add_to_form(form)
widget = form.get_widget('f1')
assert widget is not None
assert widget.options == [(None, '---', 'None'), ('1', 'un', '1'), ('2', 'deux', '2')]

View File

@ -864,7 +864,7 @@ class ItemField(WidgetField):
if options and not self.required:
if type(options[0]) is str:
options[:0] = [None]
elif len(options) == 2:
elif len(options[0]) == 2:
options[:0] = [(None, '---')]
elif len(options[0]) == 3:
options[:0] = [(None, '---', None)]