mirror of https://github.com/apache/superset.git
make filter_values() macro to properly accept value from filter box with single value setting (#7494)
This commit is contained in:
parent
45b9880516
commit
78c1674dc7
|
@ -113,8 +113,11 @@ def filter_values(column, default=None):
|
||||||
|
|
||||||
for f in form_data[filter_type]:
|
for f in form_data[filter_type]:
|
||||||
if f['col'] == column:
|
if f['col'] == column:
|
||||||
|
if isinstance(f['val'], list):
|
||||||
for v in f['val']:
|
for v in f['val']:
|
||||||
return_val.append(v)
|
return_val.append(v)
|
||||||
|
else:
|
||||||
|
return_val.append(f['val'])
|
||||||
|
|
||||||
if return_val:
|
if return_val:
|
||||||
return return_val
|
return return_val
|
||||||
|
|
|
@ -48,9 +48,19 @@ class MacroTestCase(SupersetTestCase):
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
form_data4 = {
|
||||||
|
'extra_filters': [
|
||||||
|
{'col': 'my_special_filter', 'op': 'in', 'val': 'foo'},
|
||||||
|
],
|
||||||
|
'filters': [
|
||||||
|
{'col': 'my_special_filter', 'op': 'in', 'val': 'savage'},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
data1 = {'form_data': json.dumps(form_data1)}
|
data1 = {'form_data': json.dumps(form_data1)}
|
||||||
data2 = {'form_data': json.dumps(form_data2)}
|
data2 = {'form_data': json.dumps(form_data2)}
|
||||||
data3 = {'form_data': json.dumps(form_data3)}
|
data3 = {'form_data': json.dumps(form_data3)}
|
||||||
|
data4 = {'form_data': json.dumps(form_data4)}
|
||||||
|
|
||||||
with app.test_request_context(data=data1):
|
with app.test_request_context(data=data1):
|
||||||
filter_values = jinja_context.filter_values('my_special_filter')
|
filter_values = jinja_context.filter_values('my_special_filter')
|
||||||
|
@ -73,3 +83,7 @@ class MacroTestCase(SupersetTestCase):
|
||||||
with app.test_request_context():
|
with app.test_request_context():
|
||||||
filter_values = jinja_context.filter_values('nonexistent_filter', 'foo')
|
filter_values = jinja_context.filter_values('nonexistent_filter', 'foo')
|
||||||
self.assertEqual(filter_values, ['foo'])
|
self.assertEqual(filter_values, ['foo'])
|
||||||
|
|
||||||
|
with app.test_request_context(data=data4):
|
||||||
|
filter_values = jinja_context.filter_values('my_special_filter')
|
||||||
|
self.assertEqual(filter_values, ['savage', 'foo'])
|
||||||
|
|
Loading…
Reference in New Issue