From c33d6b2feed540afb7ade8876791801af203d45d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 13 Dec 2016 18:35:39 +0100 Subject: [PATCH] Store default date format as Screen property Instead of setting date_format in every context (which will be included in url), it is better to store the default value on the Screen. Also it should be stored privately on the Screen to avoid modification which could result into an inconsistency on the display. issue6082 review25841002 --- tryton/action/main.py | 5 ----- tryton/gui/window/view_form/screen/screen.py | 6 ++++++ tryton/gui/window/view_form/view/form_gtk/calendar.py | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tryton/action/main.py b/tryton/action/main.py index 7159c0f3c2..c5eb1715df 100644 --- a/tryton/action/main.py +++ b/tryton/action/main.py @@ -69,11 +69,6 @@ class Action(object): def _exec_action(action, data=None, context=None): if context is None: context = {} - else: - context = context.copy() - if 'date_format' not in context: - context['date_format'] = rpc.CONTEXT.get( - 'locale', {}).get('date', '%x') if data is None: data = {} else: diff --git a/tryton/gui/window/view_form/screen/screen.py b/tryton/gui/window/view_form/screen/screen.py index f7f7492f42..549de46f28 100644 --- a/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/gui/window/view_form/screen/screen.py @@ -137,6 +137,8 @@ class Screen(SignalEvent): self.search_value = search_value self.fields_view_tree = {} self.order = self.default_order = order + self.__date_format = context.get( + 'date_format', rpc.CONTEXT.get('locale', {}).get('date', '%x')) self.view_to_load = [] self._domain_parser = {} self.pre_validate = False @@ -328,6 +330,10 @@ 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 7c6af7be85..505522dea7 100644 --- a/tryton/gui/window/view_form/view/form_gtk/calendar.py +++ b/tryton/gui/window/view_form/view/form_gtk/calendar.py @@ -64,7 +64,7 @@ class Date(Widget): if field and record: format_ = field.date_format(record) else: - format_ = self.view.screen.context.get('date_format', '%x') + format_ = self.view.screen.date_format self.entry.props.format = format_ def display(self, record, field): @@ -142,7 +142,7 @@ class DateTime(Date): date_format = field.date_format(record) time_format = field.time_format(record) else: - date_format = self.view.screen.context.get('date_format', '%x') + date_format = self.view.screen.date_format time_format = '%X' self.entry.props.date_format = date_format self.entry.props.time_format = time_format