Skip to content

Commit

Permalink
Fixed bug with human filter description, refs #189
Browse files Browse the repository at this point in the history
We were showing this:

    201 rows where sorted by sortable_with_nulls

We now show this:

    201 rows sorted by sortable_with_nulls
  • Loading branch information
simonw authored and Simon Willison committed Apr 9, 2018
1 parent 23e0fdb commit c1d37fd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion datasette/templates/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1 style="padding-left: 10px; border-left: 10px solid #{{ database_hash[:6] }}"

{% if filtered_table_rows or human_description_en %}
<h3>{% 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 %}
</h3>
{% endif %}

Expand Down
5 changes: 4 additions & 1 deletion datasette/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit c1d37fd

Please sign in to comment.