fin_connexion: date en FR
This commit is contained in:
parent
041f14a06f
commit
b7818f0e4f
2 changed files with 26 additions and 1 deletions
|
@ -15,6 +15,7 @@ from lc_ldap.variables import base_dn
|
|||
import ldap
|
||||
from affich_tools import coul
|
||||
import gestion.mail as mail_module
|
||||
from locale_util import setlocale
|
||||
|
||||
#: Une journée (c'est plus pratique)
|
||||
DAY = datetime.timedelta(days=1)
|
||||
|
@ -70,6 +71,9 @@ def warn(adh, delai):
|
|||
data = {'delai': delai}
|
||||
for l in ['adhesion', 'connexion']:
|
||||
fin = max(parse_gtf(v.value) for v in adh['fin' + l.capitalize()])
|
||||
# TODO mettre cette partie dans la génération multilangue de
|
||||
# mail_module et faire un filtre jinja idoine
|
||||
with setlocale('fr_FR.UTF-8'):
|
||||
fin = fin.date().strftime('%d %B %Y')
|
||||
data['fin_%s' % l] = fin
|
||||
|
||||
|
|
21
gestion/mail/locale_util.py
Normal file
21
gestion/mail/locale_util.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Source:
|
||||
# http://stackoverflow.com/questions/18593661/how-do-i-strftime-a-date-object-in-a-different-locale
|
||||
import locale
|
||||
import threading
|
||||
|
||||
from datetime import datetime
|
||||
from contextlib import contextmanager
|
||||
|
||||
|
||||
LOCALE_LOCK = threading.Lock()
|
||||
|
||||
@contextmanager
|
||||
def setlocale(name):
|
||||
with LOCALE_LOCK:
|
||||
saved = locale.setlocale(locale.LC_ALL)
|
||||
try:
|
||||
yield locale.setlocale(locale.LC_ALL, name)
|
||||
finally:
|
||||
locale.setlocale(locale.LC_ALL, saved)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue