From 079462dcceff978600f68bcf98c092fe1699bfd9 Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 3 May 2024 15:18:20 +0200 Subject: [PATCH] Move to plone 6 0 11 (#260) ready to works with plone 6.0.11 and plone.restapi 9.6.1 --- CHANGES.rst | 6 ++- setup.py | 2 +- .../browser/utils/check_servizi.py | 27 +----------- .../contenttypes/indexers/pagina_argomento.py | 23 +++++++++- .../restapi/deserializers/documento.py | 27 +----------- .../restapi/deserializers/news.py | 27 +----------- .../restapi/deserializers/servizio.py | 27 +----------- .../deserializers/unitaorganizzativa.py | 28 +----------- .../restapi/deserializers/venue.py | 27 +----------- .../plone/contenttypes/upgrades/to_7300.py | 1 - src/design/plone/contenttypes/utils.py | 44 +++++++++++++++++++ test_plone60.cfg | 10 ++++- 12 files changed, 85 insertions(+), 164 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9910347b..51056e6e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,11 @@ Changelog 6.2.9 (unreleased) ------------------ -- Aggiunto la cartella "Altri Documenti" sulla persona +- Add this folder "Altri Documenti" under "Persona pubblica" + [lucabel] +- Code porting to work with both plone 6.0.10.x and 6.0.11 + due to some core egg update + Code porting to work with the new plone.restapi 9.6.1 version [lucabel] diff --git a/setup.py b/setup.py index ada821bd..c41b390d 100644 --- a/setup.py +++ b/setup.py @@ -64,7 +64,7 @@ "redturtle.volto>=5.0.0", "redturtle.bandi", "z3c.unconfigure", - "plone.restapi<9.6.1", + "plone.restapi", "eea.api.taxonomy", "openpyxl", "collective.volto.enhancedlinks", diff --git a/src/design/plone/contenttypes/browser/utils/check_servizi.py b/src/design/plone/contenttypes/browser/utils/check_servizi.py index 34f9e390..fc74b52a 100644 --- a/src/design/plone/contenttypes/browser/utils/check_servizi.py +++ b/src/design/plone/contenttypes/browser/utils/check_servizi.py @@ -1,15 +1,13 @@ # -*- coding: utf-8 -*- from DateTime import DateTime +from design.plone.contenttypes.utils import text_in_block from openpyxl import Workbook from openpyxl.styles import Alignment from openpyxl.styles import Font from openpyxl.styles import PatternFill from openpyxl.utils import get_column_letter from plone import api -from plone.restapi.behaviors import IBlocks -from plone.restapi.indexers import SearchableText_blocks from Products.Five import BrowserView -from zope.interface import implementer import io @@ -17,29 +15,6 @@ FLAG = '' -def text_in_block(blocks): - @implementer(IBlocks) - class FakeObject(object): - """ - We use a fake object to use SearchableText Indexer - """ - - def Subject(self): - return "" - - def __init__(self, blocks, blocks_layout): - self.blocks = blocks - self.blocks_layout = blocks_layout - self.id = "" - self.title = "" - self.description = "" - - if not blocks: - return None - fakeObj = FakeObject(blocks.get("blocks", ""), blocks.get("blocks_layout", "")) - return SearchableText_blocks(fakeObj)() - - class CheckServizi(BrowserView): cds = None diff --git a/src/design/plone/contenttypes/indexers/pagina_argomento.py b/src/design/plone/contenttypes/indexers/pagina_argomento.py index 839ad4a1..c07e06de 100644 --- a/src/design/plone/contenttypes/indexers/pagina_argomento.py +++ b/src/design/plone/contenttypes/indexers/pagina_argomento.py @@ -1,11 +1,24 @@ # -*- coding: utf-8 -*- from design.plone.contenttypes.interfaces.pagina_argomento import IPaginaArgomento from plone.app.dexterity.textindexer.interfaces import IDynamicTextIndexExtender -from plone.restapi.indexers import SearchableText_blocks from zope.component import adapter from zope.interface import implementer +HAVE_REST_API_PRE_961 = False + +try: + # plone 6.0.11 with last plone.restapi>9.6.0 + from plone.app.contenttypes.indexers import SearchableText + from plone.restapi.indexers import get_blocks_text + from plone.restapi.indexers import text_strip + +except ImportError: + # plone 6.0.10.1 with plone.restapi<9.6.1 + HAVE_REST_API_PRE_961 = True + from plone.restapi.indexers import SearchableText_blocks + + @adapter(IPaginaArgomento) @implementer(IDynamicTextIndexExtender) class SearchableTextExtender(object): @@ -14,4 +27,10 @@ def __init__(self, context): def __call__(self): """Extend the searchable text with blocks""" - return SearchableText_blocks(self.context)() + if HAVE_REST_API_PRE_961: + return SearchableText_blocks(self.context)() + else: + blocks_text = get_blocks_text(self.context) + std_text = SearchableText(self.context) + blocks_text.append(std_text) + return text_strip(blocks_text) diff --git a/src/design/plone/contenttypes/restapi/deserializers/documento.py b/src/design/plone/contenttypes/restapi/deserializers/documento.py index 40a6afa6..1114bc52 100644 --- a/src/design/plone/contenttypes/restapi/deserializers/documento.py +++ b/src/design/plone/contenttypes/restapi/deserializers/documento.py @@ -1,9 +1,8 @@ # -*- coding: utf-8 -*- from design.plone.contenttypes.interfaces.documento import IDocumento -from plone.restapi.behaviors import IBlocks +from design.plone.contenttypes.utils import text_in_block from plone.restapi.deserializer import json_body from plone.restapi.deserializer.dxcontent import DeserializeFromJson -from plone.restapi.indexers import SearchableText_blocks from plone.restapi.interfaces import IDeserializeFromJson from zExceptions import BadRequest from zope.component import adapter @@ -24,30 +23,6 @@ def new_error(message): return {"error": "ValidationError", "message": message} -def text_in_block(blocks): - @implementer(IBlocks) - class FakeObject(object): - """ - We use a fake object to use SearchableText Indexer - """ - - def Subject(self): - return "" - - def __init__(self, blocks, blocks_layout): - self.blocks = blocks - self.blocks_layout = blocks_layout - self.id = "" - self.title = "" - self.description = "" - - if not blocks: - return None - - fakeObj = FakeObject(blocks.get("blocks", ""), blocks.get("blocks_layout", "")) - return SearchableText_blocks(fakeObj)() - - @implementer(IDeserializeFromJson) @adapter(IDocumento, Interface) class DeserializeDocumentoFromJson(DeserializeFromJson): diff --git a/src/design/plone/contenttypes/restapi/deserializers/news.py b/src/design/plone/contenttypes/restapi/deserializers/news.py index 7fa62c4d..d07425f1 100644 --- a/src/design/plone/contenttypes/restapi/deserializers/news.py +++ b/src/design/plone/contenttypes/restapi/deserializers/news.py @@ -1,9 +1,8 @@ # -*- coding: utf-8 -*- +from design.plone.contenttypes.utils import text_in_block from plone.app.contenttypes.interfaces import INewsItem -from plone.restapi.behaviors import IBlocks from plone.restapi.deserializer import json_body from plone.restapi.deserializer.dxcontent import DeserializeFromJson -from plone.restapi.indexers import SearchableText_blocks from plone.restapi.interfaces import IDeserializeFromJson from zExceptions import BadRequest from zope.component import adapter @@ -23,30 +22,6 @@ def new_error(message): return {"error": "ValidationError", "message": message} -def text_in_block(blocks): - @implementer(IBlocks) - class FakeObject(object): - """ - We use a fake object to use SearchableText Indexer - """ - - def Subject(self): - return "" - - def __init__(self, blocks, blocks_layout): - self.blocks = blocks - self.blocks_layout = blocks_layout - self.id = "" - self.title = "" - self.description = "" - - if not blocks: - return None - - fakeObj = FakeObject(blocks.get("blocks", ""), blocks.get("blocks_layout", "")) - return SearchableText_blocks(fakeObj)() - - @implementer(IDeserializeFromJson) @adapter(INewsItem, Interface) class DeserializeNewsFromJson(DeserializeFromJson): diff --git a/src/design/plone/contenttypes/restapi/deserializers/servizio.py b/src/design/plone/contenttypes/restapi/deserializers/servizio.py index 8e05c076..f51b5a5c 100644 --- a/src/design/plone/contenttypes/restapi/deserializers/servizio.py +++ b/src/design/plone/contenttypes/restapi/deserializers/servizio.py @@ -1,9 +1,8 @@ # -*- coding: utf-8 -*- from design.plone.contenttypes.interfaces.servizio import IServizio -from plone.restapi.behaviors import IBlocks +from design.plone.contenttypes.utils import text_in_block from plone.restapi.deserializer import json_body from plone.restapi.deserializer.dxcontent import DeserializeFromJson -from plone.restapi.indexers import SearchableText_blocks from plone.restapi.interfaces import IDeserializeFromJson from zExceptions import BadRequest from zope.component import adapter @@ -27,30 +26,6 @@ def new_error(message): return {"error": "ValidationError", "message": message} -def text_in_block(blocks): - @implementer(IBlocks) - class FakeObject(object): - """ - We use a fake object to use SearchableText Indexer - """ - - def Subject(self): - return "" - - def __init__(self, blocks, blocks_layout): - self.blocks = blocks - self.blocks_layout = blocks_layout - self.id = "" - self.title = "" - self.description = "" - - if not blocks: - return None - - fakeObj = FakeObject(blocks.get("blocks", ""), blocks.get("blocks_layout", "")) - return SearchableText_blocks(fakeObj)() - - @implementer(IDeserializeFromJson) @adapter(IServizio, Interface) class DeserializeServizioFromJson(DeserializeFromJson): diff --git a/src/design/plone/contenttypes/restapi/deserializers/unitaorganizzativa.py b/src/design/plone/contenttypes/restapi/deserializers/unitaorganizzativa.py index 2f041cbb..10c80d88 100644 --- a/src/design/plone/contenttypes/restapi/deserializers/unitaorganizzativa.py +++ b/src/design/plone/contenttypes/restapi/deserializers/unitaorganizzativa.py @@ -1,9 +1,8 @@ # -*- coding: utf-8 -*- from design.plone.contenttypes.interfaces.unita_organizzativa import IUnitaOrganizzativa -from plone.restapi.behaviors import IBlocks +from design.plone.contenttypes.utils import text_in_block from plone.restapi.deserializer import json_body from plone.restapi.deserializer.dxcontent import DeserializeFromJson -from plone.restapi.indexers import SearchableText_blocks from plone.restapi.interfaces import IDeserializeFromJson from zExceptions import BadRequest from zope.component import adapter @@ -21,30 +20,6 @@ def new_error(message): return {"error": "ValidationError", "message": message} -def text_in_block(blocks): - @implementer(IBlocks) - class FakeObject(object): - """ - We use a fake object to use SearchableText Indexer - """ - - def Subject(self): - return "" - - def __init__(self, blocks, blocks_layout): - self.blocks = blocks - self.blocks_layout = blocks_layout - self.id = "" - self.title = "" - self.description = "" - - if not blocks: - return None - - fakeObj = FakeObject(blocks.get("blocks", ""), blocks.get("blocks_layout", "")) - return SearchableText_blocks(fakeObj)() - - @implementer(IDeserializeFromJson) @adapter(IUnitaOrganizzativa, Interface) class DeserializeUnitaOrganizzativaFromJson(DeserializeFromJson): @@ -58,7 +33,6 @@ def __call__( is_post = method == "POST" is_patch = method == "PATCH" errors = [] - if list(data.keys()) != ["ordering"]: title = data.get("title") description = data.get("description") diff --git a/src/design/plone/contenttypes/restapi/deserializers/venue.py b/src/design/plone/contenttypes/restapi/deserializers/venue.py index 96eb9186..92395ef9 100644 --- a/src/design/plone/contenttypes/restapi/deserializers/venue.py +++ b/src/design/plone/contenttypes/restapi/deserializers/venue.py @@ -1,9 +1,8 @@ # -*- coding: utf-8 -*- from collective.venue.interfaces import IVenue -from plone.restapi.behaviors import IBlocks +from design.plone.contenttypes.utils import text_in_block from plone.restapi.deserializer import json_body from plone.restapi.deserializer.dxcontent import DeserializeFromJson -from plone.restapi.indexers import SearchableText_blocks from plone.restapi.interfaces import IDeserializeFromJson from zExceptions import BadRequest from zope.component import adapter @@ -21,30 +20,6 @@ def new_error(message): return {"error": "ValidationError", "message": message} -def text_in_block(blocks): - @implementer(IBlocks) - class FakeObject(object): - """ - We use a fake object to use SearchableText Indexer - """ - - def Subject(self): - return "" - - def __init__(self, blocks, blocks_layout): - self.blocks = blocks - self.blocks_layout = blocks_layout - self.id = "" - self.title = "" - self.description = "" - - if not blocks: - return None - - fakeObj = FakeObject(blocks.get("blocks", ""), blocks.get("blocks_layout", "")) - return SearchableText_blocks(fakeObj)() - - @implementer(IDeserializeFromJson) @adapter(IVenue, Interface) class DeserializeLuogoFromJson(DeserializeFromJson): diff --git a/src/design/plone/contenttypes/upgrades/to_7300.py b/src/design/plone/contenttypes/upgrades/to_7300.py index ba010d21..32b5573f 100644 --- a/src/design/plone/contenttypes/upgrades/to_7300.py +++ b/src/design/plone/contenttypes/upgrades/to_7300.py @@ -6,7 +6,6 @@ def to_7300(context): - mapping = { # portal_type "Documento Personale": { diff --git a/src/design/plone/contenttypes/utils.py b/src/design/plone/contenttypes/utils.py index 734e19b8..2cda35eb 100644 --- a/src/design/plone/contenttypes/utils.py +++ b/src/design/plone/contenttypes/utils.py @@ -1,13 +1,28 @@ # -*- coding: utf-8 -*- from design.plone.contenttypes.controlpanels.settings import IDesignPloneSettings from plone import api +from plone.restapi.behaviors import IBlocks from uuid import uuid4 +from zope.interface import implementer import json import logging import six +HAVE_REST_API_PRE_961 = False + +try: + # plone 6.0.11 with last plone.restapi>9.6.0 + from plone.restapi.indexers import get_blocks_text + from plone.restapi.indexers import text_strip + +except ImportError: + # plone 6.0.10.1 with plone.restapi<9.6.1 + HAVE_REST_API_PRE_961 = True + from plone.restapi.indexers import SearchableText_blocks + + logger = logging.getLogger(__name__) @@ -32,3 +47,32 @@ def create_default_blocks(context): title_uuid = str(uuid4()) context.blocks = {title_uuid: {"@type": "title"}} context.blocks_layout = {"items": [title_uuid]} + + +def text_in_block(blocks): + @implementer(IBlocks) + class FakeObject(object): + """ + We use a fake object to use SearchableText Indexer + """ + + def Subject(self): + return "" + + def __init__(self, blocks, blocks_layout): + self.blocks = blocks + self.blocks_layout = blocks_layout + self.id = "" + self.title = "" + self.description = "" + + if not blocks: + return None + + fakeObj = FakeObject(blocks.get("blocks", ""), blocks.get("blocks_layout", "")) + + if HAVE_REST_API_PRE_961: + return SearchableText_blocks(fakeObj)() + else: + blocks_text = get_blocks_text(fakeObj) + return text_strip(blocks_text) diff --git a/test_plone60.cfg b/test_plone60.cfg index 59e99e0e..60840265 100644 --- a/test_plone60.cfg +++ b/test_plone60.cfg @@ -4,7 +4,6 @@ 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 @@ -68,4 +67,11 @@ webencodings = 0.5.1 # Plone==6.0.10 # collective.volto.blocksfield==2.0.0 # redturtle.bandi==1.4.3 -plone.restapi = 9.6.0 + +# Added by buildout at 2024-05-02 17:26:10.555785 + +# Required by: +# Plone==6.0.11 +# collective.volto.blocksfield==2.0.0 +# design.plone.contenttypes==6.2.9.dev0 +plone.restapi = 9.6.1