diff --git a/mo/web/table.py b/mo/web/table.py index 4121226a843470cb037c850efe093c68accbe6b7..9d816ff26a626fa3325dc97f1a124a3f9c1ed500 100644 --- a/mo/web/table.py +++ b/mo/web/table.py @@ -55,15 +55,35 @@ class CellLink(Cell): return a + '>' + escape(self.text) + '</a>' +class CellCheckbox(Cell): + name: str + value: str + checked: bool + + def __init__(self, name: str, value: str, checked: bool = False): + Cell.__init__(self, "") + self.name = name + self.value = value + self.checked = checked + + def to_html(self) -> str: + ch = f'<input type="checkbox" name="{self.name}" value="{self.value}"' + if self.checked: + ch += ' checked' + return ch + '>' + + class Table: columns: Sequence[Column] rows: Iterable[dict] filename: str + show_downlink: bool - def __init__(self, columns: Sequence[Column], rows: Iterable[dict], filename: str): + def __init__(self, columns: Sequence[Column], rows: Iterable[dict], filename: str, show_downlink: bool = True): self.columns = columns self.rows = rows self.filename = filename + self.show_downlink = show_downlink def to_html(self) -> str: tab = ['<table class=data>', '<tr>'] @@ -82,7 +102,8 @@ class Table: tab.append(f'\t<td>{vals}') tab.append('</table>') - tab.append("<p>Stáhnout jako <a href='?format=csv'>CSV</a> nebo <a href='?format=tsv'>TSV</a>.") + if self.show_downlink: + tab.append("<p>Stáhnout jako <a href='?format=csv'>CSV</a> nebo <a href='?format=tsv'>TSV</a>.") return Markup("\n".join(tab)) def to_csv(self, dialect: str) -> str: