Add local context to get context without session context
The issue8312 was to strict by its usage of Group._context as it misses the context_model, the parent context or the _datetime keys. Instead we introduce a second type of context which provides the same context but without the session part. issue8463 review255831002
This commit is contained in:
1 parent
7d3c2a5238
commit
8d3a4bae45
5 files changed
+37
-15
No files matched your search
@@ -548,7 +548,7 @@ class Form(SignalEvent, TabContent):
|
||||
'id': record_id,
|
||||
'ids': record_ids,
|
||||
}
|
||||
Action._exec_action(action, data, self.screen.group._context.copy())
|
||||
Action._exec_action(action, data, self.screen.local_context)
|
||||
|
||||
def activate_save(self):
|
||||
self.buttons['save'].props.sensitive = self.screen.modified()
|
||||
|
||||
@@ -61,11 +61,11 @@ class Field(object):
|
||||
def validation_domains(self, record, pre_validate=None):
|
||||
return concat(*self.domains_get(record, pre_validate))
|
||||
|
||||
def get_context(self, record, record_context=None):
|
||||
def get_context(self, record, record_context=None, local=False):
|
||||
if record_context is not None:
|
||||
context = record_context.copy()
|
||||
else:
|
||||
context = record.get_context()
|
||||
context = record.get_context(local=local)
|
||||
context.update(record.expr_eval(self.attrs.get('context', {})))
|
||||
return context
|
||||
|
||||
@@ -444,8 +444,9 @@ class M2OField(Field):
|
||||
record.value.setdefault(self.name + '.', {})['rec_name'] = rec_name
|
||||
record.value[self.name] = value
|
||||
|
||||
def get_context(self, record, record_context=None):
|
||||
context = super(M2OField, self).get_context(record, record_context)
|
||||
def get_context(self, record, record_context=None, local=False):
|
||||
context = super(M2OField, self).get_context(
|
||||
record, record_context=record_context, local=local)
|
||||
if self.attrs.get('datetime_field'):
|
||||
context['_datetime'] = record.get_eval(
|
||||
)[self.attrs.get('datetime_field')]
|
||||
@@ -866,9 +867,9 @@ class ReferenceField(Field):
|
||||
record.value[self.name] = ref_model, ref_id
|
||||
record.value.setdefault(self.name + '.', {})['rec_name'] = rec_name
|
||||
|
||||
def get_context(self, record, record_context=None):
|
||||
def get_context(self, record, record_context=None, local=False):
|
||||
context = super(ReferenceField, self).get_context(
|
||||
record, record_context)
|
||||
record, record_context, local=local)
|
||||
if self.attrs.get('datetime_field'):
|
||||
context['_datetime'] = record.get_eval(
|
||||
)[self.attrs.get('datetime_field')]
|
||||
|
||||
@@ -279,13 +279,24 @@ class Group(SignalEvent, list):
|
||||
|
||||
@property
|
||||
def context(self):
|
||||
ctx = rpc.CONTEXT.copy()
|
||||
return self._get_context(local=False)
|
||||
|
||||
@property
|
||||
def local_context(self):
|
||||
return self._get_context(local=True)
|
||||
|
||||
def _get_context(self, local=False):
|
||||
if not local:
|
||||
ctx = rpc.CONTEXT.copy()
|
||||
else:
|
||||
ctx = {}
|
||||
if self.parent:
|
||||
parent_context = self.parent.get_context()
|
||||
parent_context = self.parent.get_context(local=local)
|
||||
ctx.update(parent_context)
|
||||
if self.child_name in self.parent.group.fields:
|
||||
field = self.parent.group.fields[self.child_name]
|
||||
ctx.update(field.get_context(self.parent, parent_context))
|
||||
ctx.update(field.get_context(
|
||||
self.parent, parent_context, local=local))
|
||||
ctx.update(self._context)
|
||||
if self.parent_datetime_field:
|
||||
ctx['_datetime'] = self.parent.get_eval(
|
||||
|
||||
@@ -398,8 +398,11 @@ class Record(SignalEvent):
|
||||
|
||||
invalid_fields = property(_get_invalid_fields)
|
||||
|
||||
def get_context(self):
|
||||
return self.group.context
|
||||
def get_context(self, local=False):
|
||||
if not local:
|
||||
return self.group.context
|
||||
else:
|
||||
return self.group.local_context
|
||||
|
||||
def set_default(self, val, signal=True, validate=True):
|
||||
fieldnames = []
|
||||
|
||||
@@ -256,7 +256,7 @@ class Screen(SignalEvent):
|
||||
self.clear()
|
||||
self.context_screen.display(set_cursor=True)
|
||||
return False
|
||||
context = self.group._context.copy()
|
||||
context = self.local_context
|
||||
context.update(self.context_screen.get_on_change_value())
|
||||
self.new_group(context)
|
||||
|
||||
@@ -362,6 +362,13 @@ class Screen(SignalEvent):
|
||||
context['context_model'] = self.context_screen.model_name
|
||||
return context
|
||||
|
||||
@property
|
||||
def local_context(self):
|
||||
context = self.group.local_context
|
||||
if self.context_screen:
|
||||
context['context_model'] = self.context_screen.model_name
|
||||
return context
|
||||
|
||||
def __get_group(self):
|
||||
return self.__group
|
||||
|
||||
@@ -467,7 +474,7 @@ class Screen(SignalEvent):
|
||||
'model': self.model_name,
|
||||
'id': self.current_record.id if self.current_record else None,
|
||||
'ids': [r.id for r in self.selected_records],
|
||||
}, context=self.group._context.copy(), warning=False)
|
||||
}, context=self.local_context, warning=False)
|
||||
else:
|
||||
if not self.modified():
|
||||
self.switch_view(view_type='form')
|
||||
@@ -1199,7 +1206,7 @@ class Screen(SignalEvent):
|
||||
if self.domain:
|
||||
query_string.append(('domain', json.dumps(
|
||||
self.domain, cls=JSONEncoder, separators=(',', ':'))))
|
||||
context = self.group._context # Avoid rpc context
|
||||
context = self.local_context # Avoid rpc context
|
||||
if context:
|
||||
query_string.append(('context', json.dumps(
|
||||
context, cls=JSONEncoder, separators=(',', ':'))))
|
||||
|
||||
Reference in new issue
Block a user