Display metadata footer on custom SQL queries (#589)

Closes #408 - thanks, @rixx!
pull/590/head
Tobias Kunze 2019-10-14 05:53:21 +02:00 zatwierdzone przez Simon Willison
rodzic 908fc3999e
commit 12cec411ca
2 zmienionych plików z 18 dodań i 4 usunięć

Wyświetl plik

@ -10,12 +10,17 @@ class DatabaseView(DataView):
name = "database"
async def data(self, request, database, hash, default_labels=False, _size=None):
metadata = (self.ds.metadata("databases") or {}).get(database, {})
self.ds.update_with_inherited_metadata(metadata)
if request.args.get("sql"):
if not self.ds.config("allow_sql"):
raise DatasetteError("sql= is not allowed", status=400)
sql = request.raw_args.pop("sql")
validate_sql_select(sql)
return await self.custom_sql(request, database, hash, sql, _size=_size)
return await self.custom_sql(
request, database, hash, sql, _size=_size, metadata=metadata
)
db = self.ds.databases[database]
@ -24,9 +29,6 @@ class DatabaseView(DataView):
hidden_table_names = set(await db.hidden_table_names())
all_foreign_keys = await db.get_all_foreign_keys()
metadata = (self.ds.metadata("databases") or {}).get(database, {})
self.ds.update_with_inherited_metadata(metadata)
tables = []
for table in table_counts:
table_columns = await db.table_columns(table)

Wyświetl plik

@ -737,6 +737,18 @@ def test_database_metadata(app_client):
assert_footer_links(soup)
def test_database_metadata_with_custom_sql(app_client):
response = app_client.get("/fixtures?sql=select+*+from+simple_primary_key")
assert response.status == 200
soup = Soup(response.body, "html.parser")
# Page title should be the default
assert "fixtures" == soup.find("h1").text
# Description should be custom
assert "Custom SQL query returning" in soup.find("h3").text
# The source/license should be inherited
assert_footer_links(soup)
def test_table_metadata(app_client):
response = app_client.get("/fixtures/simple_primary_key")
assert response.status == 200