Skip to content

Commit e94c22e

Browse files
committed
input: Allow xml ids to be attributes
1 parent d67b242 commit e94c22e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010

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

1415
## [0.15.1] - 2020-10-21
1516

flattentool/input.py

Lines changed: 9 additions & 3 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
@@ -1120,7 +1122,11 @@ def __repr__(self):
11201122
def append(self, item):
11211123
if self.keyfield in item:
11221124
if self.xml:
1123-
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
11241130
key = item[self.keyfield]["text()"].cell_value
11251131
else:
11261132
key = item[self.keyfield]["text()"]

0 commit comments

Comments
 (0)