From fdd6b71e40c8aa9a93e95802a8b6291099d4db2c Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 8 Apr 2018 22:07:18 -0700 Subject: [PATCH] Fixed bug with human filter description, refs #189 We were showing this: 201 rows where sorted by sortable_with_nulls We now show this: 201 rows sorted by sortable_with_nulls --- datasette/templates/table.html | 2 +- datasette/utils.py | 5 ++++- tests/test_api.py | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/datasette/templates/table.html b/datasette/templates/table.html index 3238e83f31..56fd47449c 100644 --- a/datasette/templates/table.html +++ b/datasette/templates/table.html @@ -25,7 +25,7 @@

{% if filtered_table_rows or filtered_table_rows == 0 %}{{ "{:,}".format(filtered_table_rows) }} row{% if filtered_table_rows == 1 %}{% else %}s{% endif %}{% endif %} - {% if human_description_en %}where {{ human_description_en }}{% endif %} + {% if human_description_en %}{{ human_description_en }}{% endif %}

{% endif %} diff --git a/datasette/utils.py b/datasette/utils.py index 4a2e0ed5aa..7f581741d6 100644 --- a/datasette/utils.py +++ b/datasette/utils.py @@ -475,7 +475,10 @@ def human_description_en(self, extra=None): and_bits.append(', '.join(commas)) if tail: and_bits.append(tail[0]) - return ' and '.join(and_bits) + s = ' and '.join(and_bits) + if not s: + return '' + return 'where {}'.format(s) def selections(self): "Yields (column, lookup, value) tuples" diff --git a/tests/test_api.py b/tests/test_api.py index da1672430e..311938a194 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -388,6 +388,8 @@ def test_sortable_and_filtered(app_client): ) response = app_client.get(path, gather_request=False) fetched = response.json['rows'] + assert 'where content contains "d" sorted by sortable descending' \ + == response.json['human_description_en'] expected = [ row for row in generate_sortable_rows(201) if 'd' in row['content']