wuttjamaican.reports

Report Utilities

class wuttjamaican.reports.Report(config)[source]

Base class for all reports.

report_key

Each report must define a unique key, to identify it.

report_title

This is the common display title for the report.

add_params(schema)[source]

Add field nodes to the given schema, defining all report params.

Parameters:

schemaSchema instance.

The schema is from Colander so nodes must be compatible with that; for instance:

import colander

def add_params(self, schema):

    schema.add(colander.SchemaNode(
        colander.Date(),
        name='start_date'))

    schema.add(colander.SchemaNode(
        colander.Date(),
        name='end_date'))
get_output_columns()[source]

This should return a list of column definitions to be used when displaying or persisting the data output.

Each entry can be a simple column name, or else a dict with other options, e.g.:

def get_output_columns(self):
    return [
        'foo',
        {'name': 'bar',
         'label': "BAR"},
        {'name': 'sales',
         'label': "Total Sales",
         'numeric': True,
         'formatter': self.app.render_currency},
    ]
Returns:

List of column definitions as described above.

The last entry shown above has all options currently supported; here we explain those:

  • name - True name for the column.

  • label - Display label for the column. If not specified, one is derived from the name.

  • numeric - Boolean indicating the column data is numeric, so should be right-aligned.

  • formatter - Custom formatter / value rendering callable for the column. If set, this will be called with just one arg (the value) for each data row.

make_data(params, progress=None)[source]

This must “run” the report and return the final data.

Note that this should not (usually) write the data to file, its purpose is just to obtain the data.

The return value should usually be a dict, with no particular structure required beyond that. However it also can be a list of data rows.

There is no default logic here; subclass must define.

Parameters:
  • params – Dict of report params.

  • progress – Optional progress indicator factory.

Returns:

Data dict, or list of rows.

class wuttjamaican.reports.ReportHandler(config)[source]

Base class and default implementation for the report handler.

get_report(key, instance=True)[source]

Fetch the report class or instance for given key.

Parameters:
  • key – Identifying report key.

  • instance – Whether to return the class, or an instance. Default is True which means return the instance.

Returns:

Report class or instance, or None if the report could not be found.

get_report_modules()[source]

Returns a list of all known report modules.

This will discover all report modules exposed by the app, and/or its providers.

get_reports()[source]

Returns a dict of all known reports, keyed by report key.

This calls get_report_modules() and for each module, it discovers all the reports it contains.

make_report_data(report, params=None, progress=None, **kwargs)[source]

Run the given report and return the output data.

This calls Report.make_data() on the report, and tweaks the output as needed for consistency. The return value should resemble this structure:

{
    'output_title': "My Report",
    'data': ...,
}

However that is the minimum; the dict may have other keys as well.

Parameters:
  • reportReport instance to run.

  • params – Dict of report params.

  • progress – Optional progress indicator factory.

Returns:

Data dict with structure shown above.