misc: inject TEMPLATE_VARS in mail template context (#43469)

This commit is contained in:
Benjamin Dauvergne 2020-06-26 13:01:51 +02:00
parent 0e355150cc
commit 2aa8d42243
5 changed files with 21 additions and 1 deletions

View File

@ -634,7 +634,9 @@ def send_templated_mail(user_or_email, template_names, context=None, with_html=T
if not request:
request = middleware.StoreRequestMiddleware().get_request()
ctx = context or {}
ctx = copy.copy(app_settings.TEMPLATE_VARS)
if context:
ctx.update(context)
subject_template_names = [template_name + '_subject.txt' for template_name in template_names]
subject_template_names += legacy_subject_templates or []

View File

@ -0,0 +1 @@
{{ template_vars_body_html }}

View File

@ -0,0 +1 @@
{{ template_vars_body_txt }}

View File

@ -0,0 +1 @@
{{ template_vars_subject_txt }}

View File

@ -161,6 +161,21 @@ def test_send_templated_mail_template_selection(simple_user):
assert sent_mail.body == specific_template_ou
def test_send_templated_mail_template_vars(settings, simple_user):
settings.TEMPLATE_VARS = {
'template_vars_subject_txt': 'here is the subject',
'template_vars_body_txt': 'here is the text body',
'template_vars_body_html': 'here is the html body',
}
send_templated_mail(simple_user, ['template_vars'])
assert len(mail.outbox) == 1
sent_mail = mail.outbox.pop()
assert sent_mail.subject == 'here is the subject'
assert sent_mail.body == 'here is the text body\n'
assert sent_mail.alternatives == [('here is the html body\n', 'text/html')]
def test_lazy_join():
a = 'a'