changeset 7168f1b5f966 in modules/country:default
details: https://hg.tryton.org/modules/country?cmd=changeset&node=7168f1b5f966
description:
Manage unknown subdivision type
issue11128
review397091002
diffstat:
CHANGELOG | 1 +
country.py | 8 +++++++-
scripts/import_countries.py | 13 ++++++++++++-
setup.py | 4 ++--
4 files changed, 22 insertions(+), 4 deletions(-)
diffs (95 lines):
diff -r 5374d2ebccd5 -r 7168f1b5f966 CHANGELOG
--- a/CHANGELOG Thu Jan 20 22:57:48 2022 +0100
+++ b/CHANGELOG Thu Jan 20 23:04:05 2022 +0100
@@ -1,3 +1,4 @@
+* Manage unknown subdivision type
* Add support for Python 3.10
* Remove support for Python 3.6
diff -r 5374d2ebccd5 -r 7168f1b5f966 country.py
--- a/country.py Thu Jan 20 22:57:48 2022 +0100
+++ b/country.py Thu Jan 20 23:04:05 2022 +0100
@@ -94,6 +94,7 @@
code = fields.Char('Code', required=True, select=True,
help="The ISO code of the subdivision.")
type = fields.Selection([
+ (None, ""),
('administration', 'Administration'),
('administrative area', 'Administrative area'),
('administrative atoll', 'Administrative atoll'),
@@ -198,7 +199,7 @@
('unitary authority (england)', 'Unitary authority (england)'),
('unitary authority (wales)', 'Unitary authority (wales)'),
('zone', 'zone'),
- ], 'Type', required=True)
+ ], "Type")
parent = fields.Many2One('country.subdivision', 'Parent',
domain=[
('country', '=', Eval('country', -1)),
@@ -220,10 +221,15 @@
super().__register__(module_name)
+ table_h = cls.__table_handler__(module_name)
+
# Migration from 5.2: remove country data
cursor.execute(*data.delete(where=(data.module == 'country')
& (data.model == cls.__name__)))
+ # Migration from 6.2: remove type required
+ table_h.not_null_action('type', action='remove')
+
@classmethod
def search_rec_name(cls, name, clause):
return ['OR',
diff -r 5374d2ebccd5 -r 7168f1b5f966 scripts/import_countries.py
--- a/scripts/import_countries.py Thu Jan 20 22:57:48 2022 +0100
+++ b/scripts/import_countries.py Thu Jan 20 23:04:05 2022 +0100
@@ -96,6 +96,8 @@
print("Update subdivisions", file=sys.stderr)
Subdivision = Model.get('country.subdivision')
+ types = dict(Subdivision._fields['type']['selection'])
+ unknown_types = set()
records = []
for subdivision in _progress(pycountry.subdivisions):
code = subdivision.code
@@ -105,7 +107,16 @@
else:
record = Subdivision(code=code, country=countries[country_code])
record.name = _remove_forbidden_chars(subdivision.name)
- record.type = subdivision.type.lower()
+ type_ = subdivision.type.lower()
+ if type_ in types:
+ record.type = subdivision.type.lower()
+ else:
+ record.type = None
+ if type_ not in unknown_types:
+ print(
+ "Unknown subdivision type: %s" % subdivision.type,
+ file=sys.stderr)
+ unknown_types.add(type_)
records.append(record)
Subdivision.save(records)
diff -r 5374d2ebccd5 -r 7168f1b5f966 setup.py
--- a/setup.py Thu Jan 20 22:57:48 2022 +0100
+++ b/setup.py Thu Jan 20 23:04:05 2022 +0100
@@ -67,7 +67,7 @@
requires.append(get_require_version('trytond_%s' % dep))
requires.append(get_require_version('trytond'))
-tests_require = [get_require_version('proteus'), 'pycountry<=20.7.3']
+tests_require = [get_require_version('proteus'), 'pycountry']
dependency_links = []
if minor_version % 2:
dependency_links.append(
@@ -143,7 +143,7 @@
python_requires='>=3.7',
install_requires=requires,
extras_require={
- 'data': ['pycountry<=20.7.3', get_require_version('proteus')],
+ 'data': ['pycountry', get_require_version('proteus')],
'GeoNames': [get_require_version('proteus')],
},
dependency_links=dependency_links,