mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
9e8c36793b
commit
afe9aa3ae0
3 changed files with 31 additions and 5 deletions
|
|
@ -26,11 +26,13 @@
|
||||||
{% block description_source_license %}{% include "_description_source_license.html" %}{% endblock %}
|
{% block description_source_license %}{% include "_description_source_license.html" %}{% endblock %}
|
||||||
|
|
||||||
<form class="sql" action="/{{ database }}-{{ database_hash }}{% if canned_query %}/{{ canned_query }}{% endif %}" method="get">
|
<form class="sql" action="/{{ database }}-{{ database_hash }}{% if canned_query %}/{{ canned_query }}{% endif %}" method="get">
|
||||||
<h3>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 %}</h3>
|
<h3>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 %} <span class="show-hide-sql">{% if hide_sql %}(<a href="{{ path_with_removed_args(request, {'_hide_sql': '1'}) }}">show</a>){% else %}(<a href="{{ path_with_added_args(request, {'_hide_sql': '1'}) }}">hide</a>){% endif %}</span></h3>
|
||||||
{% if editable and config.allow_sql %}
|
{% if not hide_sql %}
|
||||||
<p><textarea name="sql">{% if query and query.sql %}{{ query.sql }}{% else %}select * from {{ tables[0].name|escape_sqlite }}{% endif %}</textarea></p>
|
{% if editable and config.allow_sql %}
|
||||||
{% else %}
|
<p><textarea name="sql">{% if query and query.sql %}{{ query.sql }}{% else %}select * from {{ tables[0].name|escape_sqlite }}{% endif %}</textarea></p>
|
||||||
<pre>{% if query %}{{ query.sql }}{% endif %}</pre>
|
{% else %}
|
||||||
|
<pre>{% if query %}{{ query.sql }}{% endif %}</pre>
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if named_parameter_values %}
|
{% if named_parameter_values %}
|
||||||
<h3>Query parameters</h3>
|
<h3>Query parameters</h3>
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ from datasette.utils import (
|
||||||
is_url,
|
is_url,
|
||||||
path_from_row_pks,
|
path_from_row_pks,
|
||||||
path_with_added_args,
|
path_with_added_args,
|
||||||
|
path_with_removed_args,
|
||||||
path_with_format,
|
path_with_format,
|
||||||
remove_infinites,
|
remove_infinites,
|
||||||
resolve_table_and_format,
|
resolve_table_and_format,
|
||||||
|
|
@ -578,6 +579,10 @@ class BaseView(RenderMixin):
|
||||||
"canned_query": canned_query,
|
"canned_query": canned_query,
|
||||||
"metadata": metadata,
|
"metadata": metadata,
|
||||||
"config": self.ds.config_dict(),
|
"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 {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -824,3 +824,22 @@ def test_urlify_custom_queries(app_client):
|
||||||
https://twitter.com/simonw
|
https://twitter.com/simonw
|
||||||
</a>
|
</a>
|
||||||
</td>''' == soup.find("td", {"class": "col-user_url"}).prettify().strip()
|
</td>''' == 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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue