From a5259baab0b4d6bffb4bfdb9982d9723259ba9b8 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Fri, 3 Nov 2023 16:58:43 +0000 Subject: [PATCH] start adding support for custom jinja filters --- api/tacticalrmm/ee/reporting/custom_filters.py | 5 +++++ api/tacticalrmm/ee/reporting/utils.py | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 api/tacticalrmm/ee/reporting/custom_filters.py diff --git a/api/tacticalrmm/ee/reporting/custom_filters.py b/api/tacticalrmm/ee/reporting/custom_filters.py new file mode 100644 index 0000000000..2e17c81f51 --- /dev/null +++ b/api/tacticalrmm/ee/reporting/custom_filters.py @@ -0,0 +1,5 @@ +from zoneinfo import ZoneInfo + + +def as_tz(date_obj, tz, format="%b %d, %I:%M %p"): + return date_obj.astimezone(ZoneInfo(tz)).strftime(format) diff --git a/api/tacticalrmm/ee/reporting/utils.py b/api/tacticalrmm/ee/reporting/utils.py index dd4a595758..db4efdf1b8 100644 --- a/api/tacticalrmm/ee/reporting/utils.py +++ b/api/tacticalrmm/ee/reporting/utils.py @@ -21,6 +21,7 @@ from tacticalrmm.utils import get_db_value from .constants import REPORTING_MODELS +from .custom_filters import as_tz from .markdown.config import Markdown from .models import ReportAsset, ReportDataQuery, ReportHTMLTemplate, ReportTemplate @@ -66,6 +67,7 @@ def db_template_loader(template_name: str) -> Optional[str]: env.globals["datetime"] = datetime env.globals["ZoneInfo"] = ZoneInfo env.globals["re"] = re +env.filters["as_tz"] = as_tz def generate_pdf(*, html: str, css: str = "") -> bytes: