mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
?_filter_column=col&_filter_op=isnull__1 redirect
if filter_op contains a __ the value is set to the right hand side.
e.g.
?_filter_column=col&_filter_op=isnull__1&_filter_value=x
Redirects to:
?col__isnull=1
Refs #86
This commit is contained in:
parent
386fb11d42
commit
a5881e105a
2 changed files with 12 additions and 0 deletions
|
|
@ -431,6 +431,8 @@ class TableView(BaseView):
|
||||||
filter_column = special_args['_filter_column']
|
filter_column = special_args['_filter_column']
|
||||||
filter_op = special_args.get('_filter_op') or ''
|
filter_op = special_args.get('_filter_op') or ''
|
||||||
filter_value = special_args.get('_filter_value') 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, {
|
return self.redirect(request, path_with_added_args(request, {
|
||||||
'{}__{}'.format(filter_column, filter_op): filter_value,
|
'{}__{}'.format(filter_column, filter_op): filter_value,
|
||||||
'_filter_column': None,
|
'_filter_column': None,
|
||||||
|
|
|
||||||
|
|
@ -249,6 +249,16 @@ def test_add_filter_redirects(app_client):
|
||||||
assert response.status == 302
|
assert response.status == 302
|
||||||
assert response.headers['Location'].endswith('?content__startswith=x&foo=bar')
|
assert response.headers['Location'].endswith('?content__startswith=x&foo=bar')
|
||||||
|
|
||||||
|
# Test that op with a __x suffix overrides the filter value
|
||||||
|
path = path_base + '?' + urllib.parse.urlencode({
|
||||||
|
'_filter_column': 'content',
|
||||||
|
'_filter_op': 'isnull__5',
|
||||||
|
'_filter_value': 'x'
|
||||||
|
})
|
||||||
|
response = app_client.get(path, allow_redirects=False, gather_request=False)
|
||||||
|
assert response.status == 302
|
||||||
|
assert response.headers['Location'].endswith('?content__isnull=5')
|
||||||
|
|
||||||
|
|
||||||
TABLES = '''
|
TABLES = '''
|
||||||
CREATE TABLE simple_primary_key (
|
CREATE TABLE simple_primary_key (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue