diff --git a/api/patch_request.py b/api/patch_request.py index 7541882e0ef9516fe2fb7d9a383c1907172142ea..28240e4c49242630526abc27946c06436edaa236 100644 --- a/api/patch_request.py +++ b/api/patch_request.py @@ -4,7 +4,6 @@ import pathlib from email.mime.application import MIMEApplication from typing import Optional -import jinja2 from fastapi import APIRouter, Depends, HTTPException from starlette import status @@ -15,7 +14,7 @@ from model.settings import settings from model.wapi.cntl import APIToken, Mgr from model.wapi.nd import Port, Module, Room, Bldg, Site from util.auth import check_auth -from util.util import send_email, map_array_of_dicts +from util.util import send_email, map_array_of_dicts, render_jinja_template from util.wapi_util import execute_wapi_function router = APIRouter( @@ -365,13 +364,6 @@ def validate_patch_request_actions(conn, user, actions: list[APIPatchRequestActi return internal_actions -def render_jinja_template(path, template, **kwargs): - template_loader = jinja2.FileSystemLoader(path) - template_env = jinja2.Environment(loader=template_loader, autoescape=True) - templ = template_env.get_template(template) - return templ.render(**kwargs) - - def send_informal_petch_request(message: str, mgr: Mgr, receiver=settings.patch_request_email_receivers, reply_to: Optional[str] = None) -> bool: try: diff --git a/util/util.py b/util/util.py index f5075ac1d74cc025568ede835fe9c71620e4b2f7..3cef69771f7215bedc41fce6a6c84f529f97e546 100644 --- a/util/util.py +++ b/util/util.py @@ -3,6 +3,7 @@ from email.mime.application import MIMEApplication from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText +import jinja2 import psycopg.rows from model.settings import settings @@ -12,6 +13,13 @@ def get_cursor(conn): return conn.cursor(row_factory=psycopg.rows.dict_row) +def render_jinja_template(path, template, **kwargs): + template_loader = jinja2.FileSystemLoader(path) + template_env = jinja2.Environment(loader=template_loader, autoescape=True) + templ = template_env.get_template(template) + return templ.render(**kwargs) + + def send_email(to: str | list[str], sender: str, cc=None, bcc=None, reply_to=None, subject=None, body=None, body_type: str = 'html', attachments: list[MIMEApplication] = None): if type(to) is not list: