safe.common.tables module

tables.py - v0.04 2009-07-28 Philippe Lagadec

This module provides a few classes to easily generate HTML code such as tables and lists.

Project website: http://www.decalage.info/python/html

License: CeCILL (open-source GPL compatible), see source code for details.
http://www.cecill.info
class safe.common.tables.List(lines=None, ordered=False, start=None, attribs=None)[source]

Bases: object

a List object is used to create an ordered or unordered list in HTML. (UL/OL tag)

Attributes: - lines: list, tuple or any iterable, containing one string for each line - ordered: bool, choice between an ordered (OL) or unordered list (UL) - attribs: dict, additional attributes for the OL/UL tag

Reference: http://www.w3.org/tr/html4/struct/lists.html

class safe.common.tables.Table(rows=None, border=None, style=None, width=None, cellspacing=None, cellpadding=None, attribs=None, header_row=None, table_class=None, col_width=None, col_align=None, col_valign=None, col_char=None, col_charoff=None, col_styles=None, caption=None, caption_at_bottom=False)[source]

Bases: object

A Table object is used to create a HTML table. (table tag)

Attributes:

  • rows: list, tuple or any iterable, containing one iterable or TableRow object for each row
  • header_row: list, tuple or any iterable, containing the header row (optional)
  • class: str, CSS class to use. Defaults to DEFAULT_TABLE_CLASS
  • caption: str, caption for the table
  • border: str or int, border width
  • style: str, table style in CSS syntax (thin black borders by default)
  • width: str, width of the table on the page
  • attribs: dict, additional attributes for the table tag
  • col_width: list or tuple defining width for each column
  • col_align: list or tuple defining horizontal alignment for each column
  • col_char: list or tuple defining alignment character for each column
  • col_charoff: list or tuple defining charoff attribute for each column
  • col_valign: list or tuple defining vertical alignment for each column
  • col_styles: list or tuple of HTML styles for each column

Reference: http://www.w3.org/tr/html4/struct/tables.html#h-11.2.1

column(col, header=False)[source]

Return a list contains all element in col-th column

Args:
  • col = number columnn
  • header = if False, doesn’t include the header
Returns:
  • list of string represent each element
Note:
If there is not column number col in a row, it will be represent as empty string ‘’
mozilla_row_fix(row)[source]

Mozilla bug fix workaround.

Parameters:row (row) – Row to be fixed.
toNewlineFreeString()[source]

Return a string representation of the table which contains no newlines.

Note

any preformatted <pre> blocks will be adversely affected by this.

class safe.common.tables.TableCell(text='', bgcolor=None, header=False, width=None, align=None, char=None, charoff=None, valign=None, style='', attribs=None, cell_class=None, row_span=None, col_span=None)[source]

Bases: object

A TableCell object is used to create a cell in a HTML table. (td or th)

Attributes:

  • text: text in the cell (may contain HTML tags). May be any object which can be converted to a string using str().
  • header: bool, false for a normal data cell (td), true for a header cell (th)
  • bgcolor: str, background color
  • width: str, width
  • align: str, horizontal alignment (left, center, right, justify or char)
  • char: str, alignment character, decimal point if not specified
  • charoff: str, see HTML specs
  • valign: str, vertical alignment (top|middle|bottom|baseline)
  • style: str, CSS style
  • attribs: dict, additional attributes for the td/th tag

Reference: http://www.w3.org/tr/html4/struct/tables.html#h-11.2.6

class safe.common.tables.TableRow(cells=None, bgcolor=None, header=False, attribs=None, col_align=None, col_valign=None, col_char=None, col_charoff=None, col_styles=None)[source]

Bases: object

A TableRow object is used to create a row in a HTML table. (tr tag)

Attributes:

  • cells: list, tuple or any iterable, containing one string or TableCell object for each cell
  • header: bool, true for a header row (th), false for a normal data row (td)
  • bgcolor: str, background color
  • col_align, col_valign, col_char, col_charoff, col_styles: see Table class
  • attribs: dict, additional attributes for the tr tag

Reference: http://www.w3.org/tr/html4/struct/tables.html#h-11.2.5

apply_properties(cell, col)[source]

Apply properties to the row

column_count()[source]

Return the number of columns in this row

safe.common.tables.htmllist(*args, **kwargs)[source]

return HTML code for a list as a string. See List class for parameters.

safe.common.tables.table(*args, **kwargs)[source]

return HTML code for a table as a string. See Table class for parameters.