From b28ac80bd540f55cd74367184a43efbace2a944f Mon Sep 17 00:00:00 2001
From: Alexander Kaschta <alexander.kaschta9@kit.edu>
Date: Fri, 14 Mar 2025 23:28:41 +0100
Subject: [PATCH] UPD: Make template rendering global util

---
 api/patch_request.py | 10 +---------
 util/util.py         |  8 ++++++++
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/api/patch_request.py b/api/patch_request.py
index 7541882..28240e4 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 f5075ac..3cef697 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:
-- 
GitLab