transports: add the transport identifier to the template variable available for finding templates

This commit is contained in:
Benjamin Dauvergne 2013-06-18 16:23:04 +02:00
parent 1c76a88d6b
commit 4a312d1a28
1 changed files with 8 additions and 6 deletions

View File

@ -56,14 +56,14 @@ def get_transports():
return __TRANSPORTS
def get_template_list(template_list, category):
def get_template_list(template_list, **kwargs):
'''Customize a template list given an announce category'''
for template in template_list:
yield template.format(category=category.identifier)
yield template.format(**kwargs)
def get_template(template_list, category):
template_list = get_template_list(template_list, category)
def get_template(template_list, **kwargs):
template_list = get_template_list(template_list, **kwargs)
return select_template(template_list)
@ -105,8 +105,10 @@ class EmailTransport(object):
def send(self, announce):
category = announce.category
site = category.site
subject_template = get_template(self.subject_template_list, category)
body_template = get_template(self.body_template_list, category)
subject_template = get_template(self.subject_template_list,
category=category.identifier, identifier=self.identifier)
body_template = get_template(self.body_template_list,
category=category.identifier, identifier=self.identifier)
ctx = Context({ 'announce': announce, 'site': site, 'category': category })
subject = subject_template.render(ctx).replace('\r', '').replace('\n', '')
body = body_template.render(ctx)