Revision 00ece25a
Propagation recherche par date VigiBoard (#1193)
Corrige la transmission des critères de recherche par date dans
VigiBoard.
Change-Id: I0d27c20647665b356b457333edb858c9e65f27a2
Refs: #1193.
Reviewed-on: https://vigilo-dev.si.c-s.fr/review/1307
Tested-by: Build system <qa@vigilo-dev.si.c-s.fr>
Reviewed-by: Thomas BURGUIERE <thomas.burguiere@c-s.fr>
vigiboard/controllers/plugins/date.py | ||
---|---|---|
25 | 25 |
from datetime import datetime, timedelta |
26 | 26 |
import tw.forms as twf |
27 | 27 |
from pylons.i18n import ugettext as _, lazy_ugettext as l_ |
28 |
from tg.i18n import get_lang |
|
29 |
import tg |
|
30 |
from babel import Locale |
|
31 | 28 |
|
32 |
from vigilo.turbogears.helpers import get_locales |
|
33 | 29 |
from vigilo.models import tables |
34 | 30 |
|
35 | 31 |
from vigiboard.controllers.plugins import VigiboardRequestPlugin, ITEMS |
36 |
from vigiboard.lib.dateformat import DateFormatConverter |
|
37 |
|
|
38 |
def get_calendar_lang(): |
|
39 |
# TODO: Utiliser le champ "language" du modèle pour cet utilisateur ? |
|
40 |
# On récupère la langue du navigateur de l'utilisateur |
|
41 |
lang = get_lang() |
|
42 |
if not lang: |
|
43 |
lang = tg.config['lang'] |
|
44 |
else: |
|
45 |
lang = lang[0] |
|
46 |
|
|
47 |
# TODO: Il faudrait gérer les cas où tout nous intéresse dans "lang". |
|
48 |
# Si l'identifiant de langage est composé (ex: "fr_FR"), |
|
49 |
# on ne récupère que la 1ère partie. |
|
50 |
lang = lang.replace('_', '-') |
|
51 |
lang = lang.split('-')[0] |
|
52 |
return lang |
|
53 |
|
|
54 |
def get_date_format(): |
|
55 |
# @HACK: nécessaire car l_() retourne un object LazyString |
|
56 |
# qui n'est pas sérialisable en JSON. |
|
57 |
return _('%Y-%m-%d %I:%M:%S %p').encode('utf-8') |
|
32 |
from vigiboard.lib import dateformat |
|
58 | 33 |
|
59 | 34 |
class PluginDate(VigiboardRequestPlugin): |
60 | 35 |
"""Plugin pour l'ajout d'une colonne Date.""" |
... | ... | |
65 | 40 |
label_text=l_('From'), |
66 | 41 |
button_text=l_("Choose"), |
67 | 42 |
not_empty=False, |
68 |
validator=DateFormatConverter(if_missing=None), |
|
69 |
date_format=get_date_format, |
|
70 |
calendar_lang=get_calendar_lang, |
|
43 |
validator=dateformat.DateFormatConverter(if_missing=None),
|
|
44 |
date_format=dateformat.get_date_format,
|
|
45 |
calendar_lang=dateformat.get_calendar_lang,
|
|
71 | 46 |
), |
72 | 47 |
twf.CalendarDateTimePicker( |
73 | 48 |
'to_date', |
74 | 49 |
label_text=l_('To'), |
75 | 50 |
button_text=l_("Choose"), |
76 | 51 |
not_empty=False, |
77 |
validator=DateFormatConverter(if_missing=None), |
|
78 |
date_format=get_date_format, |
|
79 |
calendar_lang=get_calendar_lang, |
|
52 |
validator=dateformat.DateFormatConverter(if_missing=None),
|
|
53 |
date_format=dateformat.get_date_format,
|
|
54 |
calendar_lang=dateformat.get_calendar_lang,
|
|
80 | 55 |
), |
81 | 56 |
] |
82 | 57 |
|
vigiboard/controllers/root.py | ||
---|---|---|
60 | 60 |
from vigiboard.controllers.vigiboardrequest import VigiboardRequest |
61 | 61 |
from vigiboard.controllers.feeds import FeedsController |
62 | 62 |
|
63 |
from vigiboard.lib import export_csv |
|
63 |
from vigiboard.lib import export_csv, dateformat
|
|
64 | 64 |
from vigiboard.widgets.edit_event import edit_event_status_options, \ |
65 | 65 |
EditEventForm |
66 | 66 |
from vigiboard.widgets.search_form import create_search_form |
... | ... | |
214 | 214 |
if isinstance(dct[key], dict): |
215 | 215 |
for subkey in dct[key]: |
216 | 216 |
serialize_dict(dct[key], subkey) |
217 |
dct[key+'.'+subkey] = dct[key][subkey]
|
|
217 |
dct['%s.%s' % (key, subkey)] = dct[key][subkey]
|
|
218 | 218 |
del dct[key] |
219 |
elif isinstance(dct[key], datetime): |
|
220 |
dct[key] = dct[key].strftime(dateformat.get_date_format()) |
|
219 | 221 |
fixed_search = search.copy() |
220 | 222 |
for column in fixed_search.copy(): |
221 | 223 |
serialize_dict(fixed_search, column) |
vigiboard/lib/dateformat.py | ||
---|---|---|
10 | 10 |
|
11 | 11 |
from pylons.i18n import ugettext as _ |
12 | 12 |
|
13 |
def get_calendar_lang(): |
|
14 |
from tg.i18n import get_lang |
|
15 |
import tg |
|
16 |
|
|
17 |
# TODO: Utiliser le champ "language" du modèle pour cet utilisateur ? |
|
18 |
# On récupère la langue du navigateur de l'utilisateur |
|
19 |
lang = get_lang() |
|
20 |
if not lang: |
|
21 |
lang = tg.config['lang'] |
|
22 |
else: |
|
23 |
lang = lang[0] |
|
24 |
|
|
25 |
# TODO: Il faudrait gérer les cas où tout nous intéresse dans "lang". |
|
26 |
# Si l'identifiant de langage est composé (ex: "fr_FR"), |
|
27 |
# on ne récupère que la 1ère partie. |
|
28 |
lang = lang.replace('_', '-') |
|
29 |
lang = lang.split('-')[0] |
|
30 |
return lang |
|
31 |
|
|
32 |
def get_date_format(): |
|
33 |
# @HACK: nécessaire car l_() retourne un object LazyString |
|
34 |
# qui n'est pas sérialisable en JSON. |
|
35 |
return _('%Y-%m-%d %I:%M:%S %p').encode('utf-8') |
|
36 |
|
|
13 | 37 |
class DateFormatConverter(FancyValidator): |
14 | 38 |
""" |
15 | 39 |
Valide une date selon un format identique à ceux |
Also available in: Unified diff