From 940e4da7ea09d3ff6e40ce37507967cad60e59d6 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Sat, 13 Apr 2024 22:26:03 +0200 Subject: [PATCH] upgrade step --- .isort.cfg | 2 + .../profiles/default/metadata.xml | 2 +- .../contenttypes/upgrades/configure.zcml | 9 +++ .../plone/contenttypes/upgrades/to_7300.py | 55 +++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 .isort.cfg create mode 100644 src/design/plone/contenttypes/upgrades/to_7300.py diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 00000000..0b113d2c --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,2 @@ +[settings] +profile = plone diff --git a/src/design/plone/contenttypes/profiles/default/metadata.xml b/src/design/plone/contenttypes/profiles/default/metadata.xml index f6ba447d..66b31642 100644 --- a/src/design/plone/contenttypes/profiles/default/metadata.xml +++ b/src/design/plone/contenttypes/profiles/default/metadata.xml @@ -1,6 +1,6 @@ - 7200 + 7300 profile-redturtle.bandi:default profile-collective.venue:default diff --git a/src/design/plone/contenttypes/upgrades/configure.zcml b/src/design/plone/contenttypes/upgrades/configure.zcml index 7d4fbff9..c3b93f12 100644 --- a/src/design/plone/contenttypes/upgrades/configure.zcml +++ b/src/design/plone/contenttypes/upgrades/configure.zcml @@ -848,4 +848,13 @@ handler=".upgrades.to_7200" /> + + + diff --git a/src/design/plone/contenttypes/upgrades/to_7300.py b/src/design/plone/contenttypes/upgrades/to_7300.py new file mode 100644 index 00000000..d9531e4d --- /dev/null +++ b/src/design/plone/contenttypes/upgrades/to_7300.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +from .upgrades import logger +from Acquisition import aq_base +from plone import api +from plone.namedfile import file + + +def to_7300(context): + + mapping = { + # portal_type + "Documento Personale": { + # field: "type" + "immagine": "image", + "pratica_associata": "file", + }, + "Messaggio": { + "documenti _allegati": "file", + }, + "Persona": { + "foto_persona": "image", + }, + "RicevutaPagamento": { + "stampa_ricevuta": "file", + "pratica_associata": "file", + "allegato": "file", + }, + } + + mapping_types = { + "image": (file.NamedImage, file.NamedBlobImage), + "file": (file.NamedFile, file.NamedBlobFile), + } + + for portal_type, fields in mapping.items(): + brains = api.content.find(unrestricted=True, portal_type=portal_type) + logger.info("Updating fields for %s %s objects", portal_type, len(brains)) + for brain in brains: + obj = aq_base(brain.getObject()) + for fieldname, _type in fields.items(): + value = getattr(obj, fieldname, None) + # if value: + # import pdb; pdb.set_trace() + if value and isinstance(value, mapping_types[_type][0]): + logger.info("Updated %s for %s", fieldname, brain.getPath()) + setattr( + obj, + fieldname, + mapping_types[_type][1]( + data=value.data, + contentType=value.contentType, + filename=value.filename, + ), + ) + logger.info("Finished updating fields")