Skip to content

Commit

Permalink
Merge pull request #241 from collective/fix_migrating_blocks
Browse files Browse the repository at this point in the history
Fix migrating bocks
  • Loading branch information
pbauer authored Mar 7, 2024
2 parents c091aa7 + 8b730b9 commit 4edf067
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
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

0 comments on commit 4edf067

Please sign in to comment.