mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
3cce63b598
commit
2a9799bae6
4 changed files with 24 additions and 5 deletions
17
app.py
17
app.py
|
|
@ -153,7 +153,22 @@ class BaseView(HTTPMethodView):
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
async def index(request, sql=None):
|
async def index(request, sql=None):
|
||||||
databases = ensure_build_metadata(True)
|
databases = []
|
||||||
|
for key, info in ensure_build_metadata(True).items():
|
||||||
|
database = {
|
||||||
|
'name': key,
|
||||||
|
'hash': info['hash'],
|
||||||
|
'path': '{}-{}'.format(key, info['hash'][:7]),
|
||||||
|
'tables_truncated': sorted(
|
||||||
|
info['tables'].items(),
|
||||||
|
key=lambda p: p[1],
|
||||||
|
reverse=True
|
||||||
|
)[:5],
|
||||||
|
'tables_count': len(info['tables'].items()),
|
||||||
|
'tables_more': len(info['tables'].items()) > 5,
|
||||||
|
'total_rows': sum(info['tables'].values()),
|
||||||
|
}
|
||||||
|
databases.append(database)
|
||||||
return jinja.render(
|
return jinja.render(
|
||||||
'index.html',
|
'index.html',
|
||||||
request,
|
request,
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ database }}</h1>
|
<h1>{{ database }}</h1>
|
||||||
|
|
||||||
|
<p><a href="/{{ database }}-{{ database_hash }}.db">download {{ database }}.db</a></p>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
td {
|
td {
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,11 @@
|
||||||
{% block title %}Databases{% endblock %}
|
{% block title %}Databases{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Database{% if databases.keys()|length != 1 %}s{% endif %}</h1>
|
<h1>Database{% if databases|length != 1 %}s{% endif %}</h1>
|
||||||
{% for name, info in databases.items() %}
|
{% for database in databases %}
|
||||||
<p><a href="{{ name}}-{{ info.hash|truncate(7, end='') }}">{{ name }}</a></p>
|
<h2><a href="{{ database.path }}">{{ database.name }}</a></h2>
|
||||||
|
<p>{{ "{:,}".format(database.total_rows) }} rows in {{ database.tables_count }} table{% if database.tables_count != 1 %}s{% endif %}</p>
|
||||||
|
<p>{% for table, count in database.tables_truncated %}<a href="{{ database.path }}/{{ table }}" title="{{ count }} rows">{{ table }}</a>{% if not loop.last %}, {% endif %}{% endfor %}{% if database.tables_more %}, <a href="{{ database.path }}">...</a>{% endif %}</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1><a href="/{{ database }}-{{ database_hash }}">{{ database }}</a></h1>
|
<h1><a href="/{{ database }}-{{ database_hash }}">{{ database }}</a></h1>
|
||||||
|
|
||||||
<h2>{{ table }}{% if total_rows != None %} ({{ total_rows }} total row{% if total_rows == 1 %}{% else %}s{% endif %} in this table){% endif %}</h2>
|
<h2>{{ table }}{% if total_rows != None %} ({{ "{:,}".format(total_rows) }} total row{% if total_rows == 1 %}{% else %}s{% endif %} in this table){% endif %}</h2>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
td {
|
td {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue