Report Generator API

The main class responsible generating the report and managing the flow

ReportGenerator

class slick_reporting.generator.ReportGenerator(report_model=None, main_queryset=None, start_date=None, end_date=None, date_field=None, q_filters=None, kwargs_filters=None, group_by=None, columns=None, time_series_pattern=None, time_series_columns=None, time_series_custom_dates=None, crosstab_model=None, crosstab_columns=None, crosstab_ids=None, crosstab_compute_reminder=None, swap_sign=False, show_empty_records=None, print_flag=False, doc_type_plus_list=None, doc_type_minus_list=None, limit_records=False, format_row_func=None)[source]

The main class responsible generating the report and managing the flow

Below are the basic needed attrs

report_model = None

The main model where data is

date_field = None

Main date field to use whenever date filter is needed

columns = None

A list of column names. Columns names can be

  1. A Computation Field

  2. If group_by is set, then any field on teh group_by model

  3. If group_by is not set, then any field name on the report_model / queryset

  4. A callable on the generator

  5. Special __time_series__, and __crosstab__ Those can be use to control the position of the time series inside the columns, defaults it’s appended at the end

    Example: columns = [‘product_id’, ‘__time_series__’, ‘col_b’] Same is true with __crosstab__

group_by = None

The field to use for grouping, if not set then the report is expected to be a sub version of the report model

Below are the needed attrs and methods for time series manipulation

time_series_pattern = ''

If set the Report will compute a time series.

Possible options are: daily, weekly, semimonthly, monthly, quarterly, semiannually, annually and custom.

if custom is set, you’d need to override get_custom_time_series_dates

time_series_columns = None
a list of Calculation Field names which will be included in the series calculation.

Example: [‘__total__’, ‘__total_quantity__’] with compute those 2 fields for all the series

get_custom_time_series_dates()[source]

Hook to get custom , maybe separated date periods :return: [ (date1,date2) , (date3,date4), …. ]

get_time_series_field_verbose_name(computation_class, date_period, index, series, pattern=None)[source]

Sent the column data to construct a verbose name. Default implementation is delegated to the ReportField.get_time_series_field_verbose_name (which is name + the end date %Y%m%d)

Parameters
  • computation_class – the computation field_name

  • date_period – a tuple of (start_date, end_date)

Returns

a verbose string

Below are the needed attrs and methods for crosstab manipulation

crosstab_model = None

If set, a cross tab over this model selected ids (via crosstab_ids)

crosstab_columns = None

The computation fields which will be computed for each crosstab-ed ids

crosstab_ids = None

A list is the ids to create a crosstab report on

crosstab_compute_reminder = True

Include an an extra crosstab_columns for the outer group ( ie: all expects those crosstab_ids)

get_crosstab_field_verbose_name(computation_class, model, id)[source]

Hook to change the crosstab field verbose name, default it delegate this function to the ReportField :param computation_class: ReportField Class :param model: the model name as string :param id: the current crosstab id :return: a verbose string

Below are the magical attrs

limit_records = None

Serves are a main limit to the returned data of teh report_model. Can be beneficial if the results may be huge.

swap_sign = False
field_registry_class = <slick_reporting.registry.ReportFieldRegistry object>

You can have a custom computation field locator! It only needs a get_field_by_name(string) and returns a ReportField`