Skip to content

Commit

Permalink
Update upgrades.py
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 authored Sep 8, 2023
1 parent 8f89807 commit d7e2d67
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/design/plone/policy/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ 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())

for schema in iterSchemata(item):
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 = []
Expand Down Expand Up @@ -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

0 comments on commit d7e2d67

Please sign in to comment.