Document toolboxDocument toolbox

How to prepare report script

Create folder

Folder name will be used as report script name

Create config.json file

This file consists of the following parts:

  • name - name of the script, should be the same as folder name

  • description - default description for report

  • rootClass - name of the class of objects used as subtree roots

  • classes - list of the classes used in report script

  • relations - definitions of relations between classes

'classes' part structure

  • name - name of the class

  • fields - array of fields used in report

"classes":[ { "name":"report_class_name_1", "fields":[ "field1name", "Custom 1" ] }, { "name":"report_class_name_2", "fields":[] } ]

'relations' part structure

For each class (if required) we have to define list of its children classes.

"relations":{ "report_class_name_1":[ "report_class_name_2" ] }

Prepare python script (report_script.py)

  • in this file create class ReportGenerator(ReportGeneratorInterface) - please remember to add following import:

from reporting_service.ReportGeneratorInterface import ReportGeneratorInterface
  • ReportGeneratorInterface has following abstract methods which should be implemented (details for these methods below):

get_pdf_template

imports

example

get_float_format

get_pdf_css_file

get_excel_template

prepare_data_frames(self, data_frames)

Object data_frames contains data from FMA collected as a dictionary. There is one, required data frame "hierarchy" which contains pairs parentId - childId. Other data frames are available under the class names given in the config.json file.

get_excel_data_row_styles

In this method one can set styles for each data set.

Style sections:

  • columns - set style for selected columns (by name)

  • rows - set style of each row

  • evenRow - set style of each even row

  • lastRow - set style of selected columns in the last row in data set

Available style properties:

  • bgColor - cell background color 

  • bold - if True, font in cell will be bold

  • italic - if True, font in cell will be italic

Example:

get_excel_columns_width

In this method one can set width of selected columns. 

Create Excel template (xlsx file)

We can build an excel template by defining columns and their style, and using macros we can insert different values or the content of data sets in selected places.

Macro is specified by double curly braces. ( {{ macro_name }} )

Create PDF template

HTML template

CSS style file