Display 0 results, closes #637

This commit is contained in:
Simon Willison 2019-11-22 22:07:01 -08:00
commit d3e1c3017e
4 changed files with 53 additions and 26 deletions

View file

@ -327,3 +327,10 @@ a.not-underlined {
pre.wrapped-sql { pre.wrapped-sql {
white-space: pre-wrap; white-space: pre-wrap;
} }
p.zero-results {
border: 2px solid #ccc;
background-color: #eee;
padding: 0.5em;
font-style: italic;
}

View file

@ -1,4 +1,5 @@
<table class="rows-and-columns"> {% if display_rows %}
<table class="rows-and-columns">
<thead> <thead>
<tr> <tr>
{% for column in display_columns %} {% for column in display_columns %}
@ -25,4 +26,7 @@
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{% else %}
<p class="zero-results">0 records</p>
{% endif %}

View file

@ -73,6 +73,8 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{% else %}
<p class="zero-results">0 results</p>
{% endif %} {% endif %}
{% include "_codemirror_foot.html" %} {% include "_codemirror_foot.html" %}

View file

@ -1059,3 +1059,17 @@ def test_custom_table_include():
'1 - 2 - <a href="/fixtures/simple_primary_key/1">hello</a> <em>1</em>' '1 - 2 - <a href="/fixtures/simple_primary_key/1">hello</a> <em>1</em>'
"</div>" "</div>"
) == str(Soup(response.text, "html.parser").select_one("div.custom-table-row")) ) == 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"))