mirror of
https://github.com/simonw/datasette.git
synced 2026-09-02 14:44:07 +02:00
Merge 4f35b0c1d0 into bdc9731740
This commit is contained in:
commit
ca50004491
2 changed files with 32 additions and 1 deletions
|
|
@ -901,7 +901,7 @@ async def display_columns_and_rows(
|
|||
columns = [col for col in columns if col["name"] != pks[0]]
|
||||
first_column = {
|
||||
"name": pks[0],
|
||||
"sortable": len(pks) == 1,
|
||||
"sortable": pks[0] in sortable_columns,
|
||||
"is_pk": True,
|
||||
"type": column_details[pks[0]].type,
|
||||
"notnull": column_details[pks[0]].notnull,
|
||||
|
|
|
|||
|
|
@ -397,6 +397,37 @@ async def test_sort_links(ds_client):
|
|||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sort_menu_excludes_unsortable_primary_key():
|
||||
# https://github.com/simonw/datasette/issues/1980
|
||||
ds = Datasette(
|
||||
[],
|
||||
metadata={
|
||||
"databases": {
|
||||
"data": {"tables": {"timezones": {"sortable_columns": ["tzid"]}}}
|
||||
}
|
||||
},
|
||||
)
|
||||
try:
|
||||
db = ds.add_database(
|
||||
Database(ds, memory_name="test_sort_menu_unsortable_pk"), name="data"
|
||||
)
|
||||
await db.execute_write_script("""
|
||||
create table timezones (
|
||||
id integer primary key,
|
||||
tzid text
|
||||
);
|
||||
insert into timezones (id, tzid) values (133, 'Europe/London');
|
||||
""")
|
||||
response = await ds.client.get("/data/timezones")
|
||||
assert response.status_code == 200
|
||||
select = Soup(response.text, "html.parser").find("select", {"name": "_sort"})
|
||||
options = [option["value"] for option in select.find_all("option")]
|
||||
assert options == ["", "tzid"]
|
||||
finally:
|
||||
ds.close()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_facet_display(ds_client):
|
||||
response = await ds_client.get(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue