Skip to content
Permalink
Browse files

Display 0 results, closes #637

  • Loading branch information
simonw committed Nov 23, 2019
1 parent fd137da commit d3e1c3017ee2f606a731208d59fe48805cdc3259
Showing with 53 additions and 26 deletions.
  1. +7 −0 datasette/static/app.css
  2. +30 −26 datasette/templates/_table.html
  3. +2 −0 datasette/templates/query.html
  4. +14 −0 tests/test_html.py
@@ -327,3 +327,10 @@ a.not-underlined {
pre.wrapped-sql {
white-space: pre-wrap;
}

p.zero-results {
border: 2px solid #ccc;
background-color: #eee;
padding: 0.5em;
font-style: italic;
}
@@ -1,28 +1,32 @@
<table class="rows-and-columns">
<thead>
<tr>
{% for column in display_columns %}
<th class="col-{{ column.name|to_css_class }}" scope="col">
{% if not column.sortable %}
{{ column.name }}
{% else %}
{% if column.name == sort %}
<a href="{{ path_with_replaced_args(request, {'_sort_desc': column.name, '_sort': None, '_next': None}) }}" rel="nofollow">{{ column.name }}&nbsp;▼</a>
{% if display_rows %}
<table class="rows-and-columns">
<thead>
<tr>
{% for column in display_columns %}
<th class="col-{{ column.name|to_css_class }}" scope="col">
{% if not column.sortable %}
{{ column.name }}
{% else %}
<a href="{{ path_with_replaced_args(request, {'_sort': column.name, '_sort_desc': None, '_next': None}) }}" rel="nofollow">{{ column.name }}{% if column.name == sort_desc %}&nbsp;▲{% endif %}</a>
{% if column.name == sort %}
<a href="{{ path_with_replaced_args(request, {'_sort_desc': column.name, '_sort': None, '_next': None}) }}" rel="nofollow">{{ column.name }}&nbsp;▼</a>
{% else %}
<a href="{{ path_with_replaced_args(request, {'_sort': column.name, '_sort_desc': None, '_next': None}) }}" rel="nofollow">{{ column.name }}{% if column.name == sort_desc %}&nbsp;▲{% endif %}</a>
{% endif %}
{% endif %}
{% endif %}
</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in display_rows %}
<tr>
{% for cell in row %}
<td class="col-{{ cell.column|to_css_class }}">{{ cell.value }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in display_rows %}
<tr>
{% for cell in row %}
<td class="col-{{ cell.column|to_css_class }}">{{ cell.value }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p class="zero-results">0 records</p>
{% endif %}
@@ -73,6 +73,8 @@ <h3>Query parameters</h3>
{% endfor %}
</tbody>
</table>
{% else %}
<p class="zero-results">0 results</p>
{% endif %}

{% include "_codemirror_foot.html" %}
@@ -1059,3 +1059,17 @@ def test_custom_table_include():
'1 - 2 - <a href="/fixtures/simple_primary_key/1">hello</a> <em>1</em>'
"</div>"
) == str(Soup(response.text, "html.parser").select_one("div.custom-table-row"))


@pytest.mark.parametrize(
"path",
[
"/fixtures?sql=select+*+from+[123_starts_with_digits]",
"/fixtures/123_starts_with_digits",
],
)
def test_zero_results(app_client, path):
response = app_client.get(path)
soup = Soup(response.text, "html.parser")
assert 0 == len(soup.select("table"))
assert 1 == len(soup.select("p.zero-results"))

0 comments on commit d3e1c30

Please sign in to comment.
You can’t perform that action at this time.