From ae341b9112bc7604713da5f83df5ce1033a24699 Mon Sep 17 00:00:00 2001 From: Andy Lulham Date: Wed, 20 Nov 2019 15:23:18 +0000 Subject: [PATCH] Use the default mapping (if we have one) Default mappings should be preferred. --- data.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/data.py b/data.py index 55c4e32d1a..00567724e4 100644 --- a/data.py +++ b/data.py @@ -211,7 +211,13 @@ def transform_codelist_mapping_keys(codelist_mapping): return codelist_mapping def create_codelist_mapping(major_version): - codelist_mapping = {x['path']:x['codelist'] for x in json.load(open('data/IATI-Codelists-{}/out/clv2/mapping.json'.format(major_version)))} + codelist_mapping = {} + for x in json.load(open('data/IATI-Codelists-{}/out/clv2/mapping.json'.format(major_version))): + if 'condition' in x \ + and x['path'] in codelist_mapping \ + and not re.search(r'not\([^)]+\)', x['condition']): + continue + codelist_mapping[x['path']] = x['codelist'] return transform_codelist_mapping_keys(codelist_mapping) MAJOR_VERSIONS = ['2', '1']