From 4c24fa6bcfe14723a85d0f455a3d4d7d108f2daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 4 Feb 2018 23:38:27 +0100 Subject: [PATCH] Add common date_format to fallback to rpc context format Since issue6082, the rpc context locale date format is no more set in the group context. issue7071 review40971002 --- tryton/common/common.py | 4 ++++ tryton/gui/window/view_form/model/field.py | 6 +++--- tryton/gui/window/view_form/screen/screen.py | 6 ------ tryton/gui/window/view_form/view/form_gtk/calendar.py | 7 +++++-- tryton/gui/window/view_form/view/screen_container.py | 3 ++- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tryton/common/common.py b/tryton/common/common.py index 47c01cff36..1c2f037b71 100644 --- a/tryton/common/common.py +++ b/tryton/common/common.py @@ -1430,3 +1430,7 @@ def ellipsize(string, length): return string ellipsis = _('...') return string[:length - len(ellipsis)] + ellipsis + + +def date_format(format_): + return format_ or rpc.CONTEXT.get('locale', {}).get('date', '%x') diff --git a/tryton/gui/window/view_form/model/field.py b/tryton/gui/window/view_form/model/field.py index ab203b0ba5..0901616103 100644 --- a/tryton/gui/window/view_form/model/field.py +++ b/tryton/gui/window/view_form/model/field.py @@ -230,7 +230,7 @@ class DateTimeField(Field): def date_format(self, record): context = self.get_context(record) - return context.get('date_format', '%x') + return common.date_format(context.get('date_format')) def time_format(self, record): return record.expr_eval(self.attrs['format']) @@ -249,7 +249,7 @@ class DateField(Field): def date_format(self, record): context = self.get_context(record) - return context.get('date_format', '%x') + return common.date_format(context.get('date_format')) class TimeField(Field): @@ -956,7 +956,7 @@ class DictField(Field): def date_format(self, record): context = self.get_context(record) - return context.get('date_format', '%x') + return common.date_format(context.get('date_format')) def time_format(self, record): return '%X' diff --git a/tryton/gui/window/view_form/screen/screen.py b/tryton/gui/window/view_form/screen/screen.py index 8e56ae2b45..76895c67bb 100644 --- a/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/gui/window/view_form/screen/screen.py @@ -129,8 +129,6 @@ class Screen(SignalEvent): self.search_value = attributes.get('search_value') self.fields_view_tree = {} self.order = self.default_order = attributes.get('order') - self.__date_format = self.context.get( - 'date_format', rpc.CONTEXT.get('locale', {}).get('date', '%x')) self.view_to_load = [] self._domain_parser = {} self.pre_validate = False @@ -335,10 +333,6 @@ class Screen(SignalEvent): def context(self): return self.group.context - @property - def date_format(self): - return self.__date_format - def __get_group(self): return self.__group 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 9d4dd94cb8..f5ce76d01b 100644 --- a/tryton/gui/window/view_form/view/form_gtk/calendar.py +++ b/tryton/gui/window/view_form/view/form_gtk/calendar.py @@ -8,6 +8,7 @@ import gettext import gobject from .widget import Widget +from tryton import common from tryton.common.datetime_ import (Date as DateEntry, Time as TimeEntry, DateTime as DateTimeEntry, add_operators) from tryton.common.widget_style import set_widget_style @@ -73,7 +74,8 @@ class Date(Widget): if field and record: format_ = field.date_format(record) else: - format_ = self.view.screen.date_format + format_ = common.date_format( + self.view.screen.context.get('date_format')) self.entry.props.format = format_ def display(self, record, field): @@ -161,7 +163,8 @@ class DateTime(Date): date_format = field.date_format(record) time_format = field.time_format(record) else: - date_format = self.view.screen.date_format + date_format = common.date_format( + self.view.screen.context.get('date_format')) time_format = '%X' self.entry.props.date_format = date_format self.entry.props.time_format = time_format diff --git a/tryton/gui/window/view_form/view/screen_container.py b/tryton/gui/window/view_form/view/screen_container.py index 97daf302da..0cb78c3e31 100644 --- a/tryton/gui/window/view_form/view/screen_container.py +++ b/tryton/gui/window/view_form/view/screen_container.py @@ -556,7 +556,8 @@ class ScreenContainer(object): entry = Selection(selections) yoptions = gtk.FILL | gtk.EXPAND elif field['type'] in ('date', 'datetime', 'time'): - date_format = self.screen.context.get('date_format', '%x') + date_format = common.date_format( + self.screen.context.get('date_format')) if field['type'] == 'date': entry = Dates(date_format) elif field['type'] in ('datetime', 'time'):