From 92ece11dd6d3851c48ad2f4a79028ccbbd1ffc3d Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Mon, 4 Mar 2024 15:39:20 +0100 Subject: [PATCH] standardize subfolders creation in events --- CHANGES.rst | 16 +- src/design/plone/contenttypes/events/bando.py | 19 -- .../plone/contenttypes/events/common.py | 169 ++++++++++++++++++ .../plone/contenttypes/events/configure.zcml | 56 +----- .../plone/contenttypes/events/documento.py | 36 ---- .../plone/contenttypes/events/evento.py | 88 --------- .../plone/contenttypes/events/incarico.py | 32 ---- src/design/plone/contenttypes/events/luogo.py | 30 ---- .../events/notizie_e_comunicati_stampa.py | 33 ---- .../plone/contenttypes/events/persona.py | 53 ------ .../plone/contenttypes/events/pratica.py | 20 --- .../plone/contenttypes/events/servizio.py | 29 --- .../events/unita_organizzativa.py | 35 ---- 13 files changed, 179 insertions(+), 437 deletions(-) delete mode 100644 src/design/plone/contenttypes/events/bando.py delete mode 100644 src/design/plone/contenttypes/events/documento.py delete mode 100644 src/design/plone/contenttypes/events/evento.py delete mode 100644 src/design/plone/contenttypes/events/luogo.py delete mode 100644 src/design/plone/contenttypes/events/notizie_e_comunicati_stampa.py delete mode 100644 src/design/plone/contenttypes/events/persona.py delete mode 100644 src/design/plone/contenttypes/events/pratica.py delete mode 100644 src/design/plone/contenttypes/events/servizio.py delete mode 100644 src/design/plone/contenttypes/events/unita_organizzativa.py diff --git a/CHANGES.rst b/CHANGES.rst index 8feb4863..0636fed2 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,10 @@ Changelog 6.1.15 (unreleased) ------------------- -- Fix in @scadenziario endpoint: return future events if afterToday criteria is set. +- Remove unused behavior (design.plone.contenttypes.behavior.geolocation_uo). + [cekk] +- Move id/title mapping for automatic created children (with events) in separate variables, + so they can be easily overrided. [cekk] @@ -20,7 +23,6 @@ Changelog [eikichi18] - 6.1.13 (2024-02-08) ------------------- @@ -43,13 +45,7 @@ Changelog - Fixed script to update pdc with description [eikichi18] -- Add collective.volto.enhancedlinks dependency (needed for slate integration). - [cekk] -- Add enhancedlinks infos in File field serializer. - [cekk] -- Add new flag in settings needed to choose to show or not auto-generated footer columns. - [cekk] -- Customize @navigation endpoint to expose also the new flag for frontend. +- Add getObjSize info in File field serializer. [cekk] - Add new flag in settings needed to choose to show or not auto-generated footer columns. [cekk] @@ -72,8 +68,6 @@ Changelog 6.1.9 (2024-01-11) ------------------ -- Do not show fieldsets with no visible fields in @types endpoint. - [cekk] - Add UID to UOJSONSummarySerializer [eikichi18] diff --git a/src/design/plone/contenttypes/events/bando.py b/src/design/plone/contenttypes/events/bando.py deleted file mode 100644 index 858b25a3..00000000 --- a/src/design/plone/contenttypes/events/bando.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -from plone import api - - -def bandoCreateHandler(bando, event): - """ """ - folders = [ - {"id": "documenti", "title": "Documenti"}, - {"id": "comunicazioni", "title": "Comunicazioni"}, - {"id": "esiti", "title": "Esiti"}, - ] - for mapping in folders: - if mapping["id"] not in bando: - api.content.create( - type="Bando Folder Deepening", - title=mapping["title"], - id=mapping["id"], - container=bando, - ) diff --git a/src/design/plone/contenttypes/events/common.py b/src/design/plone/contenttypes/events/common.py index 2fe82574..51b7c49c 100644 --- a/src/design/plone/contenttypes/events/common.py +++ b/src/design/plone/contenttypes/events/common.py @@ -1,4 +1,142 @@ # -*- coding: utf-8 -*- +from design.plone.contenttypes.interfaces import IDesignPloneContenttypesLayer +from design.plone.contenttypes.utils import create_default_blocks +from plone import api +from Products.CMFPlone.interfaces import ISelectableConstrainTypes + + +SUBFOLDERS_MAPPING = { + "Bando": [ + {"id": "documenti", "title": "Documenti", "type": "Bando Folder Deepening"}, + { + "id": "comunicazioni", + "title": "Comunicazioni", + "type": "Bando Folder Deepening", + }, + {"id": "esiti", "title": "Esiti", "type": "Bando Folder Deepening"}, + ], + "Documento": [ + { + "id": "multimedia", + "title": "Multimedia", + "type": "Document", + "allowed_types": ("Image",), + }, + ], + "Event": [ + { + "id": "immagini", + "title": "Immagini", + "allowed_types": ("Image", "Link"), + "publish": True, + }, + { + "id": "video", + "title": "Video", + "allowed_types": ("Link",), + "publish": True, + }, + { + "id": "sponsor_evento", + "title": "Sponsor Evento", + "allowed_types": ("Link",), + "publish": True, + }, + { + "id": "documenti", + "title": "Allegati", + "allowed_types": ("File",), + "publish": True, + }, + ], + "Incarico": [ + {"id": "compensi-file", "title": "Compensi", "allowed": ("File",)}, + { + "id": "importi-di-viaggio-e-o-servizi", + "title": "Importi di viaggio e/o servizi", + "allowed_types": ("File",), + }, + ], + "Venue": [ + { + "id": "multimedia", + "title": "Multimedia", + "type": "Folder", + "allowed_types": ( + "Image", + "Link", + ), + "publish": True, + } + ], + "News Item": [ + { + "id": "multimedia", + "title": "Multimedia", + "allowed_types": ( + "Image", + "Link", + ), + }, + { + "id": "documenti-allegati", + "title": "Documenti allegati", + "allowed_types": ( + "File", + "Image", + ), + }, + ], + "Persona": [ + { + "id": "foto-e-attivita-politica", + "title": "Foto e attività politica", + "allowed_types": ("Image",), + }, + { + "id": "curriculum-vitae", + "title": "Curriculum vitae", + "allowed_types": ("File",), + }, + { + "id": "situazione-patrimoniale", + "title": "Situazione patrimoniale", + "allowed_types": ("File",), + }, + { + "id": "dichiarazione-dei-redditi", + "title": "Dichiarazione dei redditi", + "allowed_types": ("File",), + }, + { + "id": "spese-elettorali", + "title": "Spese elettorali", + "allowed_types": ("File",), + }, + { + "id": "variazione-situazione-patrimoniale", + "title": "Variazione situazione patrimoniale", + "allowed_types": ("File",), + }, + {"id": "altre-cariche", "title": "Altre cariche", "allowed_types": ("File",)}, + {"id": "incarichi", "title": "Incarichi", "allowed_types": ("Incarico",)}, + ], + "Pratica": [ + { + "id": "allegati", + "title": "Allegati", + "type": "Folder", + "allowed_types": ("File",), + } + ], + "Servizio": [ + {"id": "modulistica", "title": "Modulistica", "contains": ("File", "Link")}, + {"id": "allegati", "title": "Allegati", "contains": ("File", "Link")}, + ], + "UnitaOrganizzativa": [ + {"id": "allegati", "title": "Allegati", "contains": ("File",)}, + ], +} def onModify(context, event): @@ -8,3 +146,34 @@ def onModify(context, event): ) or "IDublinCore.title" in getattr(description, "attributes", []): for child in context.listFolderContents(): child.reindexObject(idxs=["parent"]) + + +def createSubfolders(context, event): + """ + Create subfolders structure based on a portal_type mapping + """ + if not IDesignPloneContenttypesLayer.providedBy(context.REQUEST): + return + + subfolders_mapping = SUBFOLDERS_MAPPING.get(context.portal_type, []) + if not subfolders_mapping: + return + for mapping in subfolders_mapping: + if mapping["id"] not in context.keys(): + child = api.content.create( + container=context, + type=mapping.get("type", "Document"), + title=mapping["title"], + id=mapping["id"], + ) + create_default_blocks(context=child) + + # select constraints + if mapping.get("allowed_types", ()): + constraintsChild = ISelectableConstrainTypes(child) + constraintsChild.setConstrainTypesMode(1) + constraintsChild.setLocallyAllowedTypes(mapping["allowed_types"]) + + if mapping.get("publish", False): + with api.env.adopt_roles(["Reviewer"]): + api.content.transition(obj=child, transition="publish") diff --git a/src/design/plone/contenttypes/events/configure.zcml b/src/design/plone/contenttypes/events/configure.zcml index b5b62c8c..2752fbf2 100644 --- a/src/design/plone/contenttypes/events/configure.zcml +++ b/src/design/plone/contenttypes/events/configure.zcml @@ -5,46 +5,6 @@ i18n_domain="design.plone.contenttypes" > - - - - - - - - - - - + diff --git a/src/design/plone/contenttypes/events/documento.py b/src/design/plone/contenttypes/events/documento.py deleted file mode 100644 index e8cc971d..00000000 --- a/src/design/plone/contenttypes/events/documento.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -from design.plone.contenttypes.utils import create_default_blocks -from plone import api -from Products.CMFPlone.interfaces import ISelectableConstrainTypes - - -def documentoCreateHandler(documento, event): - """ - Complete content type Documento setup on added event, generating - missing folders, fields, etc. - - @param documento: Content item - - @param event: Event that triggers the method (onAdded event) - """ - if "multimedia" in documento.keys(): - # we are copying or moving it - return - - documentoConstraints = ISelectableConstrainTypes(documento) - documentoConstraints.setConstrainTypesMode(1) - documentoConstraints.setLocallyAllowedTypes(("Document",)) - - # create support folder - multimedia = api.content.create( - type="Document", title="Multimedia", container=documento - ) - create_default_blocks(context=multimedia) - - multimediaConstraints = ISelectableConstrainTypes(multimedia) - multimediaConstraints.setConstrainTypesMode(1) - multimediaConstraints.setLocallyAllowedTypes(("Image",)) - - documentoConstraints = ISelectableConstrainTypes(documento) - documentoConstraints.setConstrainTypesMode(1) - documentoConstraints.setLocallyAllowedTypes(("Modulo", "Link")) diff --git a/src/design/plone/contenttypes/events/evento.py b/src/design/plone/contenttypes/events/evento.py deleted file mode 100644 index 50173d1f..00000000 --- a/src/design/plone/contenttypes/events/evento.py +++ /dev/null @@ -1,88 +0,0 @@ -# -*- coding: utf-8 -*- -from design.plone.contenttypes.interfaces import IDesignPloneContenttypesLayer -from design.plone.contenttypes.utils import create_default_blocks -from plone import api -from Products.CMFPlone.interfaces import ISelectableConstrainTypes - - -GALLERIA_MAPPING = {"id": "immagini", "title": "Immagini"} - -DOCUMENTI_TITLE = "Allegati" - - -def eventoCreateHandler(evento, event): - """ - Complete content type evento setup on added event, generating - missing folders, fields, etc. - - @param evento: Content item - - @param event: Event that triggers the method (onAdded event) - """ - if not IDesignPloneContenttypesLayer.providedBy(evento.REQUEST): - return - if GALLERIA_MAPPING["id"] not in evento.keys(): - galleria = api.content.create( - container=evento, - type="Document", - title=GALLERIA_MAPPING["title"], - id=GALLERIA_MAPPING["id"], - ) - create_default_blocks(context=galleria) - - # select constraints - constraintsGalleria = ISelectableConstrainTypes(galleria) - constraintsGalleria.setConstrainTypesMode(1) - constraintsGalleria.setLocallyAllowedTypes(("Image", "Link")) - - with api.env.adopt_roles(["Reviewer"]): - api.content.transition(obj=galleria, transition="publish") - - if "video" not in evento.keys(): - galleria_video = api.content.create( - container=evento, - type="Document", - title="Video", - id="video", - ) - create_default_blocks(context=galleria_video) - - # select constraints - constraintsGalleriaVideo = ISelectableConstrainTypes(galleria_video) - constraintsGalleriaVideo.setConstrainTypesMode(1) - constraintsGalleriaVideo.setLocallyAllowedTypes(("Link",)) - - with api.env.adopt_roles(["Reviewer"]): - api.content.transition(obj=galleria_video, transition="publish") - - if "sponsor_evento" not in evento.keys(): - sponsor = api.content.create( - container=evento, - type="Document", - title="Sponsor Evento", - id="sponsor_evento", - ) - create_default_blocks(context=sponsor) - - constraintsSponsor = ISelectableConstrainTypes(sponsor) - constraintsSponsor.setConstrainTypesMode(1) - constraintsSponsor.setLocallyAllowedTypes(("Link",)) - - with api.env.adopt_roles(["Reviewer"]): - api.content.transition(obj=sponsor, transition="publish") - - if "documenti" not in evento.keys(): - documenti = api.content.create( - container=evento, - type="Document", - title=DOCUMENTI_TITLE, - id="documenti", - ) - create_default_blocks(context=documenti) - - constraintsDocumenti = ISelectableConstrainTypes(documenti) - constraintsDocumenti.setConstrainTypesMode(1) - constraintsDocumenti.setLocallyAllowedTypes(("File",)) - - with api.env.adopt_roles(["Reviewer"]): - api.content.transition(obj=documenti, transition="publish") diff --git a/src/design/plone/contenttypes/events/incarico.py b/src/design/plone/contenttypes/events/incarico.py index 6b077b49..34368b77 100644 --- a/src/design/plone/contenttypes/events/incarico.py +++ b/src/design/plone/contenttypes/events/incarico.py @@ -1,37 +1,5 @@ # -*- coding: utf-8 -*- -from design.plone.contenttypes.utils import create_default_blocks from plone import api -from Products.CMFPlone.interfaces import ISelectableConstrainTypes - - -def incaricoCreateHandler(incarico, event): - """ - Complete content type incarico setup on added event, generating - missing folders, fields, etc. - - @param incarico: Content item - - @param event: Event that triggers the method (onAdded event) - """ - - FOLDERS = [ - {"id": "compensi-file", "title": "Compensi", "contains": ("File",)}, - { - "id": "importi-di-viaggio-e-o-servizi", - "title": "Importi di viaggio e/o servizi", - "contains": ("File",), - }, - ] - for folder in FOLDERS: - if folder["id"] in incarico: - continue - suboject = api.content.create( - type="Document", id=folder["id"], title=folder["title"], container=incarico - ) - create_default_blocks(context=suboject) - subobjectConstraints = ISelectableConstrainTypes(suboject) - subobjectConstraints.setConstrainTypesMode(1) - subobjectConstraints.setLocallyAllowedTypes(folder["contains"]) def modify_incarico(obj, event): diff --git a/src/design/plone/contenttypes/events/luogo.py b/src/design/plone/contenttypes/events/luogo.py deleted file mode 100644 index 42bf0e47..00000000 --- a/src/design/plone/contenttypes/events/luogo.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: utf-8 -*- -from Products.CMFPlone.interfaces import ISelectableConstrainTypes -from Products.CMFPlone.utils import _createObjectByType - - -def luogoCreateHandler(luogo, event): - """ - Complete content type luogo setup on added event, generating - missing folders, fields, etc. - - @param luogo: Content item - - @param event: Event that triggers the method (onAdded event) - """ - folder_id = "multimedia" - if folder_id in luogo: - return - folder = _createObjectByType("Folder", luogo, "multimedia") - folder.title = "Multimedia" - folder.reindexObject(idxs=["Title"]) - constraints = ISelectableConstrainTypes(folder) - constraints.setConstrainTypesMode(1) - constraints.setLocallyAllowedTypes( - ( - "Image", - "Link", - ) - ) - - # non dovrebbe essere cancellabile diff --git a/src/design/plone/contenttypes/events/notizie_e_comunicati_stampa.py b/src/design/plone/contenttypes/events/notizie_e_comunicati_stampa.py deleted file mode 100644 index 053928e3..00000000 --- a/src/design/plone/contenttypes/events/notizie_e_comunicati_stampa.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -from design.plone.contenttypes.utils import create_default_blocks -from plone import api -from Products.CMFPlone.interfaces import ISelectableConstrainTypes - - -def notiziaCreateHandler(notizia, event): - """ - Complete content type notizia setup on added event, generating - missing folders, fields, etc. - - @param notizia: Content item - - @param event: Event that triggers the method (onAdded event) - """ - - if "multimedia" not in notizia.keys(): - multimedia = api.content.create( - type="Document", title="Multimedia", container=notizia - ) - create_default_blocks(context=multimedia) - constraintsMultimedia = ISelectableConstrainTypes(multimedia) - constraintsMultimedia.setConstrainTypesMode(1) - constraintsMultimedia.setLocallyAllowedTypes(("Link", "Image")) - - if "documenti-allegati" not in notizia.keys(): - documenti = api.content.create( - type="Document", title="Documenti allegati", container=notizia - ) - create_default_blocks(context=documenti) - constraintsDocumenti = ISelectableConstrainTypes(documenti) - constraintsDocumenti.setConstrainTypesMode(1) - constraintsDocumenti.setLocallyAllowedTypes(("File", "Image")) diff --git a/src/design/plone/contenttypes/events/persona.py b/src/design/plone/contenttypes/events/persona.py deleted file mode 100644 index e9aef428..00000000 --- a/src/design/plone/contenttypes/events/persona.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -from design.plone.contenttypes.utils import create_default_blocks -from plone import api -from Products.CMFPlone.interfaces import ISelectableConstrainTypes - -FOLDERS = [ - { - "id": "foto-e-attivita-politica", - "title": "Foto e attività politica", - "contains": ("Image",), - }, - {"id": "curriculum-vitae", "title": "Curriculum vitae", "contains": ("File",)}, - { - "id": "situazione-patrimoniale", - "title": "Situazione patrimoniale", - "contains": ("File",), - }, - { - "id": "dichiarazione-dei-redditi", - "title": "Dichiarazione dei redditi", - "contains": ("File",), - }, - {"id": "spese-elettorali", "title": "Spese elettorali", "contains": ("File",)}, - { - "id": "variazione-situazione-patrimoniale", - "title": "Variazione situazione patrimoniale", - "contains": ("File",), - }, - {"id": "altre-cariche", "title": "Altre cariche", "contains": ("File",)}, - {"id": "incarichi", "title": "Incarichi", "contains": ("Incarico",)}, -] - - -def personaCreateHandler(persona, event): - """ - Complete content type Persona setup on added event, generating - missing folders, fields, etc. - - @param persona: Content item - - @param event: Event that triggers the method (onAdded event) - """ - - for folder in FOLDERS: - if folder["id"] in persona: - continue - suboject = api.content.create( - type="Document", id=folder["id"], title=folder["title"], container=persona - ) - create_default_blocks(context=suboject) - subobjectConstraints = ISelectableConstrainTypes(suboject) - subobjectConstraints.setConstrainTypesMode(1) - subobjectConstraints.setLocallyAllowedTypes(folder["contains"]) diff --git a/src/design/plone/contenttypes/events/pratica.py b/src/design/plone/contenttypes/events/pratica.py deleted file mode 100644 index bf44dda7..00000000 --- a/src/design/plone/contenttypes/events/pratica.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -from plone import api -from Products.CMFPlone.interfaces import ISelectableConstrainTypes - - -def praticaCreateHandler(pratica, event): - """ - Complete content type Pratica setup on added event, generating - missing folders, fields, etc. - - @param pratica: Content item - - @param event: Event that triggers the method (onAdded event) - """ - - allegati = api.content.create(type="Folder", title="Allegati", container=pratica) - - allegatiConstraints = ISelectableConstrainTypes(allegati) - allegatiConstraints.setConstrainTypesMode(1) - allegatiConstraints.setLocallyAllowedTypes(("File",)) diff --git a/src/design/plone/contenttypes/events/servizio.py b/src/design/plone/contenttypes/events/servizio.py deleted file mode 100644 index 1a37f81e..00000000 --- a/src/design/plone/contenttypes/events/servizio.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- -from design.plone.contenttypes.utils import create_default_blocks -from plone import api -from Products.CMFPlone.interfaces import ISelectableConstrainTypes - - -def servizioCreateHandler(servizio, event): - """ - Complete content type Servizio setup on added event, generating - missing folders, fields, etc. - - @param servizio: Content item - - @param event: Event that triggers the method (onAdded event) - """ - - for folder in [ - {"id": "modulistica", "title": "Modulistica", "contains": ("File", "Link")}, - {"id": "allegati", "title": "Allegati", "contains": ("File", "Link")}, - ]: - if folder["id"] not in servizio.keys(): - child = api.content.create( - type="Document", title=folder["title"], container=servizio - ) - create_default_blocks(context=child) - - childConstraints = ISelectableConstrainTypes(child) - childConstraints.setConstrainTypesMode(1) - childConstraints.setLocallyAllowedTypes(folder["contains"]) diff --git a/src/design/plone/contenttypes/events/unita_organizzativa.py b/src/design/plone/contenttypes/events/unita_organizzativa.py deleted file mode 100644 index ec11a746..00000000 --- a/src/design/plone/contenttypes/events/unita_organizzativa.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- coding: utf-8 -*- -from design.plone.contenttypes.utils import create_default_blocks -from plone import api -from Products.CMFPlone.interfaces import ISelectableConstrainTypes - -import logging - - -logger = logging.getLogger(__name__) - - -def unitaOrganizzativaCreateHandler(unitaOrganizzativa, event): - """ - Complete content type UnitaOrganizzativa setup on added event, generating - missing folders, fields, etc. - - @param unitaOrganizzativa: Content item - - @param event: Event that triggers the method (onAdded event) - """ - if "allegati" in unitaOrganizzativa.keys(): - return - try: - allegati = api.content.create( - type="Document", title="Allegati", container=unitaOrganizzativa - ) - except AttributeError as e: - # problems with tests in design.plone.policy - logger.exception(e) - return - - create_default_blocks(context=allegati) - allegatiConstraints = ISelectableConstrainTypes(allegati) - allegatiConstraints.setConstrainTypesMode(1) - allegatiConstraints.setLocallyAllowedTypes(("File",))