Skip to content

Commit

Permalink
Fixed bug with Templates considered comment, closes #689
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Apr 5, 2020
1 parent e89b0ef commit d55fe8c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
8 changes: 0 additions & 8 deletions datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,17 +558,10 @@ async def render_template(
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(
Expand Down Expand Up @@ -603,7 +596,6 @@ async def render_template(
**context,
**{
"app_css_hash": self.app_css_hash(),
"select_templates": select_templates,
"zip": zip,
"body_scripts": body_scripts,
"format_bytes": format_bytes,
Expand Down
6 changes: 6 additions & 0 deletions datasette/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ async def render(self, templates, request, context):
**{
"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(
Expand Down
27 changes: 27 additions & 0 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
"<!-- Templates considered: {} -->".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
Expand Down

0 comments on commit d55fe8c

Please sign in to comment.