mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
?_nofacets=1 option, closes #1350
This commit is contained in:
parent
f7d3e76fb3
commit
c5ae1197a2
4 changed files with 28 additions and 7 deletions
|
|
@ -731,13 +731,14 @@ class TableView(RowTableShared):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
for facet in facet_instances:
|
if not request.args.get("_nofacets"):
|
||||||
(
|
for facet in facet_instances:
|
||||||
instance_facet_results,
|
(
|
||||||
instance_facets_timed_out,
|
instance_facet_results,
|
||||||
) = await facet.facet_results()
|
instance_facets_timed_out,
|
||||||
facet_results.update(instance_facet_results)
|
) = await facet.facet_results()
|
||||||
facets_timed_out.extend(instance_facets_timed_out)
|
facet_results.update(instance_facet_results)
|
||||||
|
facets_timed_out.extend(instance_facets_timed_out)
|
||||||
|
|
||||||
# Figure out columns and rows for the query
|
# Figure out columns and rows for the query
|
||||||
columns = [r[0] for r in results.description]
|
columns = [r[0] for r in results.description]
|
||||||
|
|
@ -828,6 +829,7 @@ class TableView(RowTableShared):
|
||||||
self.ds.setting("suggest_facets")
|
self.ds.setting("suggest_facets")
|
||||||
and self.ds.setting("allow_facet")
|
and self.ds.setting("allow_facet")
|
||||||
and not _next
|
and not _next
|
||||||
|
and not request.args.get("_nofacets")
|
||||||
):
|
):
|
||||||
for facet in facet_instances:
|
for facet in facet_instances:
|
||||||
suggested_facets.extend(await facet.suggest())
|
suggested_facets.extend(await facet.suggest())
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,8 @@ If Datasette detects that a column is a foreign key, the ``"label"`` property wi
|
||||||
|
|
||||||
The default number of facet results returned is 30, controlled by the :ref:`setting_default_facet_size` setting. You can increase this on an individual page by adding ``?_facet_size=100`` to the query string, up to a maximum of :ref:`setting_max_returned_rows` (which defaults to 1000).
|
The default number of facet results returned is 30, controlled by the :ref:`setting_default_facet_size` setting. You can increase this on an individual page by adding ``?_facet_size=100`` to the query string, up to a maximum of :ref:`setting_max_returned_rows` (which defaults to 1000).
|
||||||
|
|
||||||
|
.. _facets_metadata:
|
||||||
|
|
||||||
Facets in metadata.json
|
Facets in metadata.json
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -383,6 +383,9 @@ Special table arguments
|
||||||
``?_facet_size=100``
|
``?_facet_size=100``
|
||||||
Increase the number of facet results returned for each facet. Use ``?_facet_size=max`` for the maximum available size, determined by :ref:`setting_max_returned_rows`.
|
Increase the number of facet results returned for each facet. Use ``?_facet_size=max`` for the maximum available size, determined by :ref:`setting_max_returned_rows`.
|
||||||
|
|
||||||
|
``?_nofacets=1``
|
||||||
|
Disable all facets and facet suggestions for this page, including any defined by :ref:`facets_metadata`.
|
||||||
|
|
||||||
``?_trace=1``
|
``?_trace=1``
|
||||||
Turns on tracing for this page: SQL queries executed during the request will
|
Turns on tracing for this page: SQL queries executed during the request will
|
||||||
be gathered and included in the response, either in a new ``"_traces"`` key
|
be gathered and included in the response, either in a new ``"_traces"`` key
|
||||||
|
|
|
||||||
|
|
@ -1669,6 +1669,20 @@ def test_suggest_facets_off():
|
||||||
assert [] == client.get("/fixtures/facetable.json").json["suggested_facets"]
|
assert [] == client.get("/fixtures/facetable.json").json["suggested_facets"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("nofacets", (True, False))
|
||||||
|
def test_nofacets(app_client, nofacets):
|
||||||
|
path = "/fixtures/facetable.json?_facet=state"
|
||||||
|
if nofacets:
|
||||||
|
path += "&_nofacets=1"
|
||||||
|
response = app_client.get(path)
|
||||||
|
if nofacets:
|
||||||
|
assert response.json["suggested_facets"] == []
|
||||||
|
assert response.json["facet_results"] == {}
|
||||||
|
else:
|
||||||
|
assert response.json["suggested_facets"] != []
|
||||||
|
assert response.json["facet_results"] != {}
|
||||||
|
|
||||||
|
|
||||||
def test_expand_labels(app_client):
|
def test_expand_labels(app_client):
|
||||||
response = app_client.get(
|
response = app_client.get(
|
||||||
"/fixtures/facetable.json?_shape=object&_labels=1&_size=2"
|
"/fixtures/facetable.json?_shape=object&_labels=1&_size=2"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue