mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-06-30 22:30:14 +02:00
* Issue #24: Add ability to localise queues so that the templates used
by those queues are in languages that differ from the installation langugage. To utilise this, call your templates 'zz:templatename' where 'zz' is the language code and 'templatename' is the name used by the Helpdesk when sending e-mails. Thanks to Paul Boehm for the submission.
This commit is contained in:
27
lib.py
27
lib.py
@ -49,20 +49,39 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b
|
||||
from django.template import loader, Context
|
||||
|
||||
from helpdesk.models import EmailTemplate
|
||||
import os
|
||||
|
||||
t = EmailTemplate.objects.get(template_name__iexact=template_name)
|
||||
context = Context(email_context)
|
||||
locale = getattr(context['queue'], 'locale', 'en')
|
||||
|
||||
if locale != 'en':
|
||||
template_localized = template_name + ':' + locale
|
||||
else:
|
||||
template_localized = None
|
||||
|
||||
got_template = True
|
||||
if template_localized:
|
||||
try:
|
||||
t = EmailTemplate.objects.get(templaet_name__iexact=template_localized)
|
||||
except EmailTemplate.DoesNotExist:
|
||||
got_template = False
|
||||
|
||||
if not got_template:
|
||||
t = EmailTemplate.objects.get(template_name__iexact=template_name)
|
||||
|
||||
if not sender:
|
||||
sender = settings.DEFAULT_FROM_EMAIL
|
||||
|
||||
context = Context(email_context)
|
||||
footer_file = os.path.join('helpdesk', locale, 'email_text_footer.txt')
|
||||
|
||||
text_part = loader.get_template_from_string(
|
||||
"%s{%% include 'helpdesk/email_text_footer.txt' %%}" % t.plain_text
|
||||
"%s{%% include '%s' %%}" % (t.plain_text, footer_file)
|
||||
).render(context)
|
||||
|
||||
email_html_base_file = os.path.join('helpdesk', locale, 'email_html_base.html')
|
||||
|
||||
html_part = loader.get_template_from_string(
|
||||
"{%% extends 'helpdesk/email_html_base.html' %%}{%% block title %%}%s{%% endblock %%}{%% block content %%}%s{%% endblock %%}" % (t.heading, t.html)
|
||||
"{%% extends '%s' %%}{%% block title %%}%s{%% endblock %%}{%% block content %%}%s{%% endblock %%}" % (email_html_base_file, t.heading, t.html)
|
||||
).render(context)
|
||||
|
||||
subject_part = loader.get_template_from_string(
|
||||
|
Reference in New Issue
Block a user