Don't show 'None' as label for nullable foreign key, closes #406

pull/590/head^2
Simon Willison 2019-11-02 15:29:40 -07:00
rodzic ed57e4f990
commit 14da70525b
4 zmienionych plików z 25 dodań i 5 usunięć

Wyświetl plik

@ -637,7 +637,7 @@ class TableView(RowTableShared):
new_row = CustomRow(columns)
for column in row.keys():
value = row[column]
if (column, value) in expanded_labels:
if (column, value) in expanded_labels and value is not None:
new_row[column] = {
"value": value,
"label": expanded_labels[(column, value)],

Wyświetl plik

@ -754,6 +754,7 @@ INSERT INTO primary_key_multiple_columns VALUES (1, 'hey', 'world');
INSERT INTO primary_key_multiple_columns_explicit_label VALUES (1, 'hey', 'world2');
INSERT INTO foreign_key_references VALUES (1, 1, 1);
INSERT INTO foreign_key_references VALUES (2, null, null);
INSERT INTO complex_foreign_keys VALUES (1, 1, 2, 1);
INSERT INTO custom_foreign_key_label VALUES (1, 1);

Wyświetl plik

@ -216,7 +216,7 @@ def test_database_page(app_client):
"name": "foreign_key_references",
"columns": ["pk", "foreign_key_with_label", "foreign_key_with_no_label"],
"primary_keys": ["pk"],
"count": 1,
"count": 2,
"hidden": False,
"fts_table": None,
"foreign_keys": {
@ -1519,7 +1519,7 @@ def test_expand_labels(app_client):
def test_expand_label(app_client):
response = app_client.get(
"/fixtures/foreign_key_references.json?_shape=object"
"&_label=foreign_key_with_label"
"&_label=foreign_key_with_label&_size=1"
)
assert {
"1": {
@ -1693,3 +1693,17 @@ def test_common_prefix_database_names(app_client_conflicting_database_names):
app_client_conflicting_database_names.get(path).body.decode("utf8")
)
assert db_name == data["database"]
def test_null_foreign_keys_are_not_expanded(app_client):
response = app_client.get(
"/fixtures/foreign_key_references.json?_shape=array&_labels=on"
)
assert [
{
"pk": "1",
"foreign_key_with_label": {"value": "1", "label": "hello"},
"foreign_key_with_no_label": {"value": "1", "label": "1"},
},
{"pk": "2", "foreign_key_with_label": None, "foreign_key_with_no_label": None,},
] == response.json

Wyświetl plik

@ -603,7 +603,12 @@ def test_table_html_foreign_key_links(app_client):
'<td class="col-pk"><a href="/fixtures/foreign_key_references/1">1</a></td>',
'<td class="col-foreign_key_with_label"><a href="/fixtures/simple_primary_key/1">hello</a>\xa0<em>1</em></td>',
'<td class="col-foreign_key_with_no_label"><a href="/fixtures/primary_key_multiple_columns/1">1</a></td>',
]
],
[
'<td class="col-pk"><a href="/fixtures/foreign_key_references/2">2</a></td>',
'<td class="col-foreign_key_with_label">\xa0</td>',
'<td class="col-foreign_key_with_no_label">\xa0</td>',
],
]
assert expected == [
[str(td) for td in tr.select("td")] for tr in table.select("tbody tr")
@ -611,7 +616,7 @@ def test_table_html_foreign_key_links(app_client):
def test_table_html_disable_foreign_key_links_with_labels(app_client):
response = app_client.get("/fixtures/foreign_key_references?_labels=off")
response = app_client.get("/fixtures/foreign_key_references?_labels=off&_size=1")
assert response.status == 200
table = Soup(response.body, "html.parser").find("table")
expected = [