kopia lustrzana https://github.com/simonw/datasette
?_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 #86pull/104/head
rodzic
386fb11d42
commit
a5881e105a
|
@ -431,6 +431,8 @@ class TableView(BaseView):
|
|||
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,
|
||||
|
|
|
@ -249,6 +249,16 @@ def test_add_filter_redirects(app_client):
|
|||
assert response.status == 302
|
||||
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 = '''
|
||||
CREATE TABLE simple_primary_key (
|
||||
|
|
Ładowanie…
Reference in New Issue