Built-in Specialized Columns

class webgrid.LinkColumnBase(*args, **kwargs)[source]

Base class for columns rendering as links in HTML.

Expects a subclass to supply a create_url method for defining the link target.

Notable args:

link_label (str, optional): Caption to use instead of extracted data from the record.

Class attributes:

link_attrs (dict): Additional attributes to render on the A tag.

create_url(record)[source]

Generate a URL from the given record.

Expected to be overridden in subclass.

Basic render of an anchor tag.

render_html(record, hah)[source]

Renderer override for HTML to set up a link rather than using the raw data value.

class webgrid.BoolColumn(*args, **kwargs)[source]

Column rendering values as True/False (or the given labels).

Notable args:

reverse (bool, optional): Switch true/false cases.

true_label (str, optional): String to use for the true case.

false_label (str, optional): String to use for the false case.

format_data(data)[source]

Use to adjust the value extracted from the record for this column. By default, no change is made. Useful in sub-classes.

class webgrid.YesNoColumn(*args, **kwargs)[source]

BoolColumn rendering values as Yes/No.

Notable args:

reverse (bool, optional): Switch true/false cases.

class webgrid.DateColumnBase(*args, **kwargs)[source]

Base column for rendering date values in specified formats.

Designed to work with Python date/datetime/time and Arrow.

Notable args/attributes:

html_format (str, optional): Date format string for HTML.

csv_format (str, optional): Date format string for CSV.

xls_num_format (str, optional): Date format string for Excel.

xls_width_calc(value)[source]

Determine approximate width from value.

Value will be a date or datetime object, format as if it was going to be in HTML as an approximation of its format in Excel.

class webgrid.DateColumn(*args, **kwargs)[source]

Column for rendering date values in specified formats.

Designed to work with Python date and Arrow.

Notable args/attributes:

html_format (str, optional): Date format string for HTML.

csv_format (str, optional): Date format string for CSV.

xls_num_format (str, optional): Date format string for Excel.

class webgrid.DateTimeColumn(*args, **kwargs)[source]

Column for rendering datetime values in specified formats.

Designed to work with Python datetime and Arrow.

Notable args/attributes:

html_format (str, optional): Date format string for HTML.

csv_format (str, optional): Date format string for CSV.

xls_num_format (str, optional): Date format string for Excel.

class webgrid.TimeColumn(*args, **kwargs)[source]

Column for rendering time values in specified formats.

Designed to work with Python time and Arrow.

Notable args/attributes:

html_format (str, optional): Date format string for HTML.

csv_format (str, optional): Date format string for CSV.

xls_num_format (str, optional): Date format string for Excel.

class webgrid.NumericColumn(*args, **kwargs)[source]

Column for rendering formatted number values.

Notable args:

format_as (str, optional): Generic formats. Default “general”. - general: thousands separator and decimal point - accounting: currency symbol, etc. - percent: percentage symbol, etc.

places (int, optional): Decimal places to round to for general. Default 2.

curr (str, optional): Currency symbol for general. Default empty string.

sep (str, optional): Thousands separator. Default empty string.

dp (str, optional): Decimal separator. Default empty string.

pos (str, optional): Positive number indicator. Default empty string.

neg (str, optional): Negative number indicator for general. Default empty string.

trailneg (str, optional): Negative number suffix. Default empty string.

xls_neg_red (bool, optional): Renders negatives in red for Excel. Default True.

Class attributes:

xls_fmt_general, xls_fmt_accounting, xls_fmt_percent are Excel number formats used for the corresponding format_as setting.

get_num_format()[source]

Match format_as setting to one of the format strings in class attributes.

html_decimal_format_opts(data)[source]

Return tuple of options to expand for decimalfmt arguments.

places, curr, neg, and trailneg attributes are passed through unless format_as is “accounting”.

render_html(record, hah)[source]

HTML render override for numbers.

If format is percent, the value is multiplied by 100 to get the render value.

Negative values are given a “negative” CSS class in the render.

xls_construct_format(fmt_str)[source]

Apply places and xls_neg_red settings to the given number format string.

property xlsx_style

Number format for XLSX target.

class webgrid.EnumColumn(*args, **kwargs)[source]

This column type is meant to be used with python enum.Enum type columns. It expects that the display value is the value attribute of the enum instance.

format_data(value)[source]

Use to adjust the value extracted from the record for this column. By default, no change is made. Useful in sub-classes.