diff --git a/CHANGES.rst b/CHANGES.rst index 2cf8e48d..388d1366 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,7 +1,7 @@ Changelog ========= -6.2.23 (unreleased) +6.2.25 (unreleased) ------------------- - Do not use eea.api.taxonomy because it is deprecated. @@ -9,6 +9,22 @@ Changelog [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) ------------------- diff --git a/setup.py b/setup.py index 0b4ee34a..ce376ee6 100644 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/src/design/plone/contenttypes/browser/bando.py b/src/design/plone/contenttypes/browser/bando.py new file mode 100644 index 00000000..8af4dc43 --- /dev/null +++ b/src/design/plone/contenttypes/browser/bando.py @@ -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 diff --git a/src/design/plone/contenttypes/browser/configure.zcml b/src/design/plone/contenttypes/browser/configure.zcml index 96ee97ae..55745eed 100644 --- a/src/design/plone/contenttypes/browser/configure.zcml +++ b/src/design/plone/contenttypes/browser/configure.zcml @@ -46,5 +46,15 @@ permission="zope2.View" /> + + + diff --git a/src/design/plone/contenttypes/interfaces/__init__.py b/src/design/plone/contenttypes/interfaces/__init__.py index 56b75e8c..6db4c337 100644 --- a/src/design/plone/contenttypes/interfaces/__init__.py +++ b/src/design/plone/contenttypes/interfaces/__init__.py @@ -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.""" diff --git a/src/design/plone/contenttypes/restapi/serializers/documento.py b/src/design/plone/contenttypes/restapi/serializers/documento.py index 5a47cca8..9a2a4fd2 100644 --- a/src/design/plone/contenttypes/restapi/serializers/documento.py +++ b/src/design/plone/contenttypes/restapi/serializers/documento.py @@ -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 diff --git a/src/design/plone/contenttypes/restapi/serializers/summary.py b/src/design/plone/contenttypes/restapi/serializers/summary.py index 8060f9f1..2fee4983 100644 --- a/src/design/plone/contenttypes/restapi/serializers/summary.py +++ b/src/design/plone/contenttypes/restapi/serializers/summary.py @@ -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 diff --git a/src/design/plone/contenttypes/restapi/serializers/unita_organizzativa.py b/src/design/plone/contenttypes/restapi/serializers/unita_organizzativa.py index 04b3e5cc..743a92b7 100644 --- a/src/design/plone/contenttypes/restapi/serializers/unita_organizzativa.py +++ b/src/design/plone/contenttypes/restapi/serializers/unita_organizzativa.py @@ -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): diff --git a/src/design/plone/contenttypes/tests/test_summary_serializer.py b/src/design/plone/contenttypes/tests/test_summary_serializer.py index 66696a83..1452b994 100644 --- a/src/design/plone/contenttypes/tests/test_summary_serializer.py +++ b/src/design/plone/contenttypes/tests/test_summary_serializer.py @@ -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) diff --git a/test-6.0.x.cfg b/test-6.0.x.cfg index 0060e5fa..5a178710 100644 --- a/test-6.0.x.cfg +++ b/test-6.0.x.cfg @@ -6,4 +6,4 @@ extends = base.cfg [versions] -collective.taxonomy = +collective.taxonomy = \ No newline at end of file