Jam.py documentation

on_convert_report

on_convert_report(report)

domain: client

language: python

class: Reports class

Description

The framework converts reports internally, using LibreOffice. Use the on_convert_report event if you want to use some other service or change some parameters of report conversion.

The report parameter is the report that triggered the event.

Example

import os
from subprocess import Popen, STDOUT, PIPE

def on_convert_report(report):
    try:
        if os.name == "nt":
            import _winreg
            regpath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\soffice.exe"
            root = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, regpath)
            s_office = _winreg.QueryValue(root, "")
        else:
            s_office = "soffice"
        convertion = Popen([s_office, '--headless', '--convert-to', report.ext,
            report.report_filename, '--outdir', os.path.join(report.task.work_dir, 'static', 'reports') ],
            stderr=STDOUT,stdout=PIPE)
        out, err = convertion.communicate()
        converted = True
    except Exception as e:
        print(e)