Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/python # -*- coding: utf-8 -*-
"""A table intended to be outputted as wikitext."""
""" Initialise the Table by defining its columns.
Numeric columns are sorted differently and summed across all rows. Entries in numeric which do not appear in tile_columns are summed but not displayed.
@param title_columns: OrderedDict of {label: title} for each column. If title is set to None, the label is reused as a title. Can also be provided as a list [label_1, (label_2, title_2), label_3] where missing titles are interpreted as None. @param numeric: list of columns (labels) which should be treated as numeric. """ # convert more compact notations to OrderedDict [(k[0], k[1]) if isinstance(k, tuple) else (k, None) for k in title_columns])
""" Add row to the table and increment totals.
Only add to totals if the corresponding entry is a number. None or missing values are replaced by a standard string.
@param row_cols: dict of column labels and their values @param num_cols: dict of column labels and their values for numeric entries when the normal entry cannot be used for summation. @param empty: string to use when an entry is None. """
# handle missing and None values
""" Add a pre-formatted row to the table.
The provided text must include the initial "|-". The wikitext is not validated. No entry will be added to the sum.
@param wikitext: the wikitext for a single row. """
"""Get a header row using appropriate titles, as wikitext."""
""" Get a row summing all numeric columns, as wikitext.
Numeric columns where the total is None are skipped allowing for a way of having a column numerically sorted but excluded from the summation row. """
""" Get the summation of a given column.
@param column: the column to return. If non is specified all the sums are returned as a dict. """ else:
""" Output the table as wikitext.
@param add_summation: Whether to add a summation row at the end. @param inline: whether to output each row on one line as oposed to one line per cell. Note that this has no effect on the header and summation rows. """ else: '| {} '.format(row.get(col)) for col in list(self.columns.keys())]) else:
""" Check if the given value is a number.
@param value: The value to check @type value: str, or int @return bool """
# @todo: move common.table_header_row and common.table_bottom_row here |