|
if link_column: |
|
cells.append( |
|
{ |
|
"column": pks[0] if len(pks) == 1 else "Link", |
|
"value": jinja2.Markup( |
|
'<a href="/{database}/{table}/{flat_pks_quoted}">{flat_pks}</a>'.format( |
|
database=database, |
|
table=urllib.parse.quote_plus(table), |
|
flat_pks=str( |
|
jinja2.escape( |
|
path_from_row_pks(row, pks, not pks, False) |
|
) |
|
), |
|
flat_pks_quoted=path_from_row_pks(row, pks, not pks), |
|
) |
|
), |
|
} |
|
) |
|
|
|
for value, column_dict in zip(row, columns): |
|
column = column_dict["name"] |
|
if link_column and len(pks) == 1 and column == pks[0]: |
|
# If there's a simple primary key, don't repeat the value as it's |
|
# already shown in the link column. |
|
continue |
|
|
|
if isinstance(value, dict): |
|
# It's an expanded foreign key - display link to other row |
|
label = value["label"] |
|
value = value["value"] |
|
# The table we link to depends on the column |
|
other_table = column_to_foreign_key_table[column] |
|
link_template = ( |
|
LINK_WITH_LABEL if (label != value) else LINK_WITH_VALUE |
|
) |
|
display_value = jinja2.Markup(link_template.format( |
|
database=database, |
|
table=urllib.parse.quote_plus(other_table), |
|
link_id=urllib.parse.quote_plus(str(value)), |
|
id=str(jinja2.escape(value)), |
|
label=str(jinja2.escape(label)), |
|
)) |
|
elif value is None: |
|
display_value = jinja2.Markup(" ") |
|
elif is_url(str(value).strip()): |
|
display_value = jinja2.Markup( |
|
'<a href="{url}">{url}</a>'.format( |
|
url=jinja2.escape(value.strip()) |
|
) |
|
) |
|
elif column in table_metadata.get("units", {}) and value != "": |
|
# Interpret units using pint |
|
value = value * ureg(table_metadata["units"][column]) |
|
# Pint uses floating point which sometimes introduces errors in the compact |
|
# representation, which we have to round off to avoid ugliness. In the vast |
|
# majority of cases this rounding will be inconsequential. I hope. |
|
value = round(value.to_compact(), 6) |
|
display_value = jinja2.Markup( |
|
"{:~P}".format(value).replace(" ", " ") |
|
) |
|
else: |
|
display_value = str(value) |
|
|
|
cells.append({"column": column, "value": display_value}) |
|
cell_rows.append(cells) |
https://registry.datasette.io/registry-7d4f81f/datasette_tags
Underlying JSON looks like this:
Bug is likely somewhere in here:
datasette/datasette/views/table.py
Lines 143 to 207 in e04f5b0