kopia lustrzana https://github.com/simonw/datasette
rodzic
dfb87d012c
commit
a5792a8c61
|
@ -522,7 +522,7 @@ class RowTableShared(BaseView):
|
||||||
# or to the simple or compound primary key
|
# or to the simple or compound primary key
|
||||||
if link_column:
|
if link_column:
|
||||||
cells.append({
|
cells.append({
|
||||||
'column': 'Link',
|
'column': pks[0] if len(pks) == 1 else 'Link',
|
||||||
'value': jinja2.Markup(
|
'value': jinja2.Markup(
|
||||||
'<a href="/{database}/{table}/{flat_pks_quoted}">{flat_pks}</a>'.format(
|
'<a href="/{database}/{table}/{flat_pks_quoted}">{flat_pks}</a>'.format(
|
||||||
database=database,
|
database=database,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
{% for column in display_columns %}
|
{% for column in display_columns %}
|
||||||
<th scope="col">
|
<th class="col-{{ column.name|to_css_class }}" scope="col">
|
||||||
{% if not column.sortable %}
|
{% if not column.sortable %}
|
||||||
{{ column.name }}
|
{{ column.name }}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -66,7 +66,7 @@ The row template (``/dbname/tablename/rowid``) gets::
|
||||||
|
|
||||||
<body class="row db-dbname table-tablename">
|
<body class="row db-dbname table-tablename">
|
||||||
|
|
||||||
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
|
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
|
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
|
order to ensure that multiple tables which resolve to the same stripped
|
||||||
|
@ -82,6 +82,23 @@ Some examples::
|
||||||
"-" => "336d5e"
|
"-" => "336d5e"
|
||||||
"no $ characters" => "no--characters-59e024"
|
"no $ characters" => "no--characters-59e024"
|
||||||
|
|
||||||
|
``<td>`` and ``<th>`` elements also get custom CSS classes reflecting the
|
||||||
|
database column they are representing, for example::
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="col-id" scope="col">id</th>
|
||||||
|
<th class="col-name" scope="col">name</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="col-Link"><a href="...">1</a></td>
|
||||||
|
<td class="col-name">SMITH</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
Custom templates
|
Custom templates
|
||||||
----------------
|
----------------
|
||||||
|
|
|
@ -183,13 +183,13 @@ def test_table_html_simple_primary_key(app_client):
|
||||||
assert ['nofollow'] == a['rel']
|
assert ['nofollow'] == a['rel']
|
||||||
assert [
|
assert [
|
||||||
[
|
[
|
||||||
'<td class="col-Link"><a href="/test_tables/simple_primary_key/1">1</a></td>',
|
'<td class="col-id"><a href="/test_tables/simple_primary_key/1">1</a></td>',
|
||||||
'<td class="col-content">hello</td>'
|
'<td class="col-content">hello</td>'
|
||||||
], [
|
], [
|
||||||
'<td class="col-Link"><a href="/test_tables/simple_primary_key/2">2</a></td>',
|
'<td class="col-id"><a href="/test_tables/simple_primary_key/2">2</a></td>',
|
||||||
'<td class="col-content">world</td>'
|
'<td class="col-content">world</td>'
|
||||||
], [
|
], [
|
||||||
'<td class="col-Link"><a href="/test_tables/simple_primary_key/3">3</a></td>',
|
'<td class="col-id"><a href="/test_tables/simple_primary_key/3">3</a></td>',
|
||||||
'<td class="col-content"></td>'
|
'<td class="col-content"></td>'
|
||||||
]
|
]
|
||||||
] == [[str(td) for td in tr.select('td')] for tr in table.select('tbody tr')]
|
] == [[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:]):
|
for expected_col, th in zip(('pk1', 'pk2', 'content'), ths[1:]):
|
||||||
a = th.find('a')
|
a = th.find('a')
|
||||||
assert expected_col == a.string
|
assert expected_col == a.string
|
||||||
|
assert th['class'] == ['col-{}'.format(expected_col)]
|
||||||
assert a['href'].endswith('/compound_primary_key?_sort={}'.format(
|
assert a['href'].endswith('/compound_primary_key?_sort={}'.format(
|
||||||
expected_col
|
expected_col
|
||||||
))
|
))
|
||||||
|
@ -285,7 +286,7 @@ def test_table_html_foreign_key_links(app_client):
|
||||||
table = Soup(response.body, 'html.parser').find('table')
|
table = Soup(response.body, 'html.parser').find('table')
|
||||||
expected = [
|
expected = [
|
||||||
[
|
[
|
||||||
'<td class="col-Link"><a href="/test_tables/foreign_key_references/1">1</a></td>',
|
'<td class="col-pk"><a href="/test_tables/foreign_key_references/1">1</a></td>',
|
||||||
'<td class="col-foreign_key_with_label"><a href="/test_tables/simple_primary_key/1">hello</a>\xa0<em>1</em></td>',
|
'<td class="col-foreign_key_with_label"><a href="/test_tables/simple_primary_key/1">hello</a>\xa0<em>1</em></td>',
|
||||||
'<td class="col-foreign_key_with_no_label"><a href="/test_tables/primary_key_multiple_columns/1">1</a></td>'
|
'<td class="col-foreign_key_with_no_label"><a href="/test_tables/primary_key_multiple_columns/1">1</a></td>'
|
||||||
]
|
]
|
||||||
|
|
Ładowanie…
Reference in New Issue