mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Even more complicated redirect scheme
This:
?_filter_column_1=name&_filter_op_1=contains&_filter_value_1=hello
&_filter_column_2=age&_filter_op_2=gte&_filter_value_2=12
Now redirects to this:
?name__contains=hello&age__gte=12
This is needed for the filter editing interface, refs #86
This commit is contained in:
parent
c8e7c85fd3
commit
53534b6e9d
3 changed files with 78 additions and 21 deletions
|
|
@ -22,6 +22,7 @@ from .utils import (
|
|||
detect_fts_sql,
|
||||
escape_css_string,
|
||||
escape_sqlite_table_name,
|
||||
filters_should_redirect,
|
||||
get_all_foreign_keys,
|
||||
InvalidSql,
|
||||
path_from_row_pks,
|
||||
|
|
@ -425,18 +426,9 @@ class TableView(BaseView):
|
|||
other_args[key] = value[0]
|
||||
|
||||
# Handle ?_filter_column and redirect, if present
|
||||
if '_filter_column' in special_args:
|
||||
filter_column = special_args['_filter_column']
|
||||
filter_op = special_args.get('_filter_op') or ''
|
||||
filter_value = special_args.get('_filter_value') or ''
|
||||
if '__' in filter_op:
|
||||
filter_op, filter_value = filter_op.split('__', 1)
|
||||
return self.redirect(request, path_with_added_args(request, {
|
||||
'{}__{}'.format(filter_column, filter_op): filter_value,
|
||||
'_filter_column': None,
|
||||
'_filter_op': None,
|
||||
'_filter_value': None,
|
||||
}))
|
||||
redirect_params = filters_should_redirect(special_args)
|
||||
if redirect_params:
|
||||
return self.redirect(request, path_with_added_args(request, redirect_params))
|
||||
|
||||
filters = Filters(sorted(other_args.items()))
|
||||
where_clauses, params = filters.build_where_clauses()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue