generated from john/python-template
@@ -22,6 +22,7 @@ class DocumentTableRow:
|
||||
name: str
|
||||
document_type: str
|
||||
authors: str
|
||||
tags: str
|
||||
document_date: str
|
||||
source_count: int
|
||||
|
||||
@@ -33,6 +34,7 @@ def _serialize_rows(rows: Sequence[DocumentTableRow]) -> list[dict[str, Any]]:
|
||||
"name": row.name,
|
||||
"document_type": row.document_type or "Unspecified",
|
||||
"authors": row.authors or "Not set",
|
||||
"tags": row.tags or "Not tagged",
|
||||
"document_date": row.document_date,
|
||||
"source_count": row.source_count,
|
||||
}
|
||||
@@ -59,15 +61,6 @@ def render_documents_table(rows: Sequence[DocumentTableRow]) -> None:
|
||||
"align": "left",
|
||||
"style": "width: 30%;",
|
||||
},
|
||||
{
|
||||
"name": "document_type",
|
||||
"label": "Type",
|
||||
"field": "document_type",
|
||||
"sortable": True,
|
||||
"classes": "ui-table-cell-wrap",
|
||||
"align": "center",
|
||||
"style": "width: 14%;",
|
||||
},
|
||||
{
|
||||
"name": "authors",
|
||||
"label": "Author",
|
||||
@@ -75,7 +68,16 @@ def render_documents_table(rows: Sequence[DocumentTableRow]) -> None:
|
||||
"sortable": True,
|
||||
"classes": "ui-table-cell-wrap",
|
||||
"align": "center",
|
||||
"style": "width: 22%;",
|
||||
"style": "width: 18%;",
|
||||
},
|
||||
{
|
||||
"name": "tags",
|
||||
"label": "Tags",
|
||||
"field": "tags",
|
||||
"sortable": True,
|
||||
"classes": "ui-table-cell-wrap",
|
||||
"align": "center",
|
||||
"style": "width: 16%;",
|
||||
},
|
||||
{
|
||||
"name": "document_date",
|
||||
@@ -86,6 +88,15 @@ def render_documents_table(rows: Sequence[DocumentTableRow]) -> None:
|
||||
"align": "center",
|
||||
"style": "width: 14%;",
|
||||
},
|
||||
{
|
||||
"name": "document_type",
|
||||
"label": "Type",
|
||||
"field": "document_type",
|
||||
"sortable": True,
|
||||
"classes": "ui-table-cell-wrap",
|
||||
"align": "center",
|
||||
"style": "width: 12%;",
|
||||
},
|
||||
{
|
||||
"name": "source_count",
|
||||
"label": "# Sources",
|
||||
@@ -93,7 +104,7 @@ def render_documents_table(rows: Sequence[DocumentTableRow]) -> None:
|
||||
"sortable": True,
|
||||
"classes": "font-mono",
|
||||
"align": "center",
|
||||
"style": "width: 20%;",
|
||||
"style": "width: 10%;",
|
||||
},
|
||||
],
|
||||
default_sort_by="name",
|
||||
|
||||
@@ -193,9 +193,10 @@ def register_page() -> None: # noqa: PLR0915
|
||||
DocumentTableRow(
|
||||
id=doc.id,
|
||||
name=doc.name,
|
||||
document_type=(doc.document_type_ref.label if doc.document_type_ref is not None else ""),
|
||||
authors=", ".join(_author_names(doc)),
|
||||
tags=", ".join(_tag_labels(doc)),
|
||||
document_date=compact_date(doc.document_date, doc.document_date_raw),
|
||||
document_type=(doc.document_type_ref.label if doc.document_type_ref is not None else ""),
|
||||
source_count=len(doc.sources),
|
||||
)
|
||||
for doc in documents
|
||||
@@ -628,6 +629,17 @@ def _author_names(document: Document) -> list[str]:
|
||||
)
|
||||
|
||||
|
||||
def _tag_labels(document: Document) -> list[str]:
|
||||
return sorted(
|
||||
(
|
||||
link.tag_ref.label
|
||||
for link in document.document_tags
|
||||
if link.tag_ref is not None and link.tag_ref.label.strip()
|
||||
),
|
||||
key=str.casefold,
|
||||
)
|
||||
|
||||
|
||||
def _resolve_selected_tag_labels(value: object) -> list[str]:
|
||||
def flatten(item: object) -> list[str]:
|
||||
if item is None:
|
||||
|
||||
Reference in New Issue
Block a user