mentat.reports.base module
This module contains base implementation of generic reporting class. It provides common methods and utilities usefull for all kinds of reporters like:
Jinja2 template rendering
report localization
- mentat.reports.base.BABEL_RFC3339_FORMAT = 'yyyy-MM-ddTHH:mm:ssZZZ'
RFC3339 compliant time format specifier for Babel format_datetime function.
Resources: http://babel.pocoo.org/en/latest/dates.html#date-fields
- class mentat.reports.base.BaseReporter(logger, reports_dir, templates_dir, locale='en', timezone='UTC', translations_dir=None)[source]
Bases:
object
Implementation of base reporting class providing following features and services:
self.renderer
- Jinja2 template renderingself.translator
- report localization
- format_custom_datetime(val, custom_format)[source]
Simple wrapper around :py:func:babel.dates.format_datetime` function that prints the datetime in custom format.
- format_datetime(val)[source]
Simple wrapper around :py:func:babel.dates.format_datetime` function that takes care of figuring out the appropriate locale.
- format_decimal(val)[source]
Simple wrapper around :py:func:babel.numbers.format_decimal` function that takes care of figuring out the appropriate locale.
- format_localdatetime(val)[source]
Simple wrapper around :py:func:babel.dates.format_datetime` function that takes care of figuring out the appropriate locale and prints the datetime in local timezone (local to the server).
- format_rfctzdatetime(val)[source]
Simple wrapper around :py:func:babel.dates.format_datetime` function that prints the datetime in configured timezone and enforced RFC 3339 format.
- format_timedelta(val)[source]
Simple wrapper around :py:func:babel.dates.format_timedelta` function that takes care of figuring out the appropriate locale.
- format_tzdatetime(val)[source]
Simple wrapper around :py:func:babel.dates.format_datetime` function that takes care of figuring out the appropriate locale and prints the datetime in configured timezone.
- format_url(base_url, query_params=None)[source]
Format given base URL and optional query parameters into valid URL.
- get_datetime(val)[source]
Method tries parse datetime if provided with string, otherwise return val directly.
- set_locale(locale)[source]
Change internal locale to different value.
- Parameters
locale (str) – New locale as string.
- set_timezone(timezone)[source]
Change internal timezone to different value.
- Parameters
timezone (str) – New timezone as string.
- property translator
Return translator for currently active locale.