Commit ef7d89d7 authored by P.J. Janse van Rensburg's avatar P.J. Janse van Rensburg

Merge branch 'custom-message' of git://github.com/PaulWasTaken/flask-admin...

Merge branch 'custom-message' of git://github.com/PaulWasTaken/flask-admin into PaulWasTaken-custom-message
parents 5c3ba0e2 9cae4b37
...@@ -1701,29 +1701,39 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -1701,29 +1701,39 @@ class BaseModelView(BaseView, ActionsMixin):
def get_empty_list_message(self): def get_empty_list_message(self):
return gettext('There are no items in the table.') return gettext('There are no items in the table.')
def get_invalid_value_msg(self, value, filter):
"""
Returns message, which should be printed in case of failed validation.
:param value: Invalid value
:param filter: Filter
:return: string
"""
return gettext('Invalid Filter Value: %(value)s', value=value)
# URL generation helpers # URL generation helpers
def _get_list_filter_args(self): def _get_list_filter_args(self):
if self._filters: if self._filters:
filters = [] filters = []
for n in request.args: for arg in request.args:
if not n.startswith('flt'): if not arg.startswith('flt'):
continue continue
if '_' not in n: if '_' not in arg:
continue continue
pos, key = n[3:].split('_', 1) pos, key = arg[3:].split('_', 1)
if key in self._filter_args: if key in self._filter_args:
idx, flt = self._filter_args[key] idx, flt = self._filter_args[key]
value = request.args[n] value = request.args[arg]
if flt.validate(value): if flt.validate(value):
filters.append((pos, (idx, as_unicode(flt.name), value))) data = (pos, (idx, as_unicode(flt.name), value))
filters.append(data)
else: else:
flash(gettext('Invalid Filter Value: %(value)s', value=value), 'error') flash(self.get_invalid_value_msg(value, flt), 'error')
# Sort filters # Sort filters
return [v[1] for v in sorted(filters, key=lambda n: n[0])] return [v[1] for v in sorted(filters, key=lambda n: n[0])]
......
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