Skip to content

Commit

Permalink
standardize subfolders creation in events
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Mar 4, 2024
1 parent d4821fd commit 92ece11
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 437 deletions.
16 changes: 5 additions & 11 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand All @@ -20,7 +23,6 @@ Changelog
[eikichi18]



6.1.13 (2024-02-08)
-------------------

Expand All @@ -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]
Expand All @@ -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]

Expand Down
19 changes: 0 additions & 19 deletions src/design/plone/contenttypes/events/bando.py

This file was deleted.

169 changes: 169 additions & 0 deletions src/design/plone/contenttypes/events/common.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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")
56 changes: 5 additions & 51 deletions src/design/plone/contenttypes/events/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,6 @@
i18n_domain="design.plone.contenttypes"
>

<subscriber
for="design.plone.contenttypes.interfaces.pratica.IPratica
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".pratica.praticaCreateHandler"
/>
<subscriber
for="collective.venue.interfaces.IVenue
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".luogo.luogoCreateHandler"
/>
<subscriber
for="design.plone.contenttypes.interfaces.unita_organizzativa.IUnitaOrganizzativa
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".unita_organizzativa.unitaOrganizzativaCreateHandler"
/>
<subscriber
for="design.plone.contenttypes.interfaces.persona.IPersona
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".persona.personaCreateHandler"
/>
<subscriber
for="plone.event.interfaces.IEvent
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".evento.eventoCreateHandler"
/>
<subscriber
for="design.plone.contenttypes.interfaces.documento.IDocumento
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".documento.documentoCreateHandler"
/>
<subscriber
for="design.plone.contenttypes.interfaces.servizio.IServizio
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".servizio.servizioCreateHandler"
/>
<subscriber
for="plone.app.contenttypes.interfaces.INewsItem
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".notizie_e_comunicati_stampa.notiziaCreateHandler"
/>
<subscriber
for="design.plone.contenttypes.interfaces.pagina_argomento.IPaginaArgomento
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
Expand All @@ -55,16 +15,6 @@
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".document.documentCreateHandler"
/>
<subscriber
for="redturtle.bandi.interfaces.bando.IBando
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".bando.bandoCreateHandler"
/>
<subscriber
for="design.plone.contenttypes.interfaces.incarico.IIncarico
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".incarico.incaricoCreateHandler"
/>
<subscriber
for="design.plone.contenttypes.interfaces.incarico.IIncarico
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
Expand All @@ -76,5 +26,9 @@
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler=".common.onModify"
/>

<subscriber
for="plone.dexterity.interfaces.IDexterityContent
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".common.createSubfolders"
/>
</configure>
36 changes: 0 additions & 36 deletions src/design/plone/contenttypes/events/documento.py

This file was deleted.

Loading

0 comments on commit 92ece11

Please sign in to comment.