kopia lustrzana https://github.com/simonw/datasette
rodzic
fa42a56c6a
commit
2366a016f2
|
@ -20,6 +20,7 @@ from .utils import (
|
|||
InvalidSql,
|
||||
path_from_row_pks,
|
||||
path_with_added_args,
|
||||
path_with_ext,
|
||||
compound_pks_from_path,
|
||||
sqlite_timelimit,
|
||||
validate_sql_select,
|
||||
|
@ -174,7 +175,10 @@ class BaseView(HTTPMethodView):
|
|||
extra_template_data()
|
||||
if callable(extra_template_data)
|
||||
else extra_template_data
|
||||
)}
|
||||
), **{
|
||||
'url_json': path_with_ext(request, '.json'),
|
||||
'url_jsono': path_with_ext(request, '.jsono'),
|
||||
}}
|
||||
r = self.jinja.render(
|
||||
self.template,
|
||||
request,
|
||||
|
@ -240,19 +244,26 @@ class DatabaseView(BaseView):
|
|||
|
||||
async def data(self, request, name, hash):
|
||||
sql = 'select * from sqlite_master'
|
||||
custom_sql = False
|
||||
params = {}
|
||||
if request.args.get('sql'):
|
||||
params = request.raw_args
|
||||
sql = params.pop('sql')
|
||||
validate_sql_select(sql)
|
||||
custom_sql = True
|
||||
rows = await self.execute(name, sql, params)
|
||||
columns = [r[0] for r in rows.description]
|
||||
return {
|
||||
'database': name,
|
||||
'rows': rows,
|
||||
'columns': columns,
|
||||
'query': {
|
||||
'sql': sql,
|
||||
'params': params,
|
||||
}
|
||||
}, {
|
||||
'database_hash': hash,
|
||||
'custom_sql': custom_sql,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,11 @@
|
|||
|
||||
<h1 style="padding-left: 10px; border-left: 10px solid #{{ database_hash[:6] }}">{{ database }}</h1>
|
||||
|
||||
<p><a href="/{{ database }}-{{ database_hash }}.db">download {{ database }}.db</a></p>
|
||||
{% if custom_sql %}
|
||||
<p>This data as <a href="{{ url_json }}">.json</a>, <a href="{{ url_jsono }}">.jsono</a></p>
|
||||
{% else %}
|
||||
<p><a href="/{{ database }}-{{ database_hash }}.db">download {{ database }}.db</a></p>
|
||||
{% endif %}
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
<h1 style="padding-left: 10px; border-left: 10px solid #{{ database_hash[:6] }}">{{ table }}: {{ ', '.join(primary_key_values) }}</a></h1>
|
||||
|
||||
<p>This data as <a href="{{ url_json }}">.json</a>, <a href="{{ url_jsono }}">.jsono</a></p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
<h2>{{ "{:,}".format(table_rows) }} total row{% if table_rows == 1 %}{% else %}s{% endif %} in this table</h2>
|
||||
{% endif %}
|
||||
|
||||
<p>This data as <a href="{{ url_json }}">.json</a>, <a href="{{ url_jsono }}">.jsono</a></p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -42,8 +44,10 @@
|
|||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
{% if after_link %}
|
||||
<p><a href="{{ after_link }}">Next page</a></p>
|
||||
<p><a href="{{ after_link }}">Next page</a></p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -110,6 +110,14 @@ def path_with_added_args(request, args):
|
|||
return request.path + '?' + urllib.parse.urlencode(current)
|
||||
|
||||
|
||||
def path_with_ext(request, ext):
|
||||
path = request.path
|
||||
path += ext
|
||||
if request.query_string:
|
||||
path += '?' + request.query_string
|
||||
return path
|
||||
|
||||
|
||||
_css_re = re.compile(r'''['"\n\\]''')
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue