Skip to content

Commit

Permalink
make filter_values() macro to properly accept value from filter box w…
Browse files Browse the repository at this point in the history
…ith single value setting (#7494)
  • Loading branch information
jimhorng authored and mistercrunch committed Jun 3, 2019
1 parent 45b9880 commit 78c1674
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions superset/jinja_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ def filter_values(column, default=None):

for f in form_data[filter_type]:
if f['col'] == column:
for v in f['val']:
return_val.append(v)
if isinstance(f['val'], list):
for v in f['val']:
return_val.append(v)
else:
return_val.append(f['val'])

if return_val:
return return_val
Expand Down
14 changes: 14 additions & 0 deletions tests/macro_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,19 @@ def test_filter_values_macro(self):
],
}

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)}
data2 = {'form_data': json.dumps(form_data2)}
data3 = {'form_data': json.dumps(form_data3)}
data4 = {'form_data': json.dumps(form_data4)}

with app.test_request_context(data=data1):
filter_values = jinja_context.filter_values('my_special_filter')
Expand All @@ -73,3 +83,7 @@ def test_filter_values_macro(self):
with app.test_request_context():
filter_values = jinja_context.filter_values('nonexistent_filter', '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'])

0 comments on commit 78c1674

Please sign in to comment.