From d7e2d6721e721887eadaf2bf30f0bb09aa92681c Mon Sep 17 00:00:00 2001 From: Roman <72063601+folix-01@users.noreply.github.com> Date: Fri, 8 Sep 2023 15:00:23 +0200 Subject: [PATCH] Update upgrades.py --- src/design/plone/policy/upgrades.py | 33 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/design/plone/policy/upgrades.py b/src/design/plone/policy/upgrades.py index a2f2b6c..0032f49 100644 --- a/src/design/plone/policy/upgrades.py +++ b/src/design/plone/policy/upgrades.py @@ -243,7 +243,7 @@ def to_2010(context): settings.custom_attributes = settings.custom_attributes + ["data-element"] -def to_2022(context): # noqa +def to_2022(context): for brain in api.portal.get_tool("portal_catalog")(): item = aq_base(brain.getObject()) @@ -251,7 +251,7 @@ def to_2022(context): # noqa for name, field in getFields(schema).items(): if name == "blocks": logger.info( - f"[3100 - 3101] Deleting twitter blocks if exist from {'/'.join(item.getPhysicalPath())}" + f"[2021 - 2022] Deleting twitter blocks if exist from {'/'.join(item.getPhysicalPath())}" ) twitter_block_uids = [] @@ -286,22 +286,25 @@ def to_2022(context): # noqa if blocks: logger.info( - f"[3100 - 3101] Deleting twitter blocks if exist from {'/'.join(item.getPhysicalPath())}" + f"[2021 - 2022] Deleting twitter blocks if exist from {'/'.join(item.getPhysicalPath())}" ) + twitter_block_uids = [] - blocks = deepcopy(item.blocks) - blocks_layout = deepcopy(getattr(item, "blocks_layout", {})) + blocks = deepcopy(getattr(item, "blocks", None)) + + blocks_layout = deepcopy(getattr(item, "blocks_layout", None)) - for key, block in deepcopy(blocks).items(): - if block.get("@type", "") == "twitter_posts": - twitter_block_uids.append(key) - del blocks[key] + if blocks and blocks_layout: + for key, block in deepcopy(blocks).items(): + if block.get("@type", "") == "twitter_posts": + twitter_block_uids.append(key) + del blocks[key] - for block_uid in [*item.blocks_layout.get("items", [])]: - if block_uid in twitter_block_uids: - blocks_layout["items"].remove(block_uid) + for block_uid in [*item.blocks_layout.get("items", [])]: + if block_uid in twitter_block_uids: + blocks_layout["items"].remove(block_uid) - item.blocks = blocks + item.blocks = blocks - if blocks_layout: - item.blocks_layout = blocks_layout + if blocks_layout: + item.blocks_layout = blocks_layout