mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
?_nosuggest=1 parameter for table views, closes #1557
This commit is contained in:
parent
20a2ed6bec
commit
992496f261
3 changed files with 20 additions and 0 deletions
|
|
@ -388,6 +388,7 @@ class TableView(RowTableShared):
|
|||
|
||||
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
|
||||
|
|
@ -846,6 +847,7 @@ class TableView(RowTableShared):
|
|||
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())
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue