diff --git a/datasette/app.py b/datasette/app.py index c44f0617..2a5d569e 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -558,17 +558,10 @@ class Datasette: context = context or {} if isinstance(templates, Template): template = templates - select_templates = [] else: if isinstance(templates, str): templates = [templates] template = self.jinja_env.select_template(templates) - select_templates = [ - "{}{}".format( - "*" if template_name == template.name else "", template_name - ) - for template_name in templates - ] body_scripts = [] # pylint: disable=no-member for script in pm.hook.extra_body_script( @@ -603,7 +596,6 @@ class Datasette: **context, **{ "app_css_hash": self.app_css_hash(), - "select_templates": select_templates, "zip": zip, "body_scripts": body_scripts, "format_bytes": format_bytes, diff --git a/datasette/views/base.py b/datasette/views/base.py index ad05a2f3..2478bd84 100644 --- a/datasette/views/base.py +++ b/datasette/views/base.py @@ -79,6 +79,12 @@ class BaseView(AsgiView): **{ "database_url": self.database_url, "database_color": self.database_color, + "select_templates": [ + "{}{}".format( + "*" if template_name == template.name else "", template_name + ) + for template_name in templates + ], }, } return Response.html( diff --git a/tests/test_html.py b/tests/test_html.py index 58863d6d..6abd8f84 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -456,6 +456,33 @@ def test_css_classes_on_body(app_client, path, expected_classes): assert classes == expected_classes +@pytest.mark.parametrize( + "path,expected_considered", + [ + ("/", "*index.html"), + ("/fixtures", "database-fixtures.html, *database.html"), + ( + "/fixtures/simple_primary_key", + "table-fixtures-simple_primary_key.html, *table.html", + ), + ( + "/fixtures/table%2Fwith%2Fslashes.csv", + "table-fixtures-tablewithslashescsv-fa7563.html, *table.html", + ), + ( + "/fixtures/simple_primary_key/1", + "row-fixtures-simple_primary_key.html, *row.html", + ), + ], +) +def test_templates_considered(app_client, path, expected_considered): + response = app_client.get(path) + assert response.status == 200 + assert ( + "".format(expected_considered) in response.text + ) + + def test_table_html_simple_primary_key(app_client): response = app_client.get("/fixtures/simple_primary_key?_size=3") assert response.status == 200