Skip to content

Commit

Permalink
order repeats according to XLSForm order, closes #873
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanga committed Jan 14, 2017
1 parent 95aa99a commit bbaa2aa
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions onadata/libs/utils/csv_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ def _reindex(cls, key, value, ordered_columns, row, data_dictionary,
"""
Flatten list columns by appending an index, otherwise return as is
"""
def get_ordered_repeat_value(xpath, repeat_value):
item = OrderedDict()
repeat_group = data_dictionary.get_survey_element(xpath)
for elem in repeat_group.children:
xp = elem.get_abbreviated_xpath()
if xp in repeat_value:
item[xp] = repeat_value[xp]

return item

d = {}

# check for lists
Expand All @@ -349,6 +359,8 @@ def _reindex(cls, key, value, ordered_columns, row, data_dictionary,
# for each list check for dict, we want to transform the key of
# this dict
if type(item) is dict:
# order repeat according to xform order
item = get_ordered_repeat_value(key, item)
for nested_key, nested_val in item.iteritems():
# given the key "children/details" and nested_key/
# abbreviated xpath
Expand Down

0 comments on commit bbaa2aa

Please sign in to comment.