kopia lustrzana https://github.com/simonw/datasette
Expose extra_template_vars in _contex=1, refs #693
rodzic
09253817de
commit
e89b0ef2f9
|
@ -14,6 +14,7 @@ from pathlib import Path
|
|||
|
||||
import click
|
||||
from markupsafe import Markup
|
||||
import jinja2
|
||||
from jinja2 import ChoiceLoader, Environment, FileSystemLoader, PrefixLoader, escape
|
||||
from jinja2.environment import Template
|
||||
import uvicorn
|
||||
|
@ -612,6 +613,11 @@ class Datasette:
|
|||
},
|
||||
**extra_template_vars,
|
||||
}
|
||||
if request and request.args.get("_context") and self.config("template_debug"):
|
||||
return "<pre>{}</pre>".format(
|
||||
jinja2.escape(json.dumps(template_context, default=repr, indent=4))
|
||||
)
|
||||
|
||||
return await template.render_async(template_context)
|
||||
|
||||
def _asset_urls(self, key, template, context):
|
||||
|
|
|
@ -6,7 +6,6 @@ import re
|
|||
import time
|
||||
import urllib
|
||||
|
||||
import jinja2
|
||||
import pint
|
||||
|
||||
from datasette import __version__
|
||||
|
@ -82,16 +81,6 @@ class BaseView(AsgiView):
|
|||
"database_color": self.database_color,
|
||||
},
|
||||
}
|
||||
if (
|
||||
request
|
||||
and request.args.get("_context")
|
||||
and self.ds.config("template_debug")
|
||||
):
|
||||
return Response.html(
|
||||
"<pre>{}</pre>".format(
|
||||
jinja2.escape(json.dumps(template_context, default=repr, indent=4))
|
||||
)
|
||||
)
|
||||
return Response.html(
|
||||
await self.ds.render_template(
|
||||
template, template_context, request=request, view_name=self.name
|
||||
|
|
|
@ -1097,6 +1097,14 @@ def test_config_template_debug_off(app_client):
|
|||
assert not response.text.startswith("<pre>{")
|
||||
|
||||
|
||||
def test_debug_context_includes_extra_template_vars():
|
||||
# https://github.com/simonw/datasette/issues/693
|
||||
for client in make_app_client(config={"template_debug": True}):
|
||||
response = client.get("/fixtures/facetable?_context=1")
|
||||
# scope_path is added by PLUGIN1
|
||||
assert "scope_path" in response.text
|
||||
|
||||
|
||||
def test_metadata_sort(app_client):
|
||||
response = app_client.get("/fixtures/facet_cities")
|
||||
assert response.status == 200
|
||||
|
|
Ładowanie…
Reference in New Issue