Commit c424c3fe authored by bryhoyt's avatar bryhoyt

Parse optional named filters from filter url

Old format fltN_M still works, but the new format flt_name_operation coexists side-by-side.
parent 749161e7
...@@ -958,27 +958,34 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -958,27 +958,34 @@ class BaseModelView(BaseView, ActionsMixin):
sort_desc = request.args.get('desc', None, type=int) sort_desc = request.args.get('desc', None, type=int)
search = request.args.get('search', None) search = request.args.get('search', None)
filter_idx_by_label = dict((flt.query_label(), i) for i, flt in enumerate(self._filters))
# Gather filters # Gather filters
if self._filters: if self._filters:
sfilters = [] sfilters = []
for n in request.args: for n in request.args:
if n.startswith('flt'): if not n.startswith('flt'):
ofs = n.find('_')
if ofs == -1:
continue continue
pos, filter_label = n[3:].split('_', 1)
# If pos not specified, just add incrementally to the list.
pos = int(pos) if pos else len(sfilters)
try: try:
pos = int(n[3:ofs]) # See if filter is numeric
idx = int(n[ofs + 1:]) idx = int(filter_label)
except ValueError: except ValueError:
# If non-numeric, look filter up by name
try:
idx = filter_idx_by_label[filter_label]
except KeyError:
# No matching filter name
continue continue
if idx >= 0 and idx < len(self._filters): if 0 <= idx < len(self._filters):
flt = self._filters[idx] flt = self._filters[idx]
value = request.args[n] value = request.args[n]
if flt.validate(value): if flt.validate(value):
sfilters.append((pos, (idx, flt.clean(value)))) sfilters.append((pos, (idx, flt.clean(value))))
......
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