Skip to content

Commit

Permalink
Altri allegati sulla persona (#259)
Browse files Browse the repository at this point in the history
* aggiunto la cartella altri allegati sulla persona
* add some fix in order to work with plone 6.0.11 and it's dependencies
  • Loading branch information
luca-bellenghi authored May 2, 2024
1 parent 99b6ba6 commit 5ff1087
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
6.2.9 (unreleased)
------------------

- Nothing changed yet.
- Aggiunto la cartella "Altri Documenti" sulla persona
[lucabel]


6.2.8 (2024-04-22)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"redturtle.volto>=5.0.0",
"redturtle.bandi",
"z3c.unconfigure",
"plone.restapi<9.6.1",
"eea.api.taxonomy",
"openpyxl",
"collective.volto.enhancedlinks",
Expand Down
5 changes: 5 additions & 0 deletions src/design/plone/contenttypes/events/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
},
{"id": "altre-cariche", "title": "Altre cariche", "allowed_types": ("File",)},
{"id": "incarichi", "title": "Incarichi", "allowed_types": ("Incarico",)},
{
"id": "altri-documenti",
"title": "Altri documenti",
"allowed_types": ("File", "Image", "Link"),
},
],
"Pratica": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<version>7300</version>
<version>7301</version>
<dependencies>
<dependency>profile-redturtle.bandi:default</dependency>
<dependency>profile-collective.venue:default</dependency>
Expand Down
10 changes: 8 additions & 2 deletions src/design/plone/contenttypes/restapi/serializers/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ def __call__(self, force_all_metadata=False, force_images=False):

if self.is_get_call():
res["has_children"] = self.has_children()

if force_images:
# TODO: verificare se non c'è il campo o se il campo è null/vuoto ?
if not res.get("image_scales") and not res.get("image_field"):
Expand All @@ -198,7 +197,14 @@ def __call__(self, force_all_metadata=False, force_images=False):
res["image_field"] = "preview_image"
elif "image" in scales:
res["image_field"] = "image"

# plone.app.contentlisting 3.0.5 sembra fissare un accessor che ci
# fa arrivare uno scale senza image_field.
# avremmo questo problema una volta passati a plone 6.0.11
elif res.get("image_scales") and not res.get("image_field"):
if "preview_image" in res["image_scales"]:
res["image_field"] = "preview_image"
elif "image" in res["image_scales"]:
res["image_field"] = "image"
return res

def has_children(self):
Expand Down
10 changes: 10 additions & 0 deletions src/design/plone/contenttypes/tests/test_substructure_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ def test_persona_substructure_created(self):
- spese-elettorali
- variazione-situazione-patrimoniale" "altre-cariche
- incarichi
- altri-documenti
"""
item = api.content.create(
container=self.portal,
Expand All @@ -239,6 +240,7 @@ def test_persona_substructure_created(self):
"variazione-situazione-patrimoniale",
"altre-cariche",
"incarichi",
"altri-documenti",
],
)

Expand Down Expand Up @@ -317,6 +319,14 @@ def test_persona_substructure_created(self):
self.assertEqual(item["incarichi"].locally_allowed_types, ("Incarico",))
self.assertTrue(item["incarichi"].exclude_from_search)

self.assertEqual(item["altri-documenti"].portal_type, "Document")
self.assertEqual(api.content.get_state(item["altri-documenti"]), "private")
self.assertEqual(item["altri-documenti"].constrain_types_mode, 1)
self.assertIn("File", item["altri-documenti"].locally_allowed_types)
self.assertIn("Link", item["altri-documenti"].locally_allowed_types)
self.assertIn("Image", item["altri-documenti"].locally_allowed_types)
self.assertTrue(item["altri-documenti"].exclude_from_search)

def test_servizio_substructure_created(self):
"""
Should have:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ def test_image_in_uo_serializer(self):
res = response.json()
uo_children = res["uo_children"][0]
self.assertEqual(uo_children["image_field"], None)
self.assertEqual(uo_children["image_scales"], None)
# Plone 6.0.10.1 due to a bug in plone.app.contentlisting (#64
# from github issue) return None
# Plone 6.0.11 upgrades plone.app.contentlisting to a version
# fixing the problem and the changing the return value to {}
self.assertIn(uo_children["image_scales"], (None, {}))

# now, add a preview image
filename = os.path.join(os.path.dirname(__file__), "example.png")
Expand Down
7 changes: 7 additions & 0 deletions src/design/plone/contenttypes/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -856,5 +856,12 @@
destination="7300"
handler=".to_7300.to_7300"
/>
<genericsetup:upgradeStep
title="Add new folder to persona ct"
profile="design.plone.contenttypes:default"
source="7300"
destination="7301"
handler=".to_730x.to_7301"
/>

</configure>
45 changes: 45 additions & 0 deletions src/design/plone/contenttypes/upgrades/to_730x.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- 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__)

DEFAULT_PROFILE = "profile-design.plone.contenttypes:default"


def to_7301(context):
brains = api.content.find(portal_type="Persona")
for brain in brains:
persona = brain.getObject()
FOLDER_ID = "altri-documenti"
if FOLDER_ID not in persona.keys():
child = api.content.create(
container=persona,
type="Document",
title="Altri documenti",
id=FOLDER_ID,
)
create_default_blocks(context=child)
else:
child = persona[FOLDER_ID]

child.exclude_from_search = True
child.reindexObject(idxs=["exclude_from_search"])
# select constraints
constraintsChild = ISelectableConstrainTypes(child)
constraintsChild.setConstrainTypesMode(1)
constraintsChild.setLocallyAllowedTypes(
(
"File",
"Image",
"Link",
)
)
if api.content.get_state(persona) == "published":
if api.content.get_state(child) != "published":
with api.env.adopt_roles(["Reviewer"]):
api.content.transition(obj=child, transition="publish")
1 change: 1 addition & 0 deletions test_plone60.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extends =
https://raw.github.com/collective/buildout.plonetest/master/test-6.0.x.cfg
https://raw.githubusercontent.com/collective/buildout.plonetest/master/qa.cfg
https://raw.githubusercontent.com/RedTurtle/iocomune-backend/main/versions.cfg
https://dist.plone.org/release/6.0.10.1/versions.cfg
base.cfg

update-versions-file = test_plone60.cfg
Expand Down

0 comments on commit 5ff1087

Please sign in to comment.