Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix migrating bocks #241

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
1.12 (unreleased)
-----------------

- Nothing changed yet.
- Fix migrating bocks to make Volto sites portable and support plone.distribution.
[pbauer, tlotze]


1.11 (2024-02-28)
Expand Down
2 changes: 2 additions & 0 deletions src/collective/exportimport/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@
<adapter factory=".serializer.CollectionFieldSerializer" />
<adapter factory=".serializer.ChoiceFieldSerializer" />
<adapter factory=".serializer.long_converter" />
<adapter factory=".serializer.ExportingBlocksJSONFieldSerializer" />

<!-- Deserializers -->
<adapter factory=".deserializer.RichTextFieldDeserializerWithoutUnescape" />
<adapter factory=".deserializer.PortletRichTextFieldDeserializer" />
<adapter factory=".deserializer.ImportingBlocksJSONFieldDeserializer" />

<browser:page
name="exportimport_links"
Expand Down
12 changes: 12 additions & 0 deletions src/collective/exportimport/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
from plone.app.textfield.value import RichTextValue
from plone.dexterity.interfaces import IDexterityContent
from plone.portlets.interfaces import IPortletAssignment
from plone.restapi.behaviors import IBlocks
from plone.restapi.deserializer.dxfields import DefaultFieldDeserializer
from plone.restapi.interfaces import IFieldDeserializer
from plone.restapi.interfaces import IFieldDeserializer
from plone.schema import IJSONField
from zope.component import adapter
from zope.interface import implementer

Expand All @@ -15,6 +18,7 @@ class RichTextFieldDeserializerWithoutUnescape(DefaultFieldDeserializer):
"""Override default RichTextFieldDeserializer without using html_parser.unescape().
Fixes https://github.com/collective/collective.exportimport/issues/99
"""

def __call__(self, value):
content_type = self.field.default_mime_type
encoding = "utf8"
Expand All @@ -38,3 +42,11 @@ def __call__(self, value):
@adapter(IRichText, IPortletAssignment, IMigrationMarker)
class PortletRichTextFieldDeserializer(RichTextFieldDeserializerWithoutUnescape):
pass


@implementer(IFieldDeserializer)
@adapter(IJSONField, IBlocks, IMigrationMarker)
class ImportingBlocksJSONFieldDeserializer(DefaultFieldDeserializer):
"""We skip the subscribers that deserialize the blocks from the frontend.
We only need the raw data.
"""
11 changes: 11 additions & 0 deletions src/collective/exportimport/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
from plone.dexterity.interfaces import IDexterityContent
from plone.namedfile.interfaces import INamedFileField, INamedBlobFileField
from plone.namedfile.interfaces import INamedImageField
from plone.restapi.behaviors import IBlocks
from plone.restapi.interfaces import IFieldSerializer
from plone.restapi.interfaces import IJsonCompatible
from plone.restapi.serializer.blocks import BlocksJSONFieldSerializer
from plone.restapi.serializer.converters import json_compatible
from plone.restapi.serializer.dxfields import DefaultFieldSerializer
from plone.schema import IJSONField
from Products.CMFCore.utils import getToolByName
from zope.component import adapter
from zope.component import getUtility
Expand Down Expand Up @@ -607,6 +610,14 @@ def __call__(self):
return json_compatible(result)


@adapter(IJSONField, IBlocks, IMigrationMarker)
@implementer(IFieldSerializer)
class ExportingBlocksJSONFieldSerializer(DefaultFieldSerializer):
"""We skip the subscribers that serialize the blocks for the frontend.
We only need the raw data.
"""


if six.PY2:

@adapter(long)
Expand Down
Loading