on_convert_report¶
- on_convert_report(report)¶
domain: server
language: python
class: Reports class
Description¶
The framework converts reports internally, using LibreOffice. It is possible to use portable LibreOffice installlation.
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)
Portable LibreOffice on Windows¶
Add the event to report and modify the above with the LO installation path, ie.:
if os.name == "nt":
s_office = r"C:\Users\your_username\Downloads\LibreOfficePortable\App\libreoffice\program\soffice.exe"
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)