changeset 98a106a6fd84 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=98a106a6fd84
description:
        Add language attribute to data tag

        issue9559
        review302061002
diffstat:

 CHANGELOG                    |  1 +
 doc/topics/modules/index.rst |  1 +
 trytond/convert.py           |  6 +++++-
 trytond/modules/__init__.py  |  2 +-
 trytond/tests/test_tryton.py |  3 ++-
 trytond/tryton.rnc           |  1 +
 trytond/tryton.rng           |  8 ++++++++
 7 files changed, 19 insertions(+), 3 deletions(-)

diffs (110 lines):

diff -r 8288b688cfeb -r 98a106a6fd84 CHANGELOG
--- a/CHANGELOG Thu Sep 17 17:18:02 2020 +0200
+++ b/CHANGELOG Fri Sep 18 00:06:31 2020 +0200
@@ -1,3 +1,4 @@
+* Add language attribute to data tag
 * Add e-mail template
 * Send e-mail on behalf of user
 * Register mixins to generic Report class
diff -r 8288b688cfeb -r 98a106a6fd84 doc/topics/modules/index.rst
--- a/doc/topics/modules/index.rst      Thu Sep 17 17:18:02 2020 +0200
+++ b/doc/topics/modules/index.rst      Fri Sep 18 00:06:31 2020 +0200
@@ -118,6 +118,7 @@
         * ``depends`` to import data only if all modules in the comma separated
           module list value are activated,
         * ``grouped`` to create records at the end with a grouped call.
+        * ``language`` to import data only if the language is translatable.
 
     * ``record``: Create a record of the model defined by the attribute
       ``model`` in the database. The ``id`` attribute can be used to refer to
diff -r 8288b688cfeb -r 98a106a6fd84 trytond/convert.py
--- a/trytond/convert.py        Thu Sep 17 17:18:02 2020 +0200
+++ b/trytond/convert.py        Fri Sep 18 00:06:31 2020 +0200
@@ -410,7 +410,7 @@
 
 class TrytondXmlHandler(sax.handler.ContentHandler):
 
-    def __init__(self, pool, module, module_state, modules):
+    def __init__(self, pool, module, module_state, modules, languages):
         "Register known taghandlers, and managed tags."
         sax.handler.ContentHandler.__init__(self)
 
@@ -427,6 +427,7 @@
         self.grouped_model_data = []
         self.skip_data = False
         self.modules = modules
+        self.languages = languages
 
         # Tag handlders are used to delegate the processing
         self.taghandlerlist = {
@@ -477,6 +478,9 @@
                 depends = {m.strip() for m in depends if m}
                 if not depends.issubset(self.modules):
                     self.skip_data = True
+                if (attributes.get('language')
+                        and attributes.get('language') not in self.languages):
+                    self.skip_data = True
 
             elif name == "tryton":
                 pass
diff -r 8288b688cfeb -r 98a106a6fd84 trytond/modules/__init__.py
--- a/trytond/modules/__init__.py       Thu Sep 17 17:18:02 2020 +0200
+++ b/trytond/modules/__init__.py       Fri Sep 18 00:06:31 2020 +0200
@@ -242,7 +242,7 @@
 
                 # Instanciate a new parser for the module
                 tryton_parser = convert.TrytondXmlHandler(
-                    pool, module, package_state, modules)
+                    pool, module, package_state, modules, lang)
 
                 for filename in node.info.get('xml', []):
                     filename = filename.replace('/', os.sep)
diff -r 8288b688cfeb -r 98a106a6fd84 trytond/tests/test_tryton.py
--- a/trytond/tests/test_tryton.py      Thu Sep 17 17:18:02 2020 +0200
+++ b/trytond/tests/test_tryton.py      Fri Sep 18 00:06:31 2020 +0200
@@ -214,6 +214,7 @@
     'Trytond Test Case'
     module = None
     extras = None
+    language = 'en'
 
     @classmethod
     def setUpClass(cls):
@@ -221,7 +222,7 @@
         modules = [cls.module]
         if cls.extras:
             modules.extend(cls.extras)
-        activate_module(modules)
+        activate_module(modules, lang=cls.language)
         super(ModuleTestCase, cls).setUpClass()
 
     @classmethod
diff -r 8288b688cfeb -r 98a106a6fd84 trytond/tryton.rnc
--- a/trytond/tryton.rnc        Thu Sep 17 17:18:02 2020 +0200
+++ b/trytond/tryton.rnc        Fri Sep 18 00:06:31 2020 +0200
@@ -8,6 +8,7 @@
 attlist.data &=
   [ a:defaultValue = "0" ] attribute grouped { "0" | "1" }?
 attlist.data &= attribute depends { text }?
+attlist.data &= attribute language { text }?
 record = element record { attlist.record, field* }
 attlist.record &= attribute model { text }
 attlist.record &= attribute id { text }
diff -r 8288b688cfeb -r 98a106a6fd84 trytond/tryton.rng
--- a/trytond/tryton.rng        Thu Sep 17 17:18:02 2020 +0200
+++ b/trytond/tryton.rng        Fri Sep 18 00:06:31 2020 +0200
@@ -55,6 +55,14 @@
       </attribute>
     </optional>
   </define>
+  <define name="attlist.data" combine="interleave">
+    <optional>
+      <attribute>
+        <name ns="">language</name>
+        <text/>
+      </attribute>
+    </optional>
+  </define>
   <define name="record">
     <element>
       <name ns="">record</name>

Reply via email to