From e7a5723754792aa20e74ab751e163813c2ac6d6a Mon Sep 17 00:00:00 2001 From: Luca Bellenghi Date: Fri, 12 Jan 2024 10:13:59 +0100 Subject: [PATCH] add upgrade step for pdc_desc field --- CHANGES.rst | 2 ++ .../plone/contenttypes/upgrades/configure.zcml | 11 ++++++++++- src/design/plone/contenttypes/upgrades/upgrades.py | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 2bb4f441..9d4d57f7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,8 @@ Changelog - Added description to PDC fields [pnicolli] + Added upgrade step to update PDC fields description + [lucabel] 6.1.9 (2024-01-11) diff --git a/src/design/plone/contenttypes/upgrades/configure.zcml b/src/design/plone/contenttypes/upgrades/configure.zcml index 3cfeb960..e8fc5e60 100644 --- a/src/design/plone/contenttypes/upgrades/configure.zcml +++ b/src/design/plone/contenttypes/upgrades/configure.zcml @@ -794,5 +794,14 @@ handler=".upgrades.update_types" /> - + + + diff --git a/src/design/plone/contenttypes/upgrades/upgrades.py b/src/design/plone/contenttypes/upgrades/upgrades.py index 18ba85b1..6019d520 100644 --- a/src/design/plone/contenttypes/upgrades/upgrades.py +++ b/src/design/plone/contenttypes/upgrades/upgrades.py @@ -1559,3 +1559,17 @@ def has_empty_prezzo(value): "blocks_layout": {"items": [uid]}, } logger.info(f"Fixed {len(fixed)} Events.") + + +def update_pdc_with_pdc_desc(context): + brains = api.content.find(portal_type="PuntoDiContatto") + logger.info(f"Found {len(brains)} PuntoDiContatto content type") + for brain in brains: + pdc = brain.getObject() + value_punto_contatto = getattr(pdc, "value_punto_contatto", []) + if value_punto_contatto: + for v in value_punto_contatto: + if not v.get("pdc_desc", None): + v["pdc_desc"] = None + logger.info(f"Set pdc_desc for {pdc.absolute_url()}") + logger.info("Ends of update")