Skip to content

Commit

Permalink
Handle cost with empty text block in previous upgrade-step (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk authored Oct 30, 2023
1 parent bd9d78b commit 103e065
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
6.0.21 (unreleased)
-------------------

- Nothing changed yet.
- Handle cost with empty text block in previous upgrade-step.
[cekk]


6.0.20 (2023-10-30)
Expand Down
13 changes: 12 additions & 1 deletion src/design/plone/contenttypes/upgrades/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,17 @@ def to_7011(context):


def to_7012(context):
def has_empty_prezzo(value):
if not value:
return True
if value == {"blocks": {}, "blocks_layout": {"items": []}}:
return True
blocks_layout = value.get("blocks_layout", {}).get("items", [])
blocks = list(value.get("blocks", {}).values())
if len(blocks_layout) == 1 and blocks[0] == {"@type": "text"}:
return True
return False

logger.info("Set default value in prezzo field because now is required.")

brains = api.content.find(portal_type=["Event"])
Expand All @@ -1518,7 +1529,7 @@ def to_7012(context):
logger.info("Progress: {}/{}".format(i, tot))
event = brain.getObject()
prezzo = getattr(event, "prezzo", None)
if not prezzo or prezzo == {"blocks": {}, "blocks_layout": {"items": []}}:
if has_empty_prezzo(value=prezzo):
fixed.append(brain.getPath())
uid = str(uuid4())
event.prezzo = {
Expand Down

0 comments on commit 103e065

Please sign in to comment.