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
This commit is contained in:
1 parent
4fb4bd8754
commit
c33d6b2fee
3 files changed
+8
-7
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user