Fix missing space before the view count on the index page (#2951)

Fixes the "0 tables1 view" bug, closes #2012
This commit is contained in:
Dipak Chaudhari 2026-09-25 00:20:01 +05:30 • committed by GitHub
commit e4e6f91962
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 2 deletions

View file

@ -26,8 +26,7 @@
{% if database.show_table_row_counts %}{{ "{:,}".format(database.hidden_table_rows_sum) }} rows in {% endif %}{{ database.hidden_tables_count }} hidden table{% if database.hidden_tables_count != 1 %}s{% endif -%}
{% endif -%}
{% if database.views_count -%}
{% if database.tables_count or database.hidden_tables_count %}, {% endif -%}
{{ "{:,}".format(database.views_count) }} view{% if database.views_count != 1 %}s{% endif %}
, {{ "{:,}".format(database.views_count) }} view{% if database.views_count != 1 %}s{% endif %}
{% endif %}
</p>
<p>{% for table in database.tables_and_views_truncated %}<a href="{{ urls.table(database.name, table.name) }}"{% if table.count %} title="{{ table.count }} rows"{% endif %}>{{ table.name }}</a>{% if table.private %} 🔒{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if database.tables_and_views_more %}, <a href="{{ urls.database(database.name) }}">...</a>{% endif %}</p>

View file

@ -51,6 +51,36 @@ def test_homepage(app_client_two_attached_databases):
] == table_links
@pytest.mark.asyncio
@pytest.mark.parametrize(
"sql,expected",
(
(["create view one as select 1 as n"], "0 tables, 1 view"),
(
["create view one as select 1 as n", "create view two as select 2 as n"],
"0 tables, 2 views",
),
(
["create table t (id integer primary key)", "create view v as select 1"],
"0 rows in 1 table, 1 view",
),
),
)
async def test_homepage_database_summary_separators(sql, expected):
# https://github.com/simonw/datasette/issues/2012
ds = Datasette()
await ds.invoke_startup()
db = ds.add_memory_database("summary_separators")
for statement in sql:
await db.execute_write(statement)
response = await ds.client.get("/")
assert response.status_code == 200
soup = Soup(response.text, "html.parser")
h2 = next(h2 for h2 in soup.select("h2") if h2.text.strip() == "summary_separators")
counts_p = h2.find_next("p")
assert " ".join(counts_p.text.split()) == expected
@pytest.mark.asyncio
@pytest.mark.parametrize("path", ("/", "/-/"))
async def test_homepage_alternative_location(path, tmp_path_factory):