kopia lustrzana https://github.com/simonw/datasette
Fix bug with facet_array= not returning facets
Refs https://github.com/simonw/datasette/pull/1999#issuecomment-1476898261pull/1999/head
rodzic
395bd6bb6b
commit
4bb4984869
|
@ -1954,7 +1954,7 @@ async def table_view_data(
|
||||||
|
|
||||||
# Resolve extras
|
# Resolve extras
|
||||||
extras = _get_extras(request)
|
extras = _get_extras(request)
|
||||||
if request.args.getlist("_facet"):
|
if any(k for k in request.args.keys() if k == "_facet" or k.startswith("_facet_")):
|
||||||
extras.add("facet_results")
|
extras.add("facet_results")
|
||||||
if request.args.get("_shape") == "object":
|
if request.args.get("_shape") == "object":
|
||||||
extras.add("primary_keys")
|
extras.add("primary_keys")
|
||||||
|
|
|
@ -927,6 +927,36 @@ async def test_facets(ds_client, path, expected_facet_results):
|
||||||
assert expected_facet_results == facet_results["results"]
|
assert expected_facet_results == facet_results["results"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@pytest.mark.skipif(not detect_json1(), reason="requires JSON1 extension")
|
||||||
|
async def test_facets_array(ds_client):
|
||||||
|
response = await ds_client.get("/fixtures/facetable.json?_facet_array=tags")
|
||||||
|
facet_results = response.json()["facet_results"]
|
||||||
|
assert facet_results["results"]["tags"]["results"] == [
|
||||||
|
{
|
||||||
|
"value": "tag1",
|
||||||
|
"label": "tag1",
|
||||||
|
"count": 2,
|
||||||
|
"toggle_url": "http://localhost/fixtures/facetable.json?_facet_array=tags&tags__arraycontains=tag1",
|
||||||
|
"selected": False,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "tag2",
|
||||||
|
"label": "tag2",
|
||||||
|
"count": 1,
|
||||||
|
"toggle_url": "http://localhost/fixtures/facetable.json?_facet_array=tags&tags__arraycontains=tag2",
|
||||||
|
"selected": False,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "tag3",
|
||||||
|
"label": "tag3",
|
||||||
|
"count": 1,
|
||||||
|
"toggle_url": "http://localhost/fixtures/facetable.json?_facet_array=tags&tags__arraycontains=tag3",
|
||||||
|
"selected": False,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_suggested_facets(ds_client):
|
async def test_suggested_facets(ds_client):
|
||||||
suggestions = [
|
suggestions = [
|
||||||
|
|
Ładowanie…
Reference in New Issue