Views now show their SQL, are handled a bit better

Refs #66
This commit is contained in:
Simon Willison 2017-11-12 12:31:46 -08:00
commit ff2ab9dc7d
4 changed files with 43 additions and 27 deletions

View file

@ -20,7 +20,7 @@
{% for table in tables %}
<div class="db-table">
<h2><a href="/{{ database }}-{{ database_hash }}/{{ table.name }}">{{ table.name }}</a></h2>
<h2><a href="/{{ database }}-{{ database_hash }}/{{ table.name|urlencode }}">{{ table.name }}</a></h2>
<p><em>{% for column in table.columns[:9] %}{{ column }}{% if not loop.last %}, {% endif %}{% endfor %}{% if table.columns|length > 9 %}...{% endif %}</em></p>
<p>{{ "{:,}".format(table.table_rows) }} row{% if table.table_rows == 1 %}{% else %}s{% endif %}</p>
</div>
@ -30,31 +30,9 @@
<h2>Views</h2>
<ul>
{% for view in views %}
<li><a href="/{{ database }}-{{ database_hash }}/{{ view }}">{{ view }}</a></li>
<li><a href="/{{ database }}-{{ database_hash }}/{{ view|urlencode }}">{{ view }}</a></li>
{% endfor %}
</ul>
{% endif %}
<table>
<thead>
<tr>
{% for column in columns %}<th scope="col">{{ column }}</th>{% endfor %}
</tr>
</thead>
<tbody>
{% for row in rows %}
<tr>
{% for td in row %}
<td>
{% if loop.index == 2 and row.type in ("table", "view") %}
<a href="/{{ database }}-{{ database_hash }}/{{ td }}">{{ td }}</a>
{% else %}
{{ td }}
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View file

@ -16,7 +16,7 @@
{% block content %}
<div class="hd"><a href="/">home</a> / <a href="/{{ database }}-{{ database_hash }}">{{ database }}</a></div>
<h1 style="padding-left: 10px; border-left: 10px solid #{{ database_hash[:6] }}">{{ table }}</h1>
<h1 style="padding-left: 10px; border-left: 10px solid #{{ database_hash[:6] }}">{{ table }}{% if is_view %} (view){% endif %}</h1>
{% if table_rows != None %}
<h2>{{ "{:,}".format(table_rows) }} total row{% if table_rows == 1 %}{% else %}s{% endif %} in this table</h2>
@ -24,6 +24,10 @@
<p>This data as <a href="{{ url_json }}">.json</a>, <a href="{{ url_jsono }}">.jsono</a></p>
{% if view_definition %}
<pre>{{ view_definition }}</pre>
{% endif %}
<table>
<thead>
<tr>