From b3e739332624c2d4f2668a105afd727af774100b Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 14 Mar 2019 21:41:43 -0700 Subject: [PATCH 1/4] Allow more recent versions of Click Closes #414 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 92b92c3f..fb00f2d0 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ setup( package_data={'datasette': ['templates/*.html']}, include_package_data=True, install_requires=[ - 'click==6.7', + 'click>=6.7', 'click-default-group==1.2', 'Sanic==0.7.0', 'Jinja2==2.10', From 285566790879b31d2fdd2a8c6f56825162eb71b9 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 14 Mar 2019 22:00:13 -0700 Subject: [PATCH 2/4] Fix for test failure with Click 7.0 --- tests/test_publish_heroku.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_publish_heroku.py b/tests/test_publish_heroku.py index 852403ca..da4e213a 100644 --- a/tests/test_publish_heroku.py +++ b/tests/test_publish_heroku.py @@ -24,7 +24,7 @@ def test_publish_heroku_installs_plugin(mock_call, mock_check_output, mock_which with runner.isolated_filesystem(): open("t.db", "w").write("data") result = runner.invoke(cli.cli, ["publish", "heroku", "t.db"], input="y\n") - assert -1 == result.exit_code + assert 0 != result.exit_code mock_check_output.assert_has_calls( [mock.call(["heroku", "plugins"]), mock.call(["heroku", "apps:list", "--json"])] ) From 9e8c36793bfbb17c2f67371cc7f9aa8b9202fdc4 Mon Sep 17 00:00:00 2001 From: joelondon Date: Fri, 15 Mar 2019 05:06:45 +0000 Subject: [PATCH 3/4] Update spatialite.rst (#413) a line of sql added to create the idx_ in the python recipe --- docs/spatialite.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/spatialite.rst b/docs/spatialite.rst index 5a8a31b1..58179e70 100644 --- a/docs/spatialite.rst +++ b/docs/spatialite.rst @@ -68,6 +68,8 @@ Here's a recipe for taking a table with existing latitude and longitude columns, UPDATE events SET point_geom = GeomFromText('POINT('||"longitude"||' '||"latitude"||')',4326); ''') + # Now add a spatial index to that column + conn.execute('select CreateSpatialIndex("museums", "point_geom");') # If you don't commit your changes will not be persisted: conn.commit() conn.close() From afe9aa3ae03c485c5d6652741438d09445a486c1 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 14 Mar 2019 22:22:24 -0700 Subject: [PATCH 4/4] show/hide link for SQL on custom query page Closes #415 --- datasette/templates/query.html | 12 +++++++----- datasette/views/base.py | 5 +++++ tests/test_html.py | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/datasette/templates/query.html b/datasette/templates/query.html index b23c67d8..06651689 100644 --- a/datasette/templates/query.html +++ b/datasette/templates/query.html @@ -26,11 +26,13 @@ {% 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 %} -

- {% else %} -
{% if query %}{{ query.sql }}{% endif %}
+

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 hide_sql %}(show){% else %}(hide){% endif %}

+ {% if not hide_sql %} + {% if editable and config.allow_sql %} +

+ {% else %} +
{% if query %}{{ query.sql }}{% endif %}
+ {% endif %} {% endif %} {% if named_parameter_values %}

Query parameters

diff --git a/datasette/views/base.py b/datasette/views/base.py index e98762b7..4db1b654 100644 --- a/datasette/views/base.py +++ b/datasette/views/base.py @@ -23,6 +23,7 @@ from datasette.utils import ( is_url, path_from_row_pks, path_with_added_args, + path_with_removed_args, path_with_format, remove_infinites, resolve_table_and_format, @@ -578,6 +579,10 @@ class BaseView(RenderMixin): "canned_query": canned_query, "metadata": metadata, "config": self.ds.config_dict(), + "request": request, + "path_with_added_args": path_with_added_args, + "path_with_removed_args": path_with_removed_args, + "hide_sql": "_hide_sql" in params, } return { diff --git a/tests/test_html.py b/tests/test_html.py index ca6d62aa..36335201 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -824,3 +824,22 @@ def test_urlify_custom_queries(app_client): https://twitter.com/simonw ''' == soup.find("td", {"class": "col-user_url"}).prettify().strip() + + +def test_show_hide_sql_query(app_client): + path = "/fixtures?" + urllib.parse.urlencode({ + "sql": "select ('https://twitter.com/' || 'simonw') as user_url;" + }) + response = app_client.get(path) + soup = Soup(response.body, "html.parser") + span = soup.select(".show-hide-sql")[0] + assert span.find("a")["href"].endswith("&_hide_sql=1") + assert "(hide)" == span.getText() + assert soup.find("textarea") is not None + # Now follow the link to hide it + response = app_client.get(span.find("a")["href"]) + soup = Soup(response.body, "html.parser") + span = soup.select(".show-hide-sql")[0] + assert not span.find("a")["href"].endswith("&_hide_sql=1") + assert "(show)" == span.getText() + assert soup.find("textarea") is None