mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Fixed bug with Templates considered comment, closes #689
This commit is contained in:
parent
e89b0ef2f9
commit
d55fe8cdfc
3 changed files with 33 additions and 8 deletions
|
|
@ -558,17 +558,10 @@ class Datasette:
|
||||||
context = context or {}
|
context = context or {}
|
||||||
if isinstance(templates, Template):
|
if isinstance(templates, Template):
|
||||||
template = templates
|
template = templates
|
||||||
select_templates = []
|
|
||||||
else:
|
else:
|
||||||
if isinstance(templates, str):
|
if isinstance(templates, str):
|
||||||
templates = [templates]
|
templates = [templates]
|
||||||
template = self.jinja_env.select_template(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 = []
|
body_scripts = []
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
for script in pm.hook.extra_body_script(
|
for script in pm.hook.extra_body_script(
|
||||||
|
|
@ -603,7 +596,6 @@ class Datasette:
|
||||||
**context,
|
**context,
|
||||||
**{
|
**{
|
||||||
"app_css_hash": self.app_css_hash(),
|
"app_css_hash": self.app_css_hash(),
|
||||||
"select_templates": select_templates,
|
|
||||||
"zip": zip,
|
"zip": zip,
|
||||||
"body_scripts": body_scripts,
|
"body_scripts": body_scripts,
|
||||||
"format_bytes": format_bytes,
|
"format_bytes": format_bytes,
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,12 @@ class BaseView(AsgiView):
|
||||||
**{
|
**{
|
||||||
"database_url": self.database_url,
|
"database_url": self.database_url,
|
||||||
"database_color": self.database_color,
|
"database_color": self.database_color,
|
||||||
|
"select_templates": [
|
||||||
|
"{}{}".format(
|
||||||
|
"*" if template_name == template.name else "", template_name
|
||||||
|
)
|
||||||
|
for template_name in templates
|
||||||
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return Response.html(
|
return Response.html(
|
||||||
|
|
|
||||||
|
|
@ -456,6 +456,33 @@ def test_css_classes_on_body(app_client, path, expected_classes):
|
||||||
assert classes == 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):
|
def test_table_html_simple_primary_key(app_client):
|
||||||
response = app_client.get("/fixtures/simple_primary_key?_size=3")
|
response = app_client.get("/fixtures/simple_primary_key?_size=3")
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue