Skip to content
Snippets Groups Projects
Commit b28ac80b authored by Alexander Kaschta's avatar Alexander Kaschta :owl:
Browse files

UPD: Make template rendering global util

parent 70bb4fa4
No related branches found
No related tags found
No related merge requests found
Pipeline #419754 passed
......@@ -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:
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment