Facet toggling now works for integer columns, refs #255

This commit is contained in:
Simon Willison 2018-05-14 18:33:24 -03:00 committed by Simon Willison
commit f36c9d4b4c
3 changed files with 63 additions and 18 deletions

View file

@ -269,25 +269,27 @@ INSERT INTO [select] VALUES ('group', 'having', 'and');
CREATE TABLE facetable (
pk integer primary key,
planet_id integer,
state text,
city text,
neighborhood text
);
INSERT INTO facetable (state, city, neighborhood) VALUES
('CA', 'San Francisco', 'Mission'),
('CA', 'San Francisco', 'Dogpatch'),
('CA', 'San Francisco', 'SOMA'),
('CA', 'San Francisco', 'Tenderloin'),
('CA', 'San Francisco', 'Bernal Heights'),
('CA', 'San Francisco', 'Hayes Valley'),
('CA', 'Los Angeles', 'Hollywood'),
('CA', 'Los Angeles', 'Downtown'),
('CA', 'Los Angeles', 'Los Feliz'),
('CA', 'Los Angeles', 'Koreatown'),
('MI', 'Detroit', 'Downtown'),
('MI', 'Detroit', 'Greektown'),
('MI', 'Detroit', 'Corktown'),
('MI', 'Detroit', 'Mexicantown')
INSERT INTO facetable (planet_id, state, city, neighborhood) VALUES
(1, 'CA', 'San Francisco', 'Mission'),
(1, 'CA', 'San Francisco', 'Dogpatch'),
(1, 'CA', 'San Francisco', 'SOMA'),
(1, 'CA', 'San Francisco', 'Tenderloin'),
(1, 'CA', 'San Francisco', 'Bernal Heights'),
(1, 'CA', 'San Francisco', 'Hayes Valley'),
(1, 'CA', 'Los Angeles', 'Hollywood'),
(1, 'CA', 'Los Angeles', 'Downtown'),
(1, 'CA', 'Los Angeles', 'Los Feliz'),
(1, 'CA', 'Los Angeles', 'Koreatown'),
(1, 'MI', 'Detroit', 'Downtown'),
(1, 'MI', 'Detroit', 'Greektown'),
(1, 'MI', 'Detroit', 'Corktown'),
(1, 'MI', 'Detroit', 'Mexicantown'),
(2, 'MC', 'Memnonia', 'Arcadia Planitia')
;
INSERT INTO simple_primary_key VALUES (1, 'hello');

View file

@ -105,9 +105,9 @@ def test_database_page(app_client):
'fts_table': None,
'primary_keys': ['pk'],
}, {
'columns': ['pk', 'state', 'city', 'neighborhood'],
'columns': ['pk', 'planet_id', 'state', 'city', 'neighborhood'],
'name': 'facetable',
'count': 14,
'count': 15,
'foreign_keys': {'incoming': [], 'outgoing': []},
'fts_table': None,
'hidden': False,
@ -906,6 +906,12 @@ def test_page_size_matching_max_returned_rows(app_client_returend_rows_matches_p
"selected": False,
"toggle_url": "_facet=state&_facet=city&state=MI",
},
{
"value": "MC",
"count": 1,
"selected": False,
"toggle_url": "_facet=state&_facet=city&state=MC",
},
],
"city": [
{
@ -926,6 +932,12 @@ def test_page_size_matching_max_returned_rows(app_client_returend_rows_matches_p
"selected": False,
"toggle_url": "_facet=state&_facet=city&city=Los+Angeles",
},
{
"value": "Memnonia",
"count": 1,
"selected": False,
"toggle_url": "_facet=state&_facet=city&city=Memnonia",
},
],
},
), (
@ -948,6 +960,37 @@ def test_page_size_matching_max_returned_rows(app_client_returend_rows_matches_p
},
],
},
), (
"/test_tables/facetable.json?_facet=planet_id",
{
"planet_id": [
{
"value": 1,
"count": 14,
"selected": False,
"toggle_url": "_facet=planet_id&planet_id=1",
},
{
"value": 2,
"count": 1,
"selected": False,
"toggle_url": "_facet=planet_id&planet_id=2",
},
],
},
), (
# planet_id is an integer field:
"/test_tables/facetable.json?_facet=planet_id&planet_id=1",
{
"planet_id": [
{
"value": 1,
"count": 14,
"selected": True,
"toggle_url": "_facet=planet_id",
}
],
},
)
])
def test_facets(app_client, path, expected_facet_results):