tailbone.diffs

Tools for displaying data diffs

class tailbone.diffs.Diff(old_data, new_data, columns=None, fields=None, enums=None, render_field=None, render_value=None, nature='dirty', monospace=False, extra_row_attrs=None)[source]

Core diff class. In sore need of documentation.

You must provide the old and new data sets, and the set of relevant fields as well, if they cannot be easily introspected.

Parameters:
  • old_data – Dict of “old” data values.

  • new_data – Dict of “old” data values.

  • fields – Sequence of relevant field names. Note that both data dicts are expected to have keys which match these field names. If you do not specify the fields then they will (hopefully) be introspected from the old or new data sets; however this will not work if they are both empty.

  • monospace – If true, this flag will cause the value columns to be rendered in monospace font. This is assumed to be helpful when comparing “raw” data values which are shown as e.g. repr(val).

  • enums – Optional dict of enums for use when displaying field values. If specified, keys should be field names and values should be enum dicts.

get_row_attrs(field)[source]

Returns a rendered set of extra attributes for the <tr> element for the given field. May be an empty string, or a snippet of HTML attribute syntax, e.g.:

class="diff" foo="bar"

If you wish to supply additional attributes, please define extra_row_attrs, which can be either a static dict, or a callable returning a dict.

class tailbone.diffs.VersionDiff(version, *args, **kwargs)[source]

Special diff class, for use with version history views. Note that while based on Diff, this class uses a different signature for the constructor.

Parameters:
  • version – Reference to a Continuum version record (object).

  • *args – Typical usage will not require positional args beyond the version param, in which case old_data and new_data params will be auto-determined based on the version. But if you specify positional args then nothing automatic is done, they are passed as-is to the parent Diff constructor.

  • **kwargs – Remaining kwargs are passed as-is to the Diff constructor.

render_version_value(field, value, version)[source]

Render the cell value text for the given version/field info.

Note that this method is used to render both sides of the diff (before and after values).

Parameters:
  • field – Name of the field, as string.

  • value – Raw value for the field, as obtained from version.

  • version – Reference to the Continuum version object.

Returns:

Rendered text as string, or None.