Skip to content

Commit

Permalink
_facet selections persist through table form, refs #255
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw authored and Simon Willison committed May 16, 2018
1 parent 514873c commit f4943ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions datasette/templates/table.html
Expand Up @@ -81,6 +81,9 @@ <h3>{% if filtered_table_rows_count or filtered_table_rows_count == 0 %}{{ "{:,}
</div>
<label class="sort_by_desc"><input type="checkbox" name="_sort_by_desc"{% if sort_desc %} checked{% endif %}> descending</label>
{% endif %}
{% for facet in facet_results %}
<input type="hidden" name="_facet" value="{{ facet }}">
{% endfor %}
<input type="submit" value="Apply">
</div>
</form>
Expand Down
16 changes: 16 additions & 0 deletions tests/test_html.py
Expand Up @@ -201,6 +201,22 @@ def test_sort_links(app_client):
] == attrs_and_link_attrs


def test_facets_persist_through_filter_form(app_client):
response = app_client.get(
'/test_tables/facetable?_facet=planet_id&_facet=city',
gather_request=False
)
assert response.status == 200
inputs = Soup(response.body, 'html.parser').find('form').findAll('input')
hiddens = [i for i in inputs if i['type'] == 'hidden']
assert [
('_facet', 'planet_id'),
('_facet', 'city'),
] == [
(hidden['name'], hidden['value']) for hidden in hiddens
]


@pytest.mark.parametrize('path,expected_classes', [
('/', ['index']),
('/test_tables', ['db', 'db-test_tables']),
Expand Down

0 comments on commit f4943ca

Please sign in to comment.