changeset 77c8a0d86ecb in modules/country:default
details: https://hg.tryton.org/modules/country?cmd=changeset&node=77c8a0d86ecb
description:
        Add flag symbol for country and subdivision

        issue11599
        review433291003
diffstat:

 CHANGELOG             |   2 ++
 country.py            |  20 ++++++++++++++++++++
 view/country_tree.xml |   4 +++-
 3 files changed, 25 insertions(+), 1 deletions(-)

diffs (73 lines):

diff -r 68b41353f44e -r 77c8a0d86ecb CHANGELOG
--- a/CHANGELOG Fri Aug 26 18:12:02 2022 +0200
+++ b/CHANGELOG Fri Aug 26 18:21:15 2022 +0200
@@ -1,3 +1,5 @@
+* Add flag symbol for country and subdivision
+
 Version 6.4.0 - 2022-05-02
 * Bug fixes (see mercurial logs for details)
 * Use Tryton's CDN to download postal codes
diff -r 68b41353f44e -r 77c8a0d86ecb country.py
--- a/country.py        Fri Aug 26 18:12:02 2022 +0200
+++ b/country.py        Fri Aug 26 18:21:15 2022 +0200
@@ -19,6 +19,7 @@
         help="The 3 chars ISO country code.")
     code_numeric = fields.Char('Numeric Code', select=True,
         help="The ISO numeric country code.")
+    flag = fields.Function(fields.Char("Flag"), 'on_change_with_flag')
     subdivisions = fields.One2Many('country.subdivision',
             'country', 'Subdivisions')
 
@@ -49,6 +50,17 @@
         cursor.execute(*data.delete(where=(data.module == 'country')
                 & (data.model == cls.__name__)))
 
+    @fields.depends('code')
+    def on_change_with_flag(self, name=None):
+        if self.code:
+            return ''.join(map(chr, map(lambda c: 127397 + ord(c), self.code)))
+
+    def get_rec_name(self, name):
+        name = self.name
+        if self.flag:
+            name = ' '.join([self.flag, self.name])
+        return name
+
     @classmethod
     def search_rec_name(cls, name, clause):
         code_value = clause[2]
@@ -93,6 +105,7 @@
         help="The main identifier of the subdivision.")
     code = fields.Char('Code', required=True, select=True,
         help="The ISO code of the subdivision.")
+    flag = fields.Function(fields.Char("Flag"), 'on_change_with_flag')
     type = fields.Selection([
         (None, ""),
         ('administration', 'Administration'),
@@ -266,6 +279,13 @@
         # Migration from 6.2: remove type required
         table_h.not_null_action('type', action='remove')
 
+    @fields.depends('code')
+    def on_change_with_flag(self, name=None):
+        if self.code:
+            return '🏴' + ''.join(map(chr, map(
+                        lambda c: 917504 + ord(c),
+                        self.code.replace('-', '').lower()))) + '\U000e007f'
+
     @classmethod
     def search_rec_name(cls, name, clause):
         return ['OR',
diff -r 68b41353f44e -r 77c8a0d86ecb view/country_tree.xml
--- a/view/country_tree.xml     Fri Aug 26 18:12:02 2022 +0200
+++ b/view/country_tree.xml     Fri Aug 26 18:21:15 2022 +0200
@@ -2,6 +2,8 @@
 <!-- This file is part of Tryton.  The COPYRIGHT file at the top level of
 this repository contains the full copyright notices and license terms. -->
 <tree>
-    <field name="name" expand="1"/>
+    <field name="name" expand="1">
+        <prefix name="flag"/>
+    </field>
     <field name="code" optional="1"/>
 </tree>

Reply via email to