changeset 7dc88cf0b5be in tryton:default
details: https://hg.tryton.org/tryton?cmd=changeset;node=7dc88cf0b5be
description:
        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
diffstat:

 tryton/gui/window/form.py                    |   2 +-
 tryton/gui/window/view_form/model/field.py   |  13 +++++++------
 tryton/gui/window/view_form/model/group.py   |  17 ++++++++++++++---
 tryton/gui/window/view_form/model/record.py  |   7 +++++--
 tryton/gui/window/view_form/screen/screen.py |  13 ++++++++++---
 5 files changed, 37 insertions(+), 15 deletions(-)

diffs (145 lines):

diff -r 58cd75f0903a -r 7dc88cf0b5be tryton/gui/window/form.py
--- a/tryton/gui/window/form.py Mon Aug 12 12:16:41 2019 +0200
+++ b/tryton/gui/window/form.py Sun Aug 18 18:51:54 2019 +0200
@@ -548,7 +548,7 @@
             '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()
diff -r 58cd75f0903a -r 7dc88cf0b5be tryton/gui/window/view_form/model/field.py
--- a/tryton/gui/window/view_form/model/field.py        Mon Aug 12 12:16:41 
2019 +0200
+++ b/tryton/gui/window/view_form/model/field.py        Sun Aug 18 18:51:54 
2019 +0200
@@ -61,11 +61,11 @@
     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 @@
         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 @@
         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')]
diff -r 58cd75f0903a -r 7dc88cf0b5be tryton/gui/window/view_form/model/group.py
--- a/tryton/gui/window/view_form/model/group.py        Mon Aug 12 12:16:41 
2019 +0200
+++ b/tryton/gui/window/view_form/model/group.py        Sun Aug 18 18:51:54 
2019 +0200
@@ -279,13 +279,24 @@
 
     @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(
diff -r 58cd75f0903a -r 7dc88cf0b5be tryton/gui/window/view_form/model/record.py
--- a/tryton/gui/window/view_form/model/record.py       Mon Aug 12 12:16:41 
2019 +0200
+++ b/tryton/gui/window/view_form/model/record.py       Sun Aug 18 18:51:54 
2019 +0200
@@ -398,8 +398,11 @@
 
     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 = []
diff -r 58cd75f0903a -r 7dc88cf0b5be 
tryton/gui/window/view_form/screen/screen.py
--- a/tryton/gui/window/view_form/screen/screen.py      Mon Aug 12 12:16:41 
2019 +0200
+++ b/tryton/gui/window/view_form/screen/screen.py      Sun Aug 18 18:51:54 
2019 +0200
@@ -256,7 +256,7 @@
                 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 @@
             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 @@
                 '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 @@
         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=(',', ':'))))

Reply via email to