Skip to content

Commit

Permalink
Merge branch 'main' into cekk_remove_eea_api_taxonomy
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk authored Dec 3, 2024
2 parents 4f58c90 + 7e752cc commit f48ccc3
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 4 deletions.
18 changes: 17 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
Changelog
=========

6.2.23 (unreleased)
6.2.25 (unreleased)
-------------------

- Do not use eea.api.taxonomy because it is deprecated.
We still leave it as dependency to not broke old sites before uninstall (made by an upgrade-step). It need to be removed later.
[cekk]


6.2.24 (2024-11-26)
-------------------

- Add fields end and recurrence on event summary serializer
[eikichi18]


6.2.23 (2024-11-22)
-------------------

- Override BandoView: in io-Comune we add new children on Folder Deepening content
and we need to proper handle it
[lucabel]
- update serializer for documento ct adding more information about modulo children
[lucabel]

6.2.22 (2024-10-30)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setup(
name="design.plone.contenttypes",
version="6.2.23.dev0",
version="6.2.25.dev0",
description="DesignItalia contenty types",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
105 changes: 105 additions & 0 deletions src/design/plone/contenttypes/browser/bando.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
"""
This is a customization for original view. in design.plone.contenttypes
we allow folder deepening to contain also Modulo CT and we need to
handle it properly
I know it would be better to refactor redturtle.bandi to make
retrieveContentsOfFolderDeepening smaller and have "mini" methods
to retrieve information. This will be done maybe in future
"""

from design.plone.contenttypes.behaviors.multi_file import IMultiFileSchema
from plone import api
from plone.restapi.interfaces import IFieldSerializer
from redturtle.bandi.browser.bando import BandoView as BaseBandoView
from redturtle.bandi.browser.bando import IBandoView
from zope.component import queryMultiAdapter
from zope.interface import implementer

try:
from plone.restapi.serializer.utils import uid_to_url
from plone.restapi.serializer.converters import json_compatible

HAS_PLONERESTAPI = True
except ImportError:
HAS_PLONERESTAPI = False


fields = [
"file_principale",
"formato_alternativo_1",
"formato_alternativo_2",
]


@implementer(IBandoView)
class BandoView(BaseBandoView):

def retrieveContentsOfFolderDeepening(self, path_dfolder):
"""Retrieves all objects contained in Folder Deppening"""

values = []
brains = self.context.portal_catalog(
path={"query": path_dfolder, "depth": 1},
sort_on="getObjPositionInParent",
)
siteid = api.portal.get().getId()
for brain in brains:
if not brain.getPath() == path_dfolder and not brain.exclude_from_nav:
effective = brain.effective
if effective.year() == 1969:
# content not yet published
effective = None
dictfields = dict(
title=brain.Title,
description=brain.Description,
url=brain.getURL(),
path=brain.getPath(),
effective=effective,
modified=brain.modified,
)
if brain.Type == "Link":
dictfields["url"] = brain.getRemoteUrl
# resolve /resolveuid/... to url
# XXX: ma qui non funziona perchè il path è /Plone/resolveuid/...
# mentre la regex di uid_to_url si aspetta /resolveuid/... o
# ../resolveuid/...
# dictfields["url"] = uid_to_url(dictfields["url"])
# XXX: bug di Link ? in remoteUrl per i link interni nei brain
# c'è il path completo (con /Plone) invece che una url
# probabilmente legato al fatto che i link ora sono creati via
# api e non da interfaccia Plone (?)
if dictfields["url"].startswith(f"/{siteid}"):
dictfields["url"] = dictfields["url"][len(siteid) + 1 :]
if HAS_PLONERESTAPI:
dictfields["url"] = uid_to_url(dictfields["url"])
elif brain.Type == "File":
obj_file = brain.getObject().file
if obj_file:
dictfields["url"] = (
f"{brain.getURL()}/@@download/file/{obj_file.filename}" # noqa E501
)
obj_size = obj_file.size
dictfields["filesize"] = self.getSizeString(obj_size)
elif brain.Type == "Modulo":
obj = brain.getObject()
for field in fields:
field_obj = IMultiFileSchema[field]
serializer = queryMultiAdapter(
(field_obj, obj, self.request), IFieldSerializer
)
value = serializer()
dictfields[field] = value

# else:
# dictfields["url"] = brain.getURL() + "/view"
dictfields["content-type"] = brain.mime_type
# icon = getMultiAdapter((self.context, self.request, obj), IContentIcon)
# dictfields['icon'] = icon.html_tag()
dictfields["type"] = brain.Type

if HAS_PLONERESTAPI:
dictfields = json_compatible(dictfields)
values.append(dictfields)

return values
10 changes: 10 additions & 0 deletions src/design/plone/contenttypes/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,15 @@
permission="zope2.View"
/>
</configure>
<configure package="redturtle.bandi.browser">
<browser:page
name="bando_view"
for="..interfaces.IBando"
class="design.plone.contenttypes.browser.bando.BandoView"
template="bando.pt"
permission="zope2.View"
layer="design.plone.contenttypes.interfaces.IDesignPloneContenttypesLayer"
/>
</configure>

</configure>
3 changes: 2 additions & 1 deletion src/design/plone/contenttypes/interfaces/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
"""Module where all interfaces, events and exceptions live."""
from redturtle.volto.interfaces import IRedturtleVoltoLayer
from redturtle.bandi.interfaces.browserlayer import IRedturtleBandiLayer
from zope.interface import Interface


class IDesignPloneContenttypesLayer(IRedturtleVoltoLayer):
class IDesignPloneContenttypesLayer(IRedturtleVoltoLayer, IRedturtleBandiLayer):
"""Marker interface that defines a browser layer."""


Expand Down
11 changes: 11 additions & 0 deletions src/design/plone/contenttypes/restapi/serializers/documento.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,16 @@ def __call__(self, version=None, include_items=True):
result = super(DocumentoSerializer, self).__call__(
version=version, include_items=include_items
)
# Una via alternativa era l'injection di fullobject nella request ma
# mi pare una cosa cattiva da fare
brain_moduli = [
x for x in self.context.getFolderContents() if x.portal_type == "Modulo"
]
result["moduli_del_documento"] = []
for brain in brain_moduli:
modulo = brain.getObject()
result["moduli_del_documento"].append(
getMultiAdapter((modulo, self.request), ISerializeToJson)()
)
result["servizi_collegati"] = self.get_services()
return result
2 changes: 2 additions & 0 deletions src/design/plone/contenttypes/restapi/serializers/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def __call__(self, force_all_metadata=False, force_images=False):

if self.context.portal_type == "Event":
res["start"] = json_compatible(self.context.start)
res["end"] = json_compatible(self.context.end)
res["recurrence"] = json_compatible(self.context.recurrence)

if "geolocation" in metadata_fields or self.show_all_metadata_fields:
# backward compatibility for some block templates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def __call__(self, force_images=True, **kwargs):

get_taxonomy_information("tipologia_organizzazione", self.context, data)

data["image_caption"] = getattr(self.context, "image_caption", None)
data["preview_caption"] = getattr(self.context, "preview_caption", None)
return data

def getGeolocation(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,5 @@ def test_event_summary(self):
resp = self.api_session.get(event1.absolute_url()).json()
subevent = [x for x in resp["items"] if x["@type"] == "Event"][0]
self.assertIn("start", subevent)
self.assertIn("end", subevent)
self.assertIn("recurrence", subevent)
2 changes: 1 addition & 1 deletion test-6.0.x.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ extends =
base.cfg

[versions]
collective.taxonomy =
collective.taxonomy =

0 comments on commit f48ccc3

Please sign in to comment.