File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
packages/notifications-library/src/notifications_library Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 1+ import functools
2+ import json
13import logging
24from pathlib import Path
5+ from typing import Any
36
47import notifications_library
8+ from common_library .json_serialization import pydantic_encoder
59from jinja2 import Environment , FileSystemLoader , PackageLoader , select_autoescape
10+ from models_library .utils ._original_fastapi_encoders import jsonable_encoder
611
712_logger = logging .getLogger (__name__ )
813
914
15+ def _safe_json_dumps (obj : Any , ** kwargs ):
16+ return json .dumps (jsonable_encoder (obj ), default = pydantic_encoder , ** kwargs )
17+
18+
1019def create_render_environment_from_notifications_library (** kwargs ) -> Environment :
11- return Environment (
20+ env = Environment (
1221 loader = PackageLoader (notifications_library .__name__ , "templates" ),
1322 autoescape = select_autoescape (["html" , "xml" ]),
1423 ** kwargs
1524 )
25+ env .globals ["dumps" ] = functools .partial (_safe_json_dumps , indent = 1 )
26+ return env
1627
1728
1829def create_render_environment_from_folder (top_dir : Path ) -> Environment :
1930 assert top_dir .exists () # nosec
2031 assert top_dir .is_dir () # nosec
21- return Environment (
32+ env = Environment (
2233 loader = FileSystemLoader (top_dir ),
2334 autoescape = select_autoescape (
2435 ["html" , "xml" ],
2536 ),
2637 )
38+ env .globals ["dumps" ] = functools .partial (_safe_json_dumps , indent = 1 )
39+ return env
You can’t perform that action at this time.
0 commit comments