changed template path
All checks were successful
Build and Deploy Backend / build_and_deploy (push) Successful in 19s
All checks were successful
Build and Deploy Backend / build_and_deploy (push) Successful in 19s
This commit is contained in:
parent
6bb84fe2a4
commit
4f1766f8ec
4 changed files with 13 additions and 2 deletions
2
backend/.gitignore
vendored
2
backend/.gitignore
vendored
|
|
@ -1,3 +1,3 @@
|
|||
.venv/lib/**
|
||||
.venv/lib64/*
|
||||
dev.db
|
||||
*.db
|
||||
BIN
backend/dev.db
BIN
backend/dev.db
Binary file not shown.
|
|
@ -1,3 +1,4 @@
|
|||
from pathlib import Path
|
||||
from backend.config import MAILTRAP_API_TOKEN
|
||||
from mailtrap import BatchEmailRequest
|
||||
from mailtrap import BatchSendEmailParams
|
||||
|
|
@ -6,6 +7,8 @@ from mailtrap import Mail
|
|||
import mailtrap as mt
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
APP_ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
class ArticleData():
|
||||
def __init__(self, title, subtitle, description, link):
|
||||
self.title=title
|
||||
|
|
@ -18,6 +21,7 @@ class ArticleData():
|
|||
description: str
|
||||
link: str
|
||||
|
||||
|
||||
class AdminApprovalData(ArticleData):
|
||||
def __init__(self,title, subtitle, description, link, secret):
|
||||
ArticleData.__init__(self, title, subtitle, description, link)
|
||||
|
|
@ -25,11 +29,14 @@ class AdminApprovalData(ArticleData):
|
|||
|
||||
secret: str
|
||||
|
||||
|
||||
def create_html_from_template(template_name: str, data):
|
||||
env = Environment(loader = FileSystemLoader('src/backend/internal/jinja_templates'))
|
||||
print(f"APP_ROOT: {APP_ROOT}")
|
||||
env = Environment(loader = FileSystemLoader(f'{APP_ROOT}/internal/jinja_templates'))
|
||||
template = env.get_template(f"{template_name}.jinja")
|
||||
return template.render(data=data)
|
||||
|
||||
|
||||
def send_newsletter_admin_approval(data: ArticleData ):
|
||||
html = create_html_from_template("approval", data)
|
||||
|
||||
|
|
@ -41,6 +48,7 @@ def send_newsletter_admin_approval(data: ArticleData ):
|
|||
)
|
||||
send_mail(mail)
|
||||
|
||||
|
||||
def send_mail(mail: Mail):
|
||||
if ENVIRONMENT == "local":
|
||||
print(f"Mail sent: {mail.subject}")
|
||||
|
|
@ -49,6 +57,7 @@ def send_mail(mail: Mail):
|
|||
client = mt.MailtrapClient(token=MAILTRAP_API_TOKEN)
|
||||
client.send(mail)
|
||||
|
||||
|
||||
def send_batch_mail(mails: list[BatchEmailRequest]):
|
||||
if ENVIRONMENT == "local":
|
||||
for mail in mails:
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ def register_user(new_user: NewUser, session: Session = Depends(get_session)):
|
|||
except IntegrityError as e:
|
||||
session.rollback()
|
||||
raise HTTPException(HTTP_400_BAD_REQUEST)
|
||||
except Exception:
|
||||
session.rollback()
|
||||
|
||||
|
||||
@router.post(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue