1 from django import template
3 register = template.Library()
5 class MultiUserMailMessage(template.Node):
6 def __init__(self, nodelist):
7 self.nodelist = nodelist
9 def render(self, context):
10 recipients = context['recipients']
13 for recipient in recipients:
14 context['recipient'] = recipient
15 self.nodelist.render(context)
16 messages.append((recipient, context['subject'], context['html_content'], context['text_content']))
21 def email(parser, token):
22 nodelist = parser.parse(('endemail',))
23 parser.delete_first_token()
24 return MultiUserMailMessage(nodelist)
28 class EmailPartNode(template.Node):
29 def __init__(self, nodelist, varname):
30 self.nodelist = nodelist
31 self.varname = varname
33 def render(self, context):
34 context[self.varname] = self.nodelist.render(context).strip()
37 def subject(parser, token):
38 nodelist = parser.parse(('endsubject',))
39 parser.delete_first_token()
40 return EmailPartNode(nodelist, 'subject')
43 def htmlcontent(parser, token):
44 nodelist = parser.parse(('endhtmlcontent',))
45 parser.delete_first_token()
46 return EmailPartNode(nodelist, 'html_content')
49 def textcontent(parser, token):
50 nodelist = parser.parse(('endtextcontent',))
51 parser.delete_first_token()
52 return EmailPartNode(nodelist, 'text_content')