🧑‍💻(views) render email's template

THis feature is inspired by Joanie. Add two new urls to render Emails
HTML and Text templates.

Developpers can render the email template they are working on. When necessary,
run make mails-build, and reload `_debug__/mail/hello_html`, it will re-render
the updated email template.

Also, I have copy/pasted one template extra tags from Joanie, which loads
bas64 string from static images. This code is necessary to render the dummy
template `hello.html`.
This commit is contained in:
Lebaud Antoine
2024-03-19 22:44:03 +01:00
committed by aleb_the_flash
parent 0141aa220f
commit 1919dce3a9
6 changed files with 116 additions and 5 deletions

21
src/backend/debug/urls.py Normal file
View File

@@ -0,0 +1,21 @@
"""Debug Urls to check the layout of emails"""
from django.urls import path
from .views import (
DebugViewHtml,
DebugViewTxt,
)
urlpatterns = [
path(
"__debug__/mail/hello_html",
DebugViewHtml.as_view(),
name="debug.mail.hello_html",
),
path(
"__debug__/mail/hello_txt",
DebugViewTxt.as_view(),
name="debug.mail.hello_txt",
),
]

View File

@@ -0,0 +1,29 @@
"""Debug Views to check the layout of emails"""
from django.views.generic.base import TemplateView
class DebugBaseView(TemplateView):
"""Debug View to check the layout of emails"""
def get_context_data(self, **kwargs):
"""Generates sample datas to have a valid debug email"""
context = super().get_context_data(**kwargs)
context["title"] = "Development email preview"
context["email"] = "random@gmail.com"
context["fullname"] = "robert"
return context
class DebugViewHtml(DebugBaseView):
"""Debug View for HTML Email Layout"""
template_name = "mail/html/hello.html"
class DebugViewTxt(DebugBaseView):
"""Debug View for Text Email Layout"""
template_name = "mail/text/hello.txt"