changeset 338781cb8e2a in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=338781cb8e2a
description:
        Make ModelView.parse_view public

        issue10073
        review333851028
diffstat:

 CHANGELOG                  |   1 +
 doc/ref/models/models.rst  |  11 +++++++++++
 trytond/model/modelview.py |  28 +++++++++++++++++-----------
 3 files changed, 29 insertions(+), 11 deletions(-)

diffs (101 lines):

diff -r b00d30820a9e -r 338781cb8e2a CHANGELOG
--- a/CHANGELOG Sun Feb 14 15:54:29 2021 +0100
+++ b/CHANGELOG Sun Feb 14 15:56:18 2021 +0100
@@ -1,3 +1,4 @@
+* Make ModelView.parse_view public
 * Add help for each value to selection and multiselection
 * Use safe_join in SharedDataMiddlewareIndex (issue10068)
 * Use menu name for window opened from menu
diff -r b00d30820a9e -r 338781cb8e2a doc/ref/models/models.rst
--- a/doc/ref/models/models.rst Sun Feb 14 15:54:29 2021 +0100
+++ b/doc/ref/models/models.rst Sun Feb 14 15:56:18 2021 +0100
@@ -174,6 +174,17 @@
     encoded value. If the depends list is set its fields are added to the
     view if the xpath matches at least one element.
 
+
+.. classmethod:: ModelView.parse_view(tree, type[, field_children[, level[, 
view_depends]]])
+
+    Return the sanitized XML and the corresponding fields definition.
+
+
+.. note::
+
+    This method is public mainly to allow modification the existing XML of the
+    view by code.
+
 ============
 ModelStorage
 ============
diff -r b00d30820a9e -r 338781cb8e2a trytond/model/modelview.py
--- a/trytond/model/modelview.py        Sun Feb 14 15:54:29 2021 +0100
+++ b/trytond/model/modelview.py        Sun Feb 14 15:56:18 2021 +0100
@@ -376,10 +376,8 @@
         # Update arch and compute fields from arch
         parser = etree.XMLParser(remove_blank_text=True)
         tree = etree.fromstring(result['arch'], parser)
-        xarch, xfields = cls._view_look_dom_arch(
+        result['arch'], result['fields'] = cls.parse_view(
             tree, result['type'], result['field_childs'], level=level)
-        result['arch'] = xarch
-        result['fields'] = xfields
 
         cls._fields_view_get_cache.set(key, result)
         return result
@@ -427,13 +425,20 @@
         return []
 
     @classmethod
-    def _view_look_dom_arch(cls, tree, type, field_children=None, level=0):
+    def parse_view(
+            cls, tree, type, field_children=None, level=0, view_depends=None):
+        """
+        Return sanitized XML and the corresponding fields definition
+        """
         pool = Pool()
         ModelAccess = pool.get('ir.model.access')
         FieldAccess = pool.get('ir.model.field.access')
 
         encoder = PYSONEncoder()
-        view_depends = []
+        if view_depends is None:
+            view_depends = []
+        else:
+            view_depends = view_depends.copy()
         for xpath, attribute, value, *extra in cls.view_attributes():
             depends = []
             if extra:
@@ -510,8 +515,8 @@
                 if viewtreewidth.width > 0:
                     fields_width[viewtreewidth.field] = viewtreewidth.width
 
-        fields_def = cls.__view_look_dom(tree_root, type,
-                fields_width=fields_width)
+        fields_def = cls.__parse_fields(
+            tree_root, type, fields_width=fields_width)
 
         if hasattr(cls, 'active'):
             fields_def.setdefault('active', {'name': 'active'})
@@ -552,8 +557,8 @@
         return arch, fields2
 
     @classmethod
-    def __view_look_dom(cls, element, type, fields_width=None,
-            _fields_attrs=None):
+    def __parse_fields(
+            cls, element, type, fields_width=None, _fields_attrs=None):
         pool = Pool()
         Translation = pool.get('ir.translation')
         ModelData = pool.get('ir.model.data')
@@ -711,8 +716,9 @@
                     fields_attrs.setdefault(element.get(attr), {})
 
         for field in element:
-            fields_attrs = cls.__view_look_dom(field, type,
-                fields_width=fields_width, _fields_attrs=fields_attrs)
+            fields_attrs = cls.__parse_fields(
+                field, type, fields_width=fields_width,
+                _fields_attrs=fields_attrs)
         return fields_attrs
 
     @staticmethod

Reply via email to