mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Fixed hidden form fields bug #1527
This commit is contained in:
parent
515f8d38eb
commit
3a0f7d6488
2 changed files with 18 additions and 6 deletions
|
|
@ -815,7 +815,7 @@ class TableView(RowTableShared):
|
||||||
if (
|
if (
|
||||||
key.startswith("_")
|
key.startswith("_")
|
||||||
and key not in ("_sort", "_search", "_next")
|
and key not in ("_sort", "_search", "_next")
|
||||||
and not key.endswith("__exact")
|
and "__" not in key
|
||||||
):
|
):
|
||||||
for value in request.args.getlist(key):
|
for value in request.args.getlist(key):
|
||||||
form_hidden_args.append((key, value))
|
form_hidden_args.append((key, value))
|
||||||
|
|
|
||||||
|
|
@ -143,17 +143,29 @@ def test_existing_filter_redirects(app_client):
|
||||||
assert "?" not in response.headers["Location"]
|
assert "?" not in response.headers["Location"]
|
||||||
|
|
||||||
|
|
||||||
def test_exact_parameter_results_in_correct_hidden_fields(app_client):
|
@pytest.mark.parametrize(
|
||||||
|
"qs,expected_hidden",
|
||||||
|
(
|
||||||
|
# Things that should be reflected in hidden form fields:
|
||||||
|
("_facet=_neighborhood", {"_facet": "_neighborhood"}),
|
||||||
|
("_where=1+=+1&_col=_city_id", {"_where": "1 = 1", "_col": "_city_id"}),
|
||||||
|
# Things that should NOT be reflected in hidden form fields:
|
||||||
|
(
|
||||||
|
"_facet=_neighborhood&_neighborhood__exact=Downtown",
|
||||||
|
{"_facet": "_neighborhood"},
|
||||||
|
),
|
||||||
|
("_facet=_neighborhood&_city_id__gt=1", {"_facet": "_neighborhood"}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_reflected_hidden_form_fields(app_client, qs, expected_hidden):
|
||||||
# https://github.com/simonw/datasette/issues/1527
|
# https://github.com/simonw/datasette/issues/1527
|
||||||
response = app_client.get(
|
response = app_client.get("/fixtures/facetable?{}".format(qs))
|
||||||
"/fixtures/facetable?_facet=_neighborhood&_neighborhood__exact=Downtown"
|
|
||||||
)
|
|
||||||
# In this case we should NOT have a hidden _neighborhood__exact=Downtown field
|
# In this case we should NOT have a hidden _neighborhood__exact=Downtown field
|
||||||
form = Soup(response.body, "html.parser").find("form")
|
form = Soup(response.body, "html.parser").find("form")
|
||||||
hidden_inputs = {
|
hidden_inputs = {
|
||||||
input["name"]: input["value"] for input in form.select("input[type=hidden]")
|
input["name"]: input["value"] for input in form.select("input[type=hidden]")
|
||||||
}
|
}
|
||||||
assert hidden_inputs == {"_facet": "_neighborhood"}
|
assert hidden_inputs == expected_hidden
|
||||||
|
|
||||||
|
|
||||||
def test_empty_search_parameter_gets_removed(app_client):
|
def test_empty_search_parameter_gets_removed(app_client):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue