New sortable_columns option in metadata.json to control sort options

You can now explicitly set which columns in a table can be used for sorting
using the _sort and _sort_desc arguments using metadata.json:

    {
        "databases": {
            "database1": {
                "tables": {
                    "example_table": {
                        "sortable_columns": [
                            "height",
                            "weight"
                        ]
                    }
                }
            }
        }
    }

Refs #189
This commit is contained in:
Simon Willison 2018-04-08 21:58:25 -07:00
commit d1756d7736
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
7 changed files with 93 additions and 23 deletions

View file

@ -200,14 +200,10 @@ def test_row_html_simple_primary_key(app_client):
def test_table_html_no_primary_key(app_client):
response = app_client.get('/test_tables/no_primary_key', gather_request=False)
table = Soup(response.body, 'html.parser').find('table')
ths = table.findAll('th')
assert 'Link' == ths[0].string.strip()
for expected_col, th in zip(('rowid', 'content', 'a', 'b', 'c'), ths[1:]):
a = th.find('a')
assert expected_col == a.string
assert a['href'].endswith('/no_primary_key?_sort={}'.format(
expected_col
))
# We have disabled sorting for this table using metadata.json
assert [
'content', 'a', 'b', 'c'
] == [th.string.strip() for th in table.select('thead th')[2:]]
expected = [
[
'<td><a href="/test_tables/no_primary_key/{}">{}</a></td>'.format(i, i),