diff --git a/datasette/app.py b/datasette/app.py index 5e2d21d1..f079fbb6 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -522,7 +522,7 @@ class RowTableShared(BaseView): # or to the simple or compound primary key if link_column: cells.append({ - 'column': 'Link', + 'column': pks[0] if len(pks) == 1 else 'Link', 'value': jinja2.Markup( '{flat_pks}'.format( database=database, diff --git a/datasette/templates/_rows_and_columns.html b/datasette/templates/_rows_and_columns.html index 0844b5bb..cbfff5af 100644 --- a/datasette/templates/_rows_and_columns.html +++ b/datasette/templates/_rows_and_columns.html @@ -2,7 +2,7 @@ {% for column in display_columns %} - + {% if not column.sortable %} {{ column.name }} {% else %} diff --git a/docs/custom_templates.rst b/docs/custom_templates.rst index 0eae5966..64a74ee8 100644 --- a/docs/custom_templates.rst +++ b/docs/custom_templates.rst @@ -66,7 +66,7 @@ The row template (``/dbname/tablename/rowid``) gets:: -The ``db-x`` and ``table-x`` classes use the database or table names themselves IF +The ``db-x`` and ``table-x`` classes use the database or table names themselves if they are valid CSS identifiers. If they aren't, we strip any invalid characters out and append a 6 character md5 digest of the original name, in order to ensure that multiple tables which resolve to the same stripped @@ -82,6 +82,23 @@ Some examples:: "-" => "336d5e" "no $ characters" => "no--characters-59e024" +```` and ```` elements also get custom CSS classes reflecting the +database column they are representing, for example:: + + + + + + + + + + + + + + +
idname
SMITH
Custom templates ---------------- diff --git a/tests/test_html.py b/tests/test_html.py index 333e4e41..56e93e30 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -183,13 +183,13 @@ def test_table_html_simple_primary_key(app_client): assert ['nofollow'] == a['rel'] assert [ [ - '1', + '1', 'hello' ], [ - '2', + '2', 'world' ], [ - '3', + '3', '' ] ] == [[str(td) for td in tr.select('td')] for tr in table.select('tbody tr')] @@ -265,6 +265,7 @@ def test_table_html_compound_primary_key(app_client): for expected_col, th in zip(('pk1', 'pk2', 'content'), ths[1:]): a = th.find('a') assert expected_col == a.string + assert th['class'] == ['col-{}'.format(expected_col)] assert a['href'].endswith('/compound_primary_key?_sort={}'.format( expected_col )) @@ -285,7 +286,7 @@ def test_table_html_foreign_key_links(app_client): table = Soup(response.body, 'html.parser').find('table') expected = [ [ - '1', + '1', 'hello\xa01', '1' ]