mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Support title/description for canned queries, closes #342
Demo here: https://latest.datasette.io/fixtures/neighborhood_search
This commit is contained in:
parent
58fec99ab0
commit
6e37f091ed
9 changed files with 62 additions and 17 deletions
|
|
@ -161,13 +161,18 @@ METADATA = {
|
|||
},
|
||||
'queries': {
|
||||
'pragma_cache_size': 'PRAGMA cache_size;',
|
||||
'neighborhood_search': '''
|
||||
select neighborhood, facet_cities.name, state
|
||||
from facetable
|
||||
join facet_cities on facetable.city_id = facet_cities.id
|
||||
where neighborhood like '%' || :text || '%'
|
||||
order by neighborhood;
|
||||
'''
|
||||
'neighborhood_search': {
|
||||
'sql': '''
|
||||
select neighborhood, facet_cities.name, state
|
||||
from facetable
|
||||
join facet_cities
|
||||
on facetable.city_id = facet_cities.id
|
||||
where neighborhood like '%' || :text || '%'
|
||||
order by neighborhood;
|
||||
''',
|
||||
'title': 'Search neighborhoods',
|
||||
'description_html': '<b>Demonstrating</b> simple like search',
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -754,3 +754,20 @@ def test_404_trailing_slash_redirect(app_client, path, expected_redirect):
|
|||
response = app_client.get(path, allow_redirects=False)
|
||||
assert 302 == response.status
|
||||
assert expected_redirect == response.headers["Location"]
|
||||
|
||||
|
||||
def test_canned_query_with_custom_metadata(app_client):
|
||||
response = app_client.get("/fixtures/neighborhood_search?text=town")
|
||||
assert response.status == 200
|
||||
soup = Soup(response.body, "html.parser")
|
||||
assert "Search neighborhoods" == soup.find("h1").text
|
||||
assert (
|
||||
"""
|
||||
<div class="metadata-description">
|
||||
<b>
|
||||
Demonstrating
|
||||
</b>
|
||||
simple like search
|
||||
</div>""".strip()
|
||||
== soup.find("div", {"class": "metadata-description"}).prettify().strip()
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue