Skip to content

Commit 8411080

Browse files
committed
[#67] Fix rollup with titles
1 parent 6e7b89a commit 8411080

File tree

3 files changed

+102
-76
lines changed

3 files changed

+102
-76
lines changed

flattentool/json_input.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ def parse_json_dict(self, json_dict, sheet, json_key=None, parent_name='', flatt
140140
if self.rollup and parent_name == '': # Rollup only currently possible to main sheet
141141
if len(value) == 1:
142142
for k, v in value[0].items():
143-
if parent_name+key+'/0/'+k in self.schema_parser.main_sheet:
143+
if self.use_titles and parent_name+key+'/0/'+k in self.schema_parser.main_sheet.titles:
144+
if type(v) in BASIC_TYPES:
145+
flattened_dict[sheet_key_title(sheet, parent_name+key+'/0/'+k)] = v
146+
else:
147+
raise ValueError('Rolled up values must be basic types')
148+
elif not self.use_titles and parent_name+key+'/0/'+k in self.schema_parser.main_sheet:
144149
if type(v) in BASIC_TYPES:
145150
flattened_dict[sheet_key(sheet, parent_name+key+'/0/'+k)] = v
146151
else:

flattentool/tests/test_input_SpreadsheetInput_unflatten.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -590,19 +590,15 @@ def create_schema(root_id):
590590
}
591591
}
592592
},
593-
'testR': {
594-
'title': 'R title',
593+
'testArr': {
594+
'title': 'Arr title',
595595
'type': 'array',
596-
'rollUp': ['id', 'testB'],
597596
'items': {
598597
'type': 'object',
599598
'properties': {
600599
'id': {
601600
'title': 'Identifier',
602601
'type': 'string',
603-
# 'type': 'integer',
604-
# integer does not work, as testB:integer is not
605-
# in the rollUp
606602
},
607603
'testB': {
608604
'title': 'B title',
@@ -612,13 +608,6 @@ def create_schema(root_id):
612608
'title': 'C title',
613609
'type': 'string',
614610
},
615-
'testSA': {
616-
'title': 'SA title',
617-
'type': 'array',
618-
'items': {
619-
'type': 'string'
620-
}
621-
},
622611
'testNest': {
623612
'title': 'Nest title',
624613
'type': 'array',
@@ -653,6 +642,38 @@ def create_schema(root_id):
653642
}
654643
}
655644
},
645+
'testR': {
646+
'title': 'R title',
647+
'type': 'array',
648+
'rollUp': ['id', 'testB'],
649+
'items': {
650+
'type': 'object',
651+
'properties': {
652+
'id': {
653+
'title': 'Identifier',
654+
'type': 'string',
655+
# 'type': 'integer',
656+
# integer does not work, as testB:integer is not
657+
# in the rollUp
658+
},
659+
'testB': {
660+
'title': 'B title',
661+
'type': 'string',
662+
},
663+
'testC': {
664+
'title': 'C title',
665+
'type': 'string',
666+
},
667+
'testSA': {
668+
'title': 'SA title',
669+
'type': 'array',
670+
'items': {
671+
'type': 'string'
672+
}
673+
},
674+
}
675+
}
676+
},
656677
'testU': {
657678
'title': UNICODE_TEST_STRING,
658679
'type': 'string',

0 commit comments

Comments
 (0)