mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Reformatted with black
This commit is contained in:
parent
30b6f71b30
commit
298a899e79
2 changed files with 17 additions and 11 deletions
|
|
@ -174,7 +174,9 @@ disallawed_sql_res = [(re.compile("pragma"), "Statement may not contain PRAGMA")
|
||||||
|
|
||||||
|
|
||||||
def validate_sql_select(sql):
|
def validate_sql_select(sql):
|
||||||
sql = "\n".join(line for line in sql.split('\n') if not line.strip().startswith('--'))
|
sql = "\n".join(
|
||||||
|
line for line in sql.split("\n") if not line.strip().startswith("--")
|
||||||
|
)
|
||||||
sql = sql.strip().lower()
|
sql = sql.strip().lower()
|
||||||
if not any(r.match(sql) for r in allowed_sql_res):
|
if not any(r.match(sql) for r in allowed_sql_res):
|
||||||
raise InvalidSql("Statement must be a SELECT")
|
raise InvalidSql("Statement must be a SELECT")
|
||||||
|
|
|
||||||
|
|
@ -75,21 +75,25 @@ class BaseView(AsgiView):
|
||||||
async def render(self, templates, request, context):
|
async def render(self, templates, request, context):
|
||||||
template = self.ds.jinja_env.select_template(templates)
|
template = self.ds.jinja_env.select_template(templates)
|
||||||
template_context = {
|
template_context = {
|
||||||
**context,
|
**context,
|
||||||
**{
|
**{
|
||||||
"database_url": self.database_url,
|
"database_url": self.database_url,
|
||||||
"database_color": self.database_color,
|
"database_color": self.database_color,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if request and request.args.get("_context") and self.ds.config("template_debug"):
|
if (
|
||||||
|
request
|
||||||
|
and request.args.get("_context")
|
||||||
|
and self.ds.config("template_debug")
|
||||||
|
):
|
||||||
return Response.html(
|
return Response.html(
|
||||||
"<pre>{}</pre>".format(
|
"<pre>{}</pre>".format(
|
||||||
jinja2.escape(json.dumps(template_context, default=repr, indent=4))
|
jinja2.escape(json.dumps(template_context, default=repr, indent=4))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return Response.html(await self.ds.render_template(
|
return Response.html(
|
||||||
template, template_context, request=request
|
await self.ds.render_template(template, template_context, request=request)
|
||||||
))
|
)
|
||||||
|
|
||||||
|
|
||||||
class DataView(BaseView):
|
class DataView(BaseView):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue