Completed
Push — master ( 4714ad...4eeef3 )
by Vijay
01:01
created

to_str()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 3
rs 10
1
import os
2
from django.conf import settings
3
from django.core import mail
4
from django.template.loader import render_to_string
5
6
7
def to_str(x, context, template_dir=None):
8
    return render_to_string(
9
        os.path.join(template_dir, x), context).strip()
10
11
12
def send_mail(to, context, template_dir=None):
13
    """
14
    Utility to send mail.
15
    param to: recipient email list.
16
    param context: dict containing parameter, that will be passed
17
        to message templates.
18
    param template_dir: Path to directory, where required files for
19
        email exists. such as subject.txt, message.txt etc.
20
    """
21
22
#     to_str = lambda x: render_to_string(
23
#         os.path.join(template_dir, x), context).strip()
24
    subject = to_str(context, 'subject.txt')
25
    from_email = settings.DEFAULT_FROM_EMAIL
26
    text_message = to_str(context, 'message.txt')
27
    html_message = to_str(context, 'message.html')
28
    recipient_list = to
29
    return mail.send_mail(subject, text_message, from_email,
30
                          recipient_list, html_message=html_message)
31