88from django .conf import settings
99from django .core .exceptions import ImproperlyConfigured
1010from django .template .loader import render_to_string
11- from django .template import RequestContext
11+ from django .template import Context , RequestContext
1212from ietf .utils import log
1313import sys
1414import time
@@ -95,12 +95,18 @@ def copy_email(msg, to, toUser=False):
9595 new ['To' ] = to
9696 send_smtp (new )
9797
98+ def mail_context (request ):
99+ if request :
100+ return RequestContext (request )
101+ else :
102+ return Context ()
103+
98104def send_mail_subj (request , to , frm , stemplate , template , context , * args , ** kwargs ):
99105 '''
100106 Send an email message, exactly as send_mail(), but the
101107 subject field is a template.
102108 '''
103- subject = render_to_string (stemplate , context , context_instance = RequestContext (request )).replace ("\n " ," " ).strip ()
109+ subject = render_to_string (stemplate , context , context_instance = mail_context (request )).replace ("\n " ," " ).strip ()
104110 return send_mail (request , to , frm , subject , template , context , * args , ** kwargs )
105111
106112def send_mail (request , to , frm , subject , template , context , * args , ** kwargs ):
@@ -110,7 +116,7 @@ def send_mail(request, to, frm, subject, template, context, *args, **kwargs):
110116 The body is a text/plain rendering of the template with the context.
111117 extra is a dict of extra headers to add.
112118 '''
113- txt = render_to_string (template , context , context_instance = RequestContext (request ))
119+ txt = render_to_string (template , context , context_instance = mail_context (request ))
114120 return send_mail_text (request , to , frm , subject , txt , * args , ** kwargs )
115121
116122def send_mail_text (request , to , frm , subject , txt , cc = None , extra = None , toUser = None , bcc = None ):
0 commit comments