Revision 24182db6
[#1418] Filtrage sur la date.
Améliore le formulaire de filtrage concernant les dates :
- Un exemple de date au format attendu est donnée en exemple via un
placeholder pour les navigateurs supportant cette fonctionnalité.
- Il est également disponible au survol du champ par la souris.
- Le format a été rendu plus laxiste : une date sans heure peut être
saisie (ex : "25/12/2015" au lieu de "25/12/2015 00:00:00".
Change-Id: I192e5841c04b1b993d1d31dd197956783adfef91
Refs: #1418.
Reviewed-on: https://vigilo-dev.si.c-s.fr/review/1685
Tested-by: Build system <qa@vigilo-dev.si.c-s.fr>
Reviewed-by: Thomas BURGUIERE <thomas.burguiere@c-s.fr>
vigiboard/lib/dateformat.py | ||
---|---|---|
32 | 32 |
def get_date_format(): |
33 | 33 |
# @HACK: nécessaire car l_() retourne un object LazyString |
34 | 34 |
# qui n'est pas sérialisable en JSON. |
35 |
# TRANSLATORS: Format de date et heure Python/JavaScript. |
|
36 |
# TRANSLATORS: http://www.dynarch.com/static/jscalendar-1.0/doc/html/reference.html#node_sec_5.3.5 |
|
37 |
# TRANSLATORS: http://docs.python.org/release/2.5/lib/module-time.html |
|
35 | 38 |
return _('%Y-%m-%d %I:%M:%S %p').encode('utf-8') |
36 | 39 |
|
37 | 40 |
class DateFormatConverter(FancyValidator): |
... | ... | |
52 | 55 |
str_date = str_date.encode('utf-8') |
53 | 56 |
|
54 | 57 |
try: |
55 |
# TRANSLATORS: Format de date et heure Python/JavaScript. |
|
56 |
# TRANSLATORS: http://www.dynarch.com/static/jscalendar-1.0/doc/html/reference.html#node_sec_5.3.5 |
|
57 |
# TRANSLATORS: http://docs.python.org/release/2.5/lib/module-time.html |
|
58 |
date = datetime.strptime(str_date, _('%Y-%m-%d %I:%M:%S %p').encode('utf8')) |
|
58 |
# On tente d'interpréter la saisie de l'utilisateur |
|
59 |
# selon un format date + heure. |
|
60 |
date = datetime.strptime(str_date, get_date_format()) |
|
59 | 61 |
except ValueError: |
60 |
raise Invalid(self.message('invalid', state), value, state) |
|
62 |
try: |
|
63 |
# 2è essai : on essaye d'interpréter uniquement une date. |
|
64 |
# TRANSLATORS: Format de date Python/JavaScript. |
|
65 |
# TRANSLATORS: http://www.dynarch.com/static/jscalendar-1.0/doc/html/reference.html#node_sec_5.3.5 |
|
66 |
# TRANSLATORS: http://docs.python.org/release/2.5/lib/module-time.html |
|
67 |
date = datetime.strptime(str_date, _('%Y-%m-%d').encode('utf8')) |
|
68 |
except ValueError: |
|
69 |
raise Invalid(self.message('invalid', state), value, state) |
|
61 | 70 |
return date |
62 | 71 |
|
63 | 72 |
def _from_python(self, value, state): |
... | ... | |
65 | 74 |
raise Invalid(self.message('invalid', state), value, state) |
66 | 75 |
|
67 | 76 |
# Même format que pour _to_python. |
68 |
return datetime.strftime( |
|
69 |
value, |
|
70 |
_('%Y-%m-%d %I:%M:%S %p').encode('utf8') |
|
71 |
).decode('utf-8') |
|
77 |
return datetime.strftime(value, get_date_format()).decode('utf-8') |
Also available in: Unified diff