Skip to content

Commit

Permalink
Reformatted with black
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Feb 13, 2020
1 parent 30b6f71 commit 298a899
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
4 changes: 3 additions & 1 deletion datasette/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ class InvalidSql(Exception):


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()
if not any(r.match(sql) for r in allowed_sql_res):
raise InvalidSql("Statement must be a SELECT")
Expand Down
24 changes: 14 additions & 10 deletions datasette/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,25 @@ def database_color(self, database):
async def render(self, templates, request, context):
template = self.ds.jinja_env.select_template(templates)
template_context = {
**context,
**{
"database_url": self.database_url,
"database_color": self.database_color,
},
}
if request and request.args.get("_context") and self.ds.config("template_debug"):
**context,
**{
"database_url": self.database_url,
"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
))
return Response.html(
await self.ds.render_template(template, template_context, request=request)
)


class DataView(BaseView):
Expand Down

0 comments on commit 298a899

Please sign in to comment.