Commit 2348cf2f authored by Serge S. Koval's avatar Serge S. Koval

Fixed #509. Callable filter options.

parent a76c004d
...@@ -30,8 +30,13 @@ class BaseFilter(object): ...@@ -30,8 +30,13 @@ class BaseFilter(object):
:param view: :param view:
Associated administrative view class. Associated administrative view class.
""" """
if self.options: options = self.options
return [(v, text_type(n)) for v, n in self.options]
if options:
if callable(options):
options = options()
return [(v, text_type(n)) for v, n in options]
return None return None
......
...@@ -308,6 +308,19 @@ def test_column_filters(): ...@@ -308,6 +308,19 @@ def test_column_filters():
# TODO: Make calls with filters # TODO: Make calls with filters
def test_filter_list_callable():
app, admin = setup()
flt = SimpleFilter('test', options=lambda: (('1', 'Test 1'), ('2', 'Test 2')))
view = MockModelView(Model, column_filters=[flt])
admin.add_view(view)
opts = flt.get_options(view)
eq_(len(opts), 2)
eq_(opts, [('1', u'Test 1'), ('2', u'Test 2')])
def test_form(): def test_form():
# TODO: form_columns # TODO: form_columns
# TODO: form_excluded_columns # TODO: form_excluded_columns
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment