Skip to content

Commit

Permalink
Merge pull request #367 from OpenDataServices/iati-fixes
Browse files Browse the repository at this point in the history
Some bug fixes whilst working on IATI CoVE
  • Loading branch information
Bjwebb authored Nov 3, 2020
2 parents ab4e63e + 906f0b4 commit 0c42233
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.15.2] - 2020-10-29

### Fixed

- Don't fail if compiled translation files (.mo) don't exist, and Django isn't installed
- Fix some incorrect assumptions about types
- Allow XML IDs to be attributes

## [0.15.1] - 2020-10-21

### Fixed
Expand Down
27 changes: 16 additions & 11 deletions flattentool/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@
except ImproperlyConfigured:
raise ImportError

# We set up the translations ourselves, instead of using Django's gettext
# function, so that we can have a custom domain and locale directory.
translations = {}
translations["en"] = gettext.translation(domain, locale_dir, languages=["en"])
translations["es"] = gettext.translation(domain, locale_dir, languages=["es"])

def _(text):
lang = get_language()
if lang not in translations:
lang = "en"
return translations[lang].gettext(text)
try:
# We set up the translations ourselves, instead of using Django's gettext
# function, so that we can have a custom domain and locale directory.
translations = {}
translations["en"] = gettext.translation(domain, locale_dir, languages=["en"])
translations["es"] = gettext.translation(domain, locale_dir, languages=["es"])

def _(text):
lang = get_language()
if lang not in translations:
lang = "en"
return translations[lang].gettext(text)

except FileNotFoundError:
# If .mo files don't exist, pass a fake gettext function instead
_ = lambda x: x


except ImportError:
Expand Down
20 changes: 15 additions & 5 deletions flattentool/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,17 +413,19 @@ def do_unflatten(self):
)

def inthere(unflattened, id_name):
if self.xml:
if self.xml and not isinstance(unflattened.get(self.id_name), Cell):
# For an XML tag
return unflattened[id_name]["text()"].cell_value
else:
# For a JSON, or an XML attribute
return unflattened[id_name].cell_value

if (
self.id_name in unflattened
and inthere(unflattened, self.id_name)
in main_sheet_by_ocid[root_id_or_none]
):
if self.xml:
if self.xml and not isinstance(unflattened.get(self.id_name), Cell):
unflattened_id = unflattened.get(self.id_name)[
"text()"
].cell_value
Expand Down Expand Up @@ -752,7 +754,11 @@ def get_sheet_lines(self, sheet_name):
if not header:
# None means that the cell will be ignored
value = None
elif sheet_configuration.get("hashcomments") and header.startswith("#"):
elif (
sheet_configuration.get("hashcomments")
and isinstance(header, str)
and header.startswith("#")
):
# None means that the cell will be ignored
value = None
output_row[header] = value
Expand Down Expand Up @@ -945,7 +951,7 @@ def unflatten_main_with_parser(parser, line, timezone, xml, id_name):
# Quick solution to avoid casting of date as datetinme in spreadsheet > xml
if xml:
if type(cell.cell_value) == datetime.datetime and not next_path_item:
if "datetime" not in path:
if "datetime" not in str(path):
current_type = "date"

## Array
Expand Down Expand Up @@ -1116,7 +1122,11 @@ def __repr__(self):
def append(self, item):
if self.keyfield in item:
if self.xml:
if isinstance(item[self.keyfield]["text()"], Cell):
if isinstance(item[self.keyfield], Cell):
# For an XML attribute
key = item[self.keyfield].cell_value
elif isinstance(item[self.keyfield]["text()"], Cell):
# For an XML tag
key = item[self.keyfield]["text()"].cell_value
else:
key = item[self.keyfield]["text()"]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def run(self):

setup(
name="flattentool",
version="0.15.1",
version="0.15.2",
author="Open Data Services",
author_email="[email protected]",
packages=["flattentool"],
Expand Down

0 comments on commit 0c42233

Please sign in to comment.