Skip to content

Commit 3fd983a

Browse files
Cartelle aggiuntive all'interno della persona (#305)
* update with structure creation * fix upgrade
1 parent ffedc45 commit 3fd983a

File tree

6 files changed

+79
-14
lines changed

6 files changed

+79
-14
lines changed

src/design/plone/contenttypes/events/common.py

+26-10
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@
163163
"title": "Altri documenti",
164164
"allowed_types": ("File", "Image", "Link"),
165165
},
166+
{
167+
"id": "dichiarazione-insussistenza-cause-di-inconferibilita-e-incompatibilita", # noqa
168+
"title": "Dichiarazione insussistenza cause di inconferibilità e"
169+
" incompatibilità",
170+
"allowed_types": ("File",),
171+
},
172+
{
173+
"id": "emolumenti-complessivi-percepiti-a-carico-della-finanza-pubblica", # noqa
174+
"title": "Emolumenti complessivi percepiti a carico della finanza"
175+
" pubblica",
176+
"allowed_types": ("File",),
177+
},
166178
],
167179
"allowed_types": [],
168180
},
@@ -207,16 +219,7 @@ def onModify(context, event):
207219
child.reindexObject(idxs=["parent"])
208220

209221

210-
def createSubfolders(context, event):
211-
"""
212-
Create subfolders structure based on a portal_type mapping
213-
"""
214-
if not IDesignPloneContenttypesLayer.providedBy(context.REQUEST):
215-
return
216-
217-
subfolders_mapping = SUBFOLDERS_MAPPING.get(context.portal_type, [])
218-
if not subfolders_mapping:
219-
return
222+
def createStructure(context, subfolders_mapping):
220223

221224
for mapping in subfolders_mapping.get("content", {}):
222225
if mapping["id"] not in context.keys():
@@ -251,3 +254,16 @@ def createSubfolders(context, event):
251254
constraints_context = ISelectableConstrainTypes(context)
252255
constraints_context.setConstrainTypesMode(1)
253256
constraints_context.setLocallyAllowedTypes(allowed_types)
257+
258+
259+
def createSubfolders(context, event):
260+
"""
261+
Create subfolders structure based on a portal_type mapping
262+
"""
263+
if not IDesignPloneContenttypesLayer.providedBy(context.REQUEST):
264+
return
265+
266+
subfolders_mapping = SUBFOLDERS_MAPPING.get(context.portal_type, [])
267+
if not subfolders_mapping:
268+
return
269+
createStructure(context, subfolders_mapping)

src/design/plone/contenttypes/indexers/events.py

-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,4 @@ def effectiveend(obj):
3636
for occurrence in list(occurrences):
3737
if occurrence.end > end:
3838
end = occurrence.end
39-
if obj.title:
40-
print(f"{obj.title} - {end}")
4139
return end

src/design/plone/contenttypes/profiles/default/metadata.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<metadata>
3-
<version>7313</version>
3+
<version>7314</version>
44
<dependencies>
55
<dependency>profile-redturtle.bandi:default</dependency>
66
<dependency>profile-collective.venue:default</dependency>

src/design/plone/contenttypes/tests/test_substructure_creation.py

+4
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ def test_persona_substructure_created(self):
222222
- variazione-situazione-patrimoniale" "altre-cariche
223223
- incarichi
224224
- altri-documenti
225+
- dichiarazione-insussistenza-cause-di-inconferibilita-e-incompatibilita
226+
- emolumenti-complessivi-percepiti-a-carico-della-finanza-pubblica
225227
"""
226228
item = api.content.create(
227229
container=self.portal,
@@ -241,6 +243,8 @@ def test_persona_substructure_created(self):
241243
"altre-cariche",
242244
"incarichi",
243245
"altri-documenti",
246+
"dichiarazione-insussistenza-cause-di-inconferibilita-e-incompatibilita",
247+
"emolumenti-complessivi-percepiti-a-carico-della-finanza-pubblica",
244248
],
245249
)
246250

src/design/plone/contenttypes/upgrades/configure.zcml

+7
Original file line numberDiff line numberDiff line change
@@ -948,4 +948,11 @@
948948
destination="7313"
949949
handler=".to_730x.to_7313"
950950
/>
951+
<genericsetup:upgradeStep
952+
title="Update Persona subfolder"
953+
profile="design.plone.contenttypes:default"
954+
source="7313"
955+
destination="7314"
956+
handler=".to_730x.to_7314"
957+
/>
951958
</configure>

src/design/plone/contenttypes/upgrades/to_730x.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from design.plone.contenttypes.utils import create_default_blocks
55
from plone import api
66
from Products.CMFPlone.interfaces import ISelectableConstrainTypes
7-
7+
from design.plone.contenttypes.events.common import createStructure
88
import logging
99
import transaction
1010

@@ -225,3 +225,43 @@ class extra:
225225
if i % 15 == 0:
226226
logger.info("Progress: {}/{}".format(i, tot))
227227
brain.getObject().reindexObject(idxs=["effectiveend"])
228+
229+
230+
def to_7314(context):
231+
logger.info("Add new folder to Persona CT")
232+
mapping1 = {
233+
"content": [
234+
{
235+
"id": "dichiarazione-insussistenza-cause-di-inconferibilita-e-incompatibilita", # noqa
236+
"title": "Dichiarazione insussistenza cause di inconferibilità e"
237+
" incompatibilità",
238+
"allowed_types": ("File",),
239+
},
240+
]
241+
}
242+
mapping2 = {
243+
"content": [
244+
{
245+
"id": "emolumenti-complessivi-percepiti-a-carico-della-finanza-pubblica", # noqa
246+
"title": "Emolumenti complessivi percepiti a carico della finanza"
247+
" pubblica",
248+
"allowed_types": ("File",),
249+
},
250+
]
251+
}
252+
pc = api.portal.get_tool(name="portal_catalog")
253+
brains = pc(portal_type="Persona")
254+
for brain in brains:
255+
persona = brain.getObject()
256+
if (
257+
"dichiarazione-insussistenza-cause-di-inconferibilita-e-incompatibilita"
258+
not in persona.keys()
259+
):
260+
createStructure(persona, mapping1)
261+
logger.info("Add dichiarazione insussistenza for {}".format(persona.title))
262+
if (
263+
"emolumenti-complessivi-percepiti-a-carico-della-finanza-pubblica"
264+
not in persona.keys()
265+
):
266+
createStructure(persona, mapping2)
267+
logger.info("Add emolumenti complessivi for {}".format(persona.title))

0 commit comments

Comments
 (0)