Skip to content

Commit 0c42233

Browse files
authored
Merge pull request #367 from OpenDataServices/iati-fixes
Some bug fixes whilst working on IATI CoVE
2 parents ab4e63e + 906f0b4 commit 0c42233

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [0.15.2] - 2020-10-29
10+
11+
### Fixed
12+
13+
- Don't fail if compiled translation files (.mo) don't exist, and Django isn't installed
14+
- Fix some incorrect assumptions about types
15+
- Allow XML IDs to be attributes
16+
917
## [0.15.1] - 2020-10-21
1018

1119
### Fixed

flattentool/i18n.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@
1414
except ImproperlyConfigured:
1515
raise ImportError
1616

17-
# We set up the translations ourselves, instead of using Django's gettext
18-
# function, so that we can have a custom domain and locale directory.
19-
translations = {}
20-
translations["en"] = gettext.translation(domain, locale_dir, languages=["en"])
21-
translations["es"] = gettext.translation(domain, locale_dir, languages=["es"])
22-
23-
def _(text):
24-
lang = get_language()
25-
if lang not in translations:
26-
lang = "en"
27-
return translations[lang].gettext(text)
17+
try:
18+
# We set up the translations ourselves, instead of using Django's gettext
19+
# function, so that we can have a custom domain and locale directory.
20+
translations = {}
21+
translations["en"] = gettext.translation(domain, locale_dir, languages=["en"])
22+
translations["es"] = gettext.translation(domain, locale_dir, languages=["es"])
23+
24+
def _(text):
25+
lang = get_language()
26+
if lang not in translations:
27+
lang = "en"
28+
return translations[lang].gettext(text)
29+
30+
except FileNotFoundError:
31+
# If .mo files don't exist, pass a fake gettext function instead
32+
_ = lambda x: x
2833

2934

3035
except ImportError:

flattentool/input.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,17 +413,19 @@ def do_unflatten(self):
413413
)
414414

415415
def inthere(unflattened, id_name):
416-
if self.xml:
416+
if self.xml and not isinstance(unflattened.get(self.id_name), Cell):
417+
# For an XML tag
417418
return unflattened[id_name]["text()"].cell_value
418419
else:
420+
# For a JSON, or an XML attribute
419421
return unflattened[id_name].cell_value
420422

421423
if (
422424
self.id_name in unflattened
423425
and inthere(unflattened, self.id_name)
424426
in main_sheet_by_ocid[root_id_or_none]
425427
):
426-
if self.xml:
428+
if self.xml and not isinstance(unflattened.get(self.id_name), Cell):
427429
unflattened_id = unflattened.get(self.id_name)[
428430
"text()"
429431
].cell_value
@@ -752,7 +754,11 @@ def get_sheet_lines(self, sheet_name):
752754
if not header:
753755
# None means that the cell will be ignored
754756
value = None
755-
elif sheet_configuration.get("hashcomments") and header.startswith("#"):
757+
elif (
758+
sheet_configuration.get("hashcomments")
759+
and isinstance(header, str)
760+
and header.startswith("#")
761+
):
756762
# None means that the cell will be ignored
757763
value = None
758764
output_row[header] = value
@@ -945,7 +951,7 @@ def unflatten_main_with_parser(parser, line, timezone, xml, id_name):
945951
# Quick solution to avoid casting of date as datetinme in spreadsheet > xml
946952
if xml:
947953
if type(cell.cell_value) == datetime.datetime and not next_path_item:
948-
if "datetime" not in path:
954+
if "datetime" not in str(path):
949955
current_type = "date"
950956

951957
## Array
@@ -1116,7 +1122,11 @@ def __repr__(self):
11161122
def append(self, item):
11171123
if self.keyfield in item:
11181124
if self.xml:
1119-
if isinstance(item[self.keyfield]["text()"], Cell):
1125+
if isinstance(item[self.keyfield], Cell):
1126+
# For an XML attribute
1127+
key = item[self.keyfield].cell_value
1128+
elif isinstance(item[self.keyfield]["text()"], Cell):
1129+
# For an XML tag
11201130
key = item[self.keyfield]["text()"].cell_value
11211131
else:
11221132
key = item[self.keyfield]["text()"]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def run(self):
3939

4040
setup(
4141
name="flattentool",
42-
version="0.15.1",
42+
version="0.15.2",
4343
author="Open Data Services",
4444
author_email="[email protected]",
4545
packages=["flattentool"],

0 commit comments

Comments
 (0)