mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
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:
parent
a87df963a0
commit
b13f0986f2
7 changed files with 93 additions and 23 deletions
|
|
@ -412,12 +412,27 @@ def test_sortable_argument_errors(app_client):
|
|||
)
|
||||
assert 'Cannot sort table by badcolumn2' == response.json['error']
|
||||
response = app_client.get(
|
||||
'/test_tables/sortable.json?_sort=content&_sort_desc=pk2',
|
||||
'/test_tables/sortable.json?_sort=sortable_with_nulls&_sort_desc=sortable',
|
||||
gather_request=False
|
||||
)
|
||||
assert 'Cannot use _sort and _sort_desc at the same time' == response.json['error']
|
||||
|
||||
|
||||
def test_sortable_columns_metadata(app_client):
|
||||
response = app_client.get(
|
||||
'/test_tables/sortable.json?_sort=content',
|
||||
gather_request=False
|
||||
)
|
||||
assert 'Cannot sort table by content' == response.json['error']
|
||||
# no_primary_key has ALL sort options disabled
|
||||
for column in ('content', 'a', 'b', 'c'):
|
||||
response = app_client.get(
|
||||
'/test_tables/sortable.json?_sort={}'.format(column),
|
||||
gather_request=False
|
||||
)
|
||||
assert 'Cannot sort table by {}'.format(column) == response.json['error']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('path,expected_rows', [
|
||||
('/test_tables/simple_primary_key.json?content=hello', [
|
||||
['1', 'hello'],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue