emails: Store the compiled emails in separate directory.

This commit is contained in:
Vishnu Ks
2017-09-26 05:11:15 +05:30
committed by Tim Abbott
parent caaa90f22d
commit dfaa939af2
14 changed files with 37 additions and 32 deletions

View File

@@ -2,6 +2,7 @@ from django.conf import settings
from django.core.mail import EmailMultiAlternatives
from django.template import loader
from django.utils.timezone import now as timezone_now
from django.template.exceptions import TemplateDoesNotExist
from zerver.models import UserProfile, ScheduledEmail, get_user_profile_by_id, \
EMAIL_TYPES
@@ -9,6 +10,7 @@ import datetime
from email.utils import parseaddr, formataddr
import ujson
import os
from typing import Any, Dict, Iterable, List, Mapping, Optional, Text
from zerver.lib.logging_util import create_logger
@@ -75,7 +77,14 @@ def build_email(template_prefix, to_user_id=None, to_email=None, from_name=None,
using='Jinja2_plaintext').strip().replace('\n', '')
message = loader.render_to_string(template_prefix + '.txt',
context=context, using='Jinja2_plaintext')
html_message = loader.render_to_string(template_prefix + '.html', context)
try:
html_message = loader.render_to_string(template_prefix + '.html', context)
except TemplateDoesNotExist:
emails_dir = os.path.dirname(template_prefix)
template = os.path.basename(template_prefix)
compiled_template_prefix = os.path.join(emails_dir, "compiled", template)
html_message = loader.render_to_string(compiled_template_prefix + '.html', context)
if from_name is None:
from_name = "Zulip"