New hidden: True option for table metadat, closes #239

pull/246/head
Simon Willison 2018-04-25 20:42:57 -07:00
rodzic d3a0069c54
commit 02ee31c8b4
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 17E2DEA2588B7F52
4 zmienionych plików z 31 dodań i 10 usunięć

Wyświetl plik

@ -1219,6 +1219,7 @@ class Datasette:
break
m.update(data)
# List tables and their row counts
database_metadata = self.metadata.get('databases', {}).get(name, {})
tables = {}
views = []
with sqlite3.connect('file:{}?immutable=1'.format(path), uri=True) as conn:
@ -1253,13 +1254,14 @@ class Datasette:
).fetchall()]
if column_names and len(column_names) == 2 and 'id' in column_names:
label_column = [c for c in column_names if c != 'id'][0]
table_metadata = database_metadata.get('tables', {}).get(table, {})
tables[table] = {
'name': table,
'columns': column_names,
'primary_keys': primary_keys,
'count': count,
'label_column': label_column,
'hidden': False,
'hidden': table_metadata.get('hidden') or False,
}
foreign_keys = get_all_foreign_keys(conn)

Wyświetl plik

@ -142,6 +142,24 @@ used for the link label with the ``label_column`` property::
}
}
Hiding tables
-------------
You can hide tables from the database listing view (in the same way that FTS and
Spatialite tables are automatically hidden) using ``"hidden": true``::
{
"databases": {
"database1": {
"tables": {
"example_table": {
"hidden": true
}
}
}
}
}
Generating a metadata skeleton
------------------------------

Wyświetl plik

@ -90,6 +90,7 @@ METADATA = {
},
'no_primary_key': {
'sortable_columns': [],
'hidden': True,
},
'units': {
'units': {

Wyświetl plik

@ -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'] == 15
assert d['tables_count'] == 14
def test_database_page(app_client):
@ -113,14 +113,6 @@ def test_database_page(app_client):
},
'label_column': None,
'primary_keys': ['pk'],
}, {
'columns': ['content', 'a', 'b', 'c'],
'name': 'no_primary_key',
'count': 201,
'hidden': False,
'foreign_keys': {'incoming': [], 'outgoing': []},
'label_column': None,
'primary_keys': [],
}, {
'columns': ['id', 'content', 'content2'],
'name': 'primary_key_multiple_columns',
@ -213,6 +205,14 @@ def test_database_page(app_client):
'foreign_keys': {'incoming': [], 'outgoing': []},
'label_column': None,
'primary_keys': ['pk'],
}, {
'columns': ['content', 'a', 'b', 'c'],
'name': 'no_primary_key',
'count': 201,
'hidden': True,
'foreign_keys': {'incoming': [], 'outgoing': []},
'label_column': None,
'primary_keys': [],
}] == data['tables']