Skip to content

Commit

Permalink
Fix migrating bocks by bypassing the frontend-specific modifiers when…
Browse files Browse the repository at this point in the history
… serializing and deserializing blocks
  • Loading branch information
pbauer committed Mar 7, 2024
1 parent c091aa7 commit 7a15322
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
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 7a15322

Please sign in to comment.