diff --git a/tryton/gui/window/view_form/view/form_gtk/calendar.py b/tryton/gui/window/view_form/view/form_gtk/calendar.py index 24e057dcd2..47e0e8c261 100644 --- a/tryton/gui/window/view_form/view/form_gtk/calendar.py +++ b/tryton/gui/window/view_form/view/form_gtk/calendar.py @@ -7,15 +7,10 @@ import locale from interface import WidgetInterface import tryton.rpc as rpc from tryton.common import DT_FORMAT, DHM_FORMAT, HM_FORMAT, message, TRYTON_ICON +from _strptime import LocaleTime _ = gettext.gettext -if not hasattr(locale, 'nl_langinfo'): - locale.nl_langinfo = lambda *a: '%x' - -if not hasattr(locale, 'D_FMT'): - locale.D_FMT = None - class Calendar(WidgetInterface): "Calendar" @@ -71,8 +66,8 @@ class Calendar(WidgetInterface): if value == '': return False try: - date = time.strptime(value, locale.nl_langinfo( - locale.D_FMT).replace('%y', '%Y')) + date = time.strptime(value, + LocaleTime().LC_date.replace('%y', '%Y')) except: return False return time.strftime(DT_FORMAT, date) @@ -93,8 +88,8 @@ class Calendar(WidgetInterface): if len(value)>10: value = value[:10] date = time.strptime(value, DT_FORMAT) - value = time.strftime(locale.nl_langinfo( - locale.D_FMT).replace('%y', '%Y'), date) + value = time.strftime(LocaleTime().LC_date.replace('%y', '%Y'), + date) if len(value) > self.entry.get_width_chars(): self.entry.set_width_chars(len(value)) self.entry.set_text(value) @@ -134,7 +129,7 @@ class Calendar(WidgetInterface): year, month, day = cal.get_date() date = DT.date(year, month+1, day) self.entry.set_text(date.strftime( - locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'))) + LocaleTime().LC_date.replace('%y', '%Y'))) self._focus_out() self._window.present() win.destroy() @@ -192,8 +187,8 @@ class DateTime(WidgetInterface): if value == '': return False try: - date = time.strptime(value, locale.nl_langinfo( - locale.D_FMT).replace('%y', '%Y') + ' ' + HM_FORMAT) + date = time.strptime(value, + LocaleTime().LC_date.replace('%y', '%Y') + ' ' + HM_FORMAT) except: return False if 'timezone' in rpc.CONTEXT and timezone: @@ -237,8 +232,9 @@ class DateTime(WidgetInterface): date = ldt.timetuple() except: pass - value = time.strftime(locale.nl_langinfo( - locale.D_FMT).replace('%y', '%Y') + ' ' + HM_FORMAT, date) + value = time.strftime( + LocaleTime().LC_date.replace('%y', '%Y') + ' ' + HM_FORMAT, + date) if len(value) > self.entry.get_width_chars(): self.entry.set_width_chars(len(value)) self.entry.set_text(value) diff --git a/tryton/gui/window/view_form/view/graph_gtk/graph.py b/tryton/gui/window/view_form/view/graph_gtk/graph.py index 3ffbb0afaf..51de479adf 100644 --- a/tryton/gui/window/view_form/view/graph_gtk/graph.py +++ b/tryton/gui/window/view_form/view/graph_gtk/graph.py @@ -9,6 +9,7 @@ import time import tryton.rpc as rpc import cairo from tryton.action import Action +from _strptime import LocaleTime class Popup(object): @@ -360,8 +361,8 @@ class Graph(gtk.DrawingArea): end_date = mx.DateTime.mktime(time.strptime(str(maxx), '%Y-%m-%d')) while date <= end_date: key = datetime.date(date.year, date.month, date.day) - self.labels[key] = time.strftime(locale.nl_langinfo( - locale.D_FMT).replace('%y', '%Y'), + self.labels[key] = time.strftime( + LocaleTime().LC_date.replace('%y', '%Y'), time.strptime(str(key), DT_FORMAT)) self.datas.setdefault(key, {}) for yfield in self.yfields: diff --git a/tryton/gui/window/view_form/view/list_gtk/parser.py b/tryton/gui/window/view_form/view/list_gtk/parser.py index 2a74b2c800..b13a25dad0 100644 --- a/tryton/gui/window/view_form/view/list_gtk/parser.py +++ b/tryton/gui/window/view_form/view/list_gtk/parser.py @@ -19,12 +19,7 @@ import tryton.rpc as rpc import datetime as DT from tryton.common import DT_FORMAT, DHM_FORMAT, COLORS, node_attributes, TRYTON_ICON import tryton.common as common - -if not hasattr(locale, 'nl_langinfo'): - locale.nl_langinfo = lambda *a: '%x' - -if not hasattr(locale, 'D_FMT'): - locale.D_FMT = None +from _strptime import LocaleTime def send_keys(renderer, editable, position, treeview): editable.connect('key_press_event', treeview.on_keypressed) @@ -276,7 +271,7 @@ class Boolean(Int): class Date(Char): server_format = DT_FORMAT - display_format = locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y') + display_format = LocaleTime().LC_date.replace('%y', '%Y') def get_textual_value(self, model): value = model[self.field_name].get_client(model) @@ -302,7 +297,7 @@ class Date(Char): class Datetime(Date): server_format = DHM_FORMAT - display_format = locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y') + \ + display_format = LocaleTime().LC_date.replace('%y', '%Y') + \ ' %H:%M:%S' def get_textual_value(self, model): diff --git a/tryton/gui/window/view_form/widget_search/calendar.py b/tryton/gui/window/view_form/widget_search/calendar.py index 8e1e9b56a2..cc76506f28 100644 --- a/tryton/gui/window/view_form/widget_search/calendar.py +++ b/tryton/gui/window/view_form/widget_search/calendar.py @@ -6,15 +6,10 @@ import gettext import locale from interface import Interface from tryton.common import DT_FORMAT +from _strptime import LocaleTime _ = gettext.gettext -if not hasattr(locale, 'nl_langinfo'): - locale.nl_langinfo = lambda *a: '%x' - -if not hasattr(locale, 'D_FMT'): - locale.D_FMT = None - class Calendar(Interface): @@ -65,7 +60,7 @@ class Calendar(Interface): def _date_get(self, value): try: date = time.strptime(value, - locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y')) + LocaleTime().LC_date.replace('%y', '%Y')) except: return False return time.strftime(DT_FORMAT, date) @@ -115,7 +110,7 @@ class Calendar(Interface): year, month, day = cal.get_date() date = DT.date(year, month+1, day) dest.set_text(date.strftime( - locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'))) + LocaleTime().LC_date.replace('%y', '%Y'))) win.destroy() def clear(self): diff --git a/tryton/gui/window/view_tree/view_tree.py b/tryton/gui/window/view_tree/view_tree.py index 9136772c8c..0f530ae039 100644 --- a/tryton/gui/window/view_tree/view_tree.py +++ b/tryton/gui/window/view_tree/view_tree.py @@ -11,12 +11,7 @@ import datetime as DT import locale from tryton.common import DT_FORMAT, DHM_FORMAT import tryton.common as common - -if not hasattr(locale, 'nl_langinfo'): - locale.nl_langinfo = lambda *a: '%x' - -if not hasattr(locale, 'D_FMT'): - locale.D_FMT = None +from _strptime import LocaleTime FIELDS_LIST_TYPE = { 'boolean': gobject.TYPE_BOOLEAN, @@ -78,15 +73,14 @@ class ViewTreeModel(gtk.GenericTreeModel, gtk.TreeSortable): and 'widget' in self.fields_attrs[field]: field_type = self.fields_attrs[field]['widget'] if field_type in ('date',): - display_format = locale.nl_langinfo(locale.D_FMT).replace('%y', - '%Y') + display_format = LocaleTime().LC_date.replace('%y', '%Y') for obj in res_ids: if obj[field]: date = time.strptime(obj[field], DT_FORMAT) obj[field] = time.strftime(display_format, date) elif field_type in ('datetime',): - display_format = locale.nl_langinfo(locale.D_FMT).replace('%y', - '%Y') + ' %H:%M:%S' + display_format = LocaleTime().LC_date.replace('%y', '%Y') \ + + ' %H:%M:%S' for obj in res_ids: if obj[field]: date = time.strptime(obj[field], DHM_FORMAT)