Skip to content

Commit

Permalink
Check whether a ListChild is using new (w/ uuid) or old representatio…
Browse files Browse the repository at this point in the history
…n when mapping
  • Loading branch information
emilytoppm authored and gasman committed Jun 9, 2022
1 parent 038215f commit b5a56e4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions wagtail_transfer/streamfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,20 @@ def map_over_json(self, stream, func):
updated_stream = []
new_block = self.block.child_block
new_block_handler = get_block_handler(new_block)
block_is_in_new_format = getattr(
self.block,
"_item_is_in_block_format",
lambda x: False
)
for element in stream:
try:
new_value = new_block_handler.map_over_json(element, func)
updated_stream.append(new_value)
if block_is_in_new_format(element):
# We are dealing with new-style ListBlock representation
new_value = new_block_handler.map_over_json(element['value'], func)
updated_stream.append({'type': element['type'], 'value': new_value, 'id': element['id']})
else:
new_value = new_block_handler.map_over_json(element, func)
updated_stream.append(new_value)
except ValidationError:
pass
return updated_stream
Expand Down

0 comments on commit b5a56e4

Please sign in to comment.