mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
?_col=/?_nocol= to show/hide columns on the table page
Closes #615 * Cog icon for hiding columns * Show all columns cog menu item * Do not allow hide column on primary keys * Allow both ?_col= and ?_nocol= * De-duplicate if ?_col= passed multiple times * 400 error if user tries to ?_nocol= a primary key * Documentation for ?_col= and ?_nocol=
This commit is contained in:
parent
c0a748e5c3
commit
f1c29fd6a1
4 changed files with 142 additions and 15 deletions
|
|
@ -2009,3 +2009,62 @@ def test_http_options_request(app_client):
|
|||
response = app_client.request("/fixtures", method="OPTIONS")
|
||||
assert response.status == 200
|
||||
assert response.text == "ok"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"path,expected_columns",
|
||||
(
|
||||
("/fixtures/facetable.json?_col=created", ["pk", "created"]),
|
||||
(
|
||||
"/fixtures/facetable.json?_nocol=created",
|
||||
[
|
||||
"pk",
|
||||
"planet_int",
|
||||
"on_earth",
|
||||
"state",
|
||||
"city_id",
|
||||
"neighborhood",
|
||||
"tags",
|
||||
"complex_array",
|
||||
"distinct_some_null",
|
||||
],
|
||||
),
|
||||
(
|
||||
"/fixtures/facetable.json?_col=state&_col=created",
|
||||
["pk", "state", "created"],
|
||||
),
|
||||
(
|
||||
"/fixtures/facetable.json?_col=state&_col=state",
|
||||
["pk", "state"],
|
||||
),
|
||||
(
|
||||
"/fixtures/facetable.json?_col=state&_col=created&_nocol=created",
|
||||
["pk", "state"],
|
||||
),
|
||||
(
|
||||
"/fixtures/simple_view.json?_nocol=content",
|
||||
["upper_content"],
|
||||
),
|
||||
("/fixtures/simple_view.json?_col=content", ["content"]),
|
||||
),
|
||||
)
|
||||
def test_col_nocol(app_client, path, expected_columns):
|
||||
response = app_client.get(path)
|
||||
assert response.status == 200
|
||||
columns = response.json["columns"]
|
||||
assert columns == expected_columns
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"path,expected_error",
|
||||
(
|
||||
("/fixtures/facetable.json?_col=bad", "_col=bad - invalid columns"),
|
||||
("/fixtures/facetable.json?_nocol=bad", "_nocol=bad - invalid columns"),
|
||||
("/fixtures/facetable.json?_nocol=pk", "_nocol=pk - invalid columns"),
|
||||
("/fixtures/simple_view.json?_col=bad", "_col=bad - invalid columns"),
|
||||
),
|
||||
)
|
||||
def test_col_nocol_errors(app_client, path, expected_error):
|
||||
response = app_client.get(path)
|
||||
assert response.status == 400
|
||||
assert response.json["error"] == expected_error
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue