From 1ad3ebf2ed45e9e1f2caa7a91017b8899a6b4e46 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 14 Mar 2019 21:24:06 -0700 Subject: [PATCH] /dbname-hash now optional: turn on with --config hash_urls:1 --- datasette/app.py | 3 +++ datasette/templates/database.html | 14 ++++++------ datasette/templates/query.html | 6 +++--- datasette/templates/row.html | 6 +++--- datasette/templates/table.html | 8 +++---- datasette/views/base.py | 19 +++++++++++++--- datasette/views/database.py | 1 - datasette/views/index.py | 2 +- datasette/views/table.py | 2 -- docs/config.rst | 14 ++++++++++++ tests/fixtures.py | 7 ++++++ tests/test_api.py | 12 ++++++----- tests/test_html.py | 36 ++++++++++++------------------- 13 files changed, 79 insertions(+), 51 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index 37b199a4..f9268e44 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -69,6 +69,9 @@ CONFIG_OPTIONS = ( ConfigOption("facet_suggest_time_limit_ms", 50, """ Time limit for calculating a suggested facet """.strip()), + ConfigOption("hash_urls", False, """ + Include DB file contents hash in URLs, for far-future caching + """.strip()), ConfigOption("allow_facet", True, """ Allow users to specify columns to facet using ?_facet= parameter """.strip()), diff --git a/datasette/templates/database.html b/datasette/templates/database.html index f827e584..0e80c8b6 100644 --- a/datasette/templates/database.html +++ b/datasette/templates/database.html @@ -12,12 +12,12 @@ {% block content %}
home
-

{{ metadata.title or database }}

+

{{ metadata.title or database }}

{% block description_source_license %}{% include "_description_source_license.html" %}{% endblock %} {% if config.allow_sql %} -
+

Custom SQL query

@@ -27,7 +27,7 @@ {% for table in tables %} {% if show_hidden or not table.hidden %}
-

{{ table.name }}{% if table.hidden %} (hidden){% endif %}

+

{{ table.name }}{% if table.hidden %} (hidden){% endif %}

{% for column in table.columns[:9] %}{{ column }}{% if not loop.last %}, {% endif %}{% endfor %}{% if table.columns|length > 9 %}...{% endif %}

{{ "{:,}".format(table.count) }} row{% if table.count == 1 %}{% else %}s{% endif %}

@@ -35,14 +35,14 @@ {% endfor %} {% if hidden_count and not show_hidden %} -

... and {{ "{:,}".format(hidden_count) }} hidden table{% if hidden_count == 1 %}{% else %}s{% endif %}

+

... and {{ "{:,}".format(hidden_count) }} hidden table{% if hidden_count == 1 %}{% else %}s{% endif %}

{% endif %} {% if views %}

Views

{% endif %} @@ -51,13 +51,13 @@

Queries

{% endif %} {% if config.allow_download and database != ":memory:" %} -

Download SQLite DB: {{ database }}.db {{ format_bytes(size) }}

+

Download SQLite DB: {{ database }}.db {{ format_bytes(size) }}

{% endif %} {% include "_codemirror_foot.html" %} diff --git a/datasette/templates/query.html b/datasette/templates/query.html index b23c67d8..7f49ace4 100644 --- a/datasette/templates/query.html +++ b/datasette/templates/query.html @@ -19,13 +19,13 @@ {% block body_class %}query db-{{ database|to_css_class }}{% endblock %} {% block content %} - + -

{{ metadata.title or database }}

+

{{ metadata.title or database }}

{% block description_source_license %}{% include "_description_source_license.html" %}{% endblock %} - +

Custom SQL query{% if display_rows %} returning {% if truncated %}more than {% endif %}{{ "{:,}".format(display_rows|length) }} row{% if display_rows|length == 1 %}{% else %}s{% endif %}{% endif %}

{% if editable and config.allow_sql %}

diff --git a/datasette/templates/row.html b/datasette/templates/row.html index 4ef0b758..389b16b2 100644 --- a/datasette/templates/row.html +++ b/datasette/templates/row.html @@ -16,9 +16,9 @@ {% block body_class %}row db-{{ database|to_css_class }} table-{{ table|to_css_class }}{% endblock %} {% block content %} - + -

{{ table }}: {{ ', '.join(primary_key_values) }}

+

{{ table }}: {{ ', '.join(primary_key_values) }}

{% block description_source_license %}{% include "_description_source_license.html" %}{% endblock %} @@ -31,7 +31,7 @@