diff --git a/gestion/mail/mail.py b/gestion/mail/mail.py index 3e73a4af..0a50ceae 100644 --- a/gestion/mail/mail.py +++ b/gestion/mail/mail.py @@ -21,7 +21,7 @@ if '/usr/scripts' not in sys.path: from gestion import secrets_new as secrets default_language = 'fr' -template_path = os.path.join(os.path.dirname(__file__), 'template') + '/' +template_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'template') + '/' html_template = template_path + 'html' html_mutilang_template = template_path + 'html_multilang' text_mutilang_template = template_path + 'text_multilang' @@ -47,6 +47,7 @@ templateEnv.filters['name'] = given_name # file extension to rendering function map markup = { 'md' : markdown, + 'html' : lambda x:x, } ### For an example: @@ -80,6 +81,7 @@ def gen_local_body(fname, params, lang): return templateEnv.get_template(fname).render(params) def body(mail, lang1, lang2, mk, params, charset): + ret = [] file1 = template_path + mail + '/body/' + lang1 file2 = template_path + mail + '/body/' + lang2 if mk: @@ -87,17 +89,19 @@ def body(mail, lang1, lang2, mk, params, charset): file2 = file2 + '.' + mk if lang1 == lang2 or not os.path.isfile(file2): # No alt language txt = gen_local_body(file1, params, lang1) - ret = [ submessage(txt.encode(charset), 'plain', charset) ] + if mk != "html": + ret.append(submessage(txt.encode(charset), 'plain', charset)) if mk: # compute the html version html = templateEnv.get_template(html_template).render({'body': markup[mk](txt)}) ret.append(submessage(html.encode(charset), 'html', charset)) else: txt1 = gen_local_body(file1, params, lang1) txt2 = gen_local_body(file2, params, lang2) - params_txt=dict(params) - params_txt.update({'body1': txt1, 'body2':txt2}) - txt = templateEnv.get_template(text_mutilang_template).render(params_txt) - ret=[ submessage(txt.encode(charset), 'plain', charset) ] + if mk != "html": + params_txt=dict(params) + params_txt.update({'body1': txt1, 'body2':txt2}) + txt = templateEnv.get_template(text_mutilang_template).render(params_txt) + ret.append(submessage(txt.encode(charset), 'plain', charset)) if mk: # compute the html version params_html=dict(params) params_html.update({'lang1':lang1, 'lang2':lang2, 'body1': markup[mk](txt1), 'body2': markup[mk](txt2)}) diff --git a/gestion/mail/template/fin_connexion_stats/body/fr.md b/gestion/mail/template/fin_connexion_stats/body/fr.html similarity index 100% rename from gestion/mail/template/fin_connexion_stats/body/fr.md rename to gestion/mail/template/fin_connexion_stats/body/fr.html