]> git.openstreetmap.org Git - osqa.git/blob - forum/templatetags/email_tags.py
35971124cab0c50e63171c528aeee1bed5dd3609
[osqa.git] / forum / templatetags / email_tags.py
1 from django import template
2
3 register = template.Library()
4
5 class MultiUserMailMessage(template.Node):
6     def __init__(self, nodelist):
7         self.nodelist = nodelist
8
9     def render(self, context):
10         recipients = context['recipients']
11         messages = list()
12
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']))
17
18         print messages
19
20 @register.tag
21 def email(parser, token):
22     nodelist = parser.parse(('endemail',))
23     parser.delete_first_token()
24     return MultiUserMailMessage(nodelist)
25
26
27
28 class EmailPartNode(template.Node):
29     def __init__(self, nodelist, varname):
30         self.nodelist = nodelist
31         self.varname = varname
32
33     def render(self, context):
34         context[self.varname] = self.nodelist.render(context).strip()
35
36 @register.tag
37 def subject(parser, token):
38     nodelist = parser.parse(('endsubject',))
39     parser.delete_first_token()
40     return EmailPartNode(nodelist, 'subject')
41
42 @register.tag
43 def htmlcontent(parser, token):
44     nodelist = parser.parse(('endhtmlcontent',))
45     parser.delete_first_token()
46     return EmailPartNode(nodelist, 'html_content')
47
48 @register.tag
49 def textcontent(parser, token):
50     nodelist = parser.parse(('endtextcontent',))
51     parser.delete_first_token()
52     return EmailPartNode(nodelist, 'text_content')
53
54