mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
New truncate_cells_html config for truncating cells, closes #330
This commit is contained in:
parent
2db2ae4f21
commit
fc9b1cc136
5 changed files with 54 additions and 0 deletions
|
|
@ -101,6 +101,9 @@ CONFIG_OPTIONS = (
|
|||
ConfigOption("max_csv_mb", 100, """
|
||||
Maximum size allowed for CSV export in MB. Set 0 to disable this limit.
|
||||
""".strip()),
|
||||
ConfigOption("truncate_cells_html", 2048, """
|
||||
Truncate cells longer than this in HTML table view. Set to 0 to disable.
|
||||
""".strip()),
|
||||
)
|
||||
DEFAULT_CONFIG = {
|
||||
option.name: option.default
|
||||
|
|
|
|||
|
|
@ -117,6 +117,7 @@ class RowTableShared(BaseView):
|
|||
description,
|
||||
rows,
|
||||
link_column=False,
|
||||
truncate_cells=0,
|
||||
):
|
||||
"Returns columns, rows for specified table - including fancy foreign key treatment"
|
||||
table_metadata = self.table_metadata(database, table)
|
||||
|
|
@ -202,6 +203,8 @@ class RowTableShared(BaseView):
|
|||
)
|
||||
else:
|
||||
display_value = str(value)
|
||||
if truncate_cells and len(display_value) > truncate_cells:
|
||||
display_value = display_value[:truncate_cells] + u"\u2026"
|
||||
|
||||
cells.append({"column": column, "value": display_value})
|
||||
cell_rows.append(cells)
|
||||
|
|
@ -723,6 +726,7 @@ class TableView(RowTableShared):
|
|||
results.description,
|
||||
rows,
|
||||
link_column=not is_view,
|
||||
truncate_cells=self.ds.config["truncate_cells_html"],
|
||||
)
|
||||
metadata = self.ds.metadata.get("databases", {}).get(name, {}).get(
|
||||
"tables", {}
|
||||
|
|
@ -827,6 +831,7 @@ class RowView(RowTableShared):
|
|||
results.description,
|
||||
rows,
|
||||
link_column=False,
|
||||
truncate_cells=0,
|
||||
)
|
||||
for column in display_columns:
|
||||
column["sortable"] = False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue