kopia lustrzana https://github.com/simonw/datasette
label_column now defined on the table-being-linked-to, fixes #234
rodzic
f27cabbaf3
commit
f3f4295712
|
@ -525,8 +525,8 @@ class RowTableShared(BaseView):
|
|||
foreign_keys = table_info['foreign_keys']['outgoing']
|
||||
for fk in foreign_keys:
|
||||
label_column = (
|
||||
# First look for metadata.json definition:
|
||||
table_metadata.get('label_column')
|
||||
# First look in metadata.json definition for this foreign key table:
|
||||
self.table_metadata(database, fk['other_table']).get('label_column')
|
||||
# Fall back to label_column from .inspect() detection:
|
||||
or tables.get(fk['other_table'], {}).get('label_column')
|
||||
)
|
||||
|
|
|
@ -97,7 +97,7 @@ METADATA = {
|
|||
'frequency': 'Hz'
|
||||
}
|
||||
},
|
||||
'custom_foreign_key_label': {
|
||||
'primary_key_multiple_columns_explicit_label': {
|
||||
'label_column': 'content2',
|
||||
},
|
||||
}
|
||||
|
@ -145,6 +145,12 @@ CREATE TABLE primary_key_multiple_columns (
|
|||
content2 text
|
||||
);
|
||||
|
||||
CREATE TABLE primary_key_multiple_columns_explicit_label (
|
||||
id varchar(30) primary key,
|
||||
content text,
|
||||
content2 text
|
||||
);
|
||||
|
||||
CREATE TABLE compound_primary_key (
|
||||
pk1 varchar(30),
|
||||
pk2 varchar(30),
|
||||
|
@ -221,7 +227,7 @@ CREATE TABLE "complex_foreign_keys" (
|
|||
CREATE TABLE "custom_foreign_key_label" (
|
||||
pk varchar(30) primary key,
|
||||
foreign_key_with_custom_label text,
|
||||
FOREIGN KEY ("foreign_key_with_custom_label") REFERENCES [primary_key_multiple_columns](id)
|
||||
FOREIGN KEY ("foreign_key_with_custom_label") REFERENCES [primary_key_multiple_columns_explicit_label](id)
|
||||
);
|
||||
|
||||
CREATE TABLE units (
|
||||
|
@ -246,6 +252,7 @@ INSERT INTO simple_primary_key VALUES (2, 'world');
|
|||
INSERT INTO simple_primary_key VALUES (3, '');
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ def test_homepage(app_client):
|
|||
assert response.json.keys() == {'test_tables': 0}.keys()
|
||||
d = response.json['test_tables']
|
||||
assert d['name'] == 'test_tables'
|
||||
assert d['tables_count'] == 14
|
||||
assert d['tables_count'] == 15
|
||||
|
||||
|
||||
def test_database_page(app_client):
|
||||
|
@ -89,12 +89,12 @@ def test_database_page(app_client):
|
|||
'outgoing': [{
|
||||
'column': 'foreign_key_with_custom_label',
|
||||
'other_column': 'id',
|
||||
'other_table': 'primary_key_multiple_columns'
|
||||
'other_table': 'primary_key_multiple_columns_explicit_label'
|
||||
}],
|
||||
},
|
||||
'label_column': None,
|
||||
'primary_keys': ['pk'],
|
||||
}, {
|
||||
}, {
|
||||
'columns': ['pk', 'foreign_key_with_label', 'foreign_key_with_no_label'],
|
||||
'name': 'foreign_key_references',
|
||||
'count': 1,
|
||||
|
@ -130,7 +130,18 @@ def test_database_page(app_client):
|
|||
'column': 'id',
|
||||
'other_column': 'foreign_key_with_no_label',
|
||||
'other_table': 'foreign_key_references'
|
||||
}, {
|
||||
}],
|
||||
'outgoing': []
|
||||
},
|
||||
'hidden': False,
|
||||
'label_column': None,
|
||||
'primary_keys': ['id']
|
||||
}, {
|
||||
'columns': ['id', 'content', 'content2'],
|
||||
'name': 'primary_key_multiple_columns_explicit_label',
|
||||
'count': 1,
|
||||
'foreign_keys': {
|
||||
'incoming': [{
|
||||
'column': 'id',
|
||||
'other_column': 'foreign_key_with_custom_label',
|
||||
'other_table': 'custom_foreign_key_label'
|
||||
|
|
|
@ -301,7 +301,7 @@ def test_table_html_foreign_key_custom_label_column(app_client):
|
|||
expected = [
|
||||
[
|
||||
'<td class="col-pk"><a href="/test_tables/custom_foreign_key_label/1">1</a></td>',
|
||||
'<td class="col-foreign_key_with_custom_label"><a href="/test_tables/primary_key_multiple_columns/1">world</a>\xa0<em>1</em></td>',
|
||||
'<td class="col-foreign_key_with_custom_label"><a href="/test_tables/primary_key_multiple_columns_explicit_label/1">world2</a>\xa0<em>1</em></td>',
|
||||
]
|
||||
]
|
||||
assert expected == [[str(td) for td in tr.select('td')] for tr in table.select('tbody tr')]
|
||||
|
|
Ładowanie…
Reference in New Issue