Skip to content

Commit

Permalink
?_nosuggest=1 parameter for table views, closes #1557
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Dec 16, 2021
1 parent 20a2ed6 commit 992496f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions datasette/views/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ async def data(

nocount = request.args.get("_nocount")
nofacet = request.args.get("_nofacet")
nosuggest = request.args.get("_nosuggest")

if request.args.get("_shape") in ("array", "object"):
nocount = True
Expand Down Expand Up @@ -846,6 +847,7 @@ async def data(
and self.ds.setting("allow_facet")
and not _next
and not nofacet
and not nosuggest
):
for facet in facet_instances:
suggested_facets.extend(await facet.suggest())
Expand Down
3 changes: 3 additions & 0 deletions docs/json_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ Special table arguments
``?_nofacet=1``
Disable all facets and facet suggestions for this page, including any defined by :ref:`facets_metadata`.

``?_nosuggest=1``
Disable facet suggestions for this page.

``?_nocount=1``
Disable the ``select count(*)`` query used on this page - a count of ``None`` will be returned instead.

Expand Down
15 changes: 15 additions & 0 deletions tests/test_table_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,21 @@ def test_nofacet(app_client, nofacet):
assert response.json["facet_results"] != {}


@pytest.mark.parametrize("nosuggest", (True, False))
def test_nosuggest(app_client, nosuggest):
path = "/fixtures/facetable.json?_facet=state"
if nosuggest:
path += "&_nosuggest=1"
response = app_client.get(path)
if nosuggest:
assert response.json["suggested_facets"] == []
# But facets should still be returned:
assert response.json["facet_results"] != {}
else:
assert response.json["suggested_facets"] != []
assert response.json["facet_results"] != {}


@pytest.mark.parametrize("nocount,expected_count", ((True, None), (False, 15)))
def test_nocount(app_client, nocount, expected_count):
path = "/fixtures/facetable.json"
Expand Down

0 comments on commit 992496f

Please sign in to comment.