downwards compatibility for django < 1.8

This commit is contained in:
Alex Seeholzer 2015-11-13 15:36:04 +01:00
parent cd0daccb56
commit 27c519f2ee
2 changed files with 16 additions and 9 deletions

View File

@ -86,9 +86,13 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b
footer_file = os.path.join('helpdesk', locale, 'email_text_footer.txt') footer_file = os.path.join('helpdesk', locale, 'email_text_footer.txt')
# get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html # get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html
from django.template import engines try:
from django.template import engines
template_func = engines['django'].from_string
except ImportError: # occurs in django < 1.8
template_func = loader.get_template_from_string
text_part = engines['django'].from_string( text_part = template_func(
"%s{%% include '%s' %%}" % (t.plain_text, footer_file) "%s{%% include '%s' %%}" % (t.plain_text, footer_file)
).render(context) ).render(context)
@ -103,15 +107,13 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b
html_txt = html_txt.replace('\r\n', '<br>') html_txt = html_txt.replace('\r\n', '<br>')
context['comment'] = mark_safe(html_txt) context['comment'] = mark_safe(html_txt)
from django.template import engines
# get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html # get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html
html_part = engines['django'].from_string( html_part = template_func(
"{%% extends '%s' %%}{%% block title %%}%s{%% endblock %%}{%% block content %%}%s{%% endblock %%}" % (email_html_base_file, t.heading, t.html) "{%% extends '%s' %%}{%% block title %%}%s{%% endblock %%}{%% block content %%}%s{%% endblock %%}" % (email_html_base_file, t.heading, t.html)
).render(context) ).render(context)
# get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html # get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html
subject_part = engines['django'].from_string( subject_part = template_func(
HELPDESK_EMAIL_SUBJECT_TEMPLATE % { HELPDESK_EMAIL_SUBJECT_TEMPLATE % {
"subject": t.subject, "subject": t.subject,
}).render(context) }).render(context)

View File

@ -370,8 +370,13 @@ def update_ticket(request, ticket_id, public=False):
# get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html # get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html
from django.template import engines try:
comment = engines['django'].from_string(comment).render(Context(context)) from django.template import engines
template_func = engines['django'].from_string
except ImportError: # occurs in django < 1.8
template_func = loader.get_template_from_string
comment = template_func(comment).render(Context(context))
if owner is -1 and ticket.assigned_to: if owner is -1 and ticket.assigned_to:
owner = ticket.assigned_to.id owner = ticket.assigned_to.id