Skip to content

Commit

Permalink
avoid frontend block serializers; just transport the raw data
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed Apr 17, 2024
1 parent 6228d33 commit 1070049
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/plone/exportimport/deserializers/blob.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
from plone.dexterity.interfaces import IDexterityContent
from plone.exportimport import settings
from plone.exportimport.interfaces import IExportImportBlobsMarker
from plone.exportimport.interfaces import IExportImportRequestMarker
from plone.exportimport.utils import path as path_utils
from plone.namedfile.interfaces import INamedField
from plone.restapi.deserializer.dxfields import DefaultFieldDeserializer
Expand All @@ -24,7 +24,7 @@ def load_blob(path: str) -> bytes:
return codecs.decode(data, "base64")


@adapter(INamedField, IDexterityContent, IExportImportBlobsMarker)
@adapter(INamedField, IDexterityContent, IExportImportRequestMarker)
@implementer(IFieldDeserializer)
class ExportImportNamedFieldDeserializer(DefaultFieldDeserializer):
def __call__(self, value):
Expand Down
15 changes: 15 additions & 0 deletions src/plone/exportimport/deserializers/blocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from plone.exportimport.interfaces import IExportImportRequestMarker
from plone.restapi.behaviors import IBlocks
from plone.restapi.deserializer.dxfields import DefaultFieldDeserializer
from plone.restapi.interfaces import IFieldDeserializer
from plone.schema import IJSONField
from zope.component import adapter
from zope.interface import implementer


@implementer(IFieldDeserializer)
@adapter(IJSONField, IBlocks, IExportImportRequestMarker)
class ExportImportBlocksDeserializer(DefaultFieldDeserializer):
"""We skip the subscribers that deserialize the blocks from the frontend.
We only need the raw data.
"""
1 change: 1 addition & 0 deletions src/plone/exportimport/deserializers/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<configure xmlns="http://namespaces.zope.org/zope">
<adapter factory=".blob.ExportImportNamedFieldDeserializer" />
<adapter factory=".blocks.ExportImportBlocksDeserializer" />
</configure>
4 changes: 2 additions & 2 deletions src/plone/exportimport/exporters/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from plone.exportimport import logger
from plone.exportimport import settings
from plone.exportimport import types
from plone.exportimport.interfaces import IExportImportBlobsMarker
from plone.exportimport.interfaces import IExportImportRequestMarker
from plone.exportimport.utils import content as content_utils
from plone.exportimport.utils import request_provides
from typing import Callable
Expand Down Expand Up @@ -130,7 +130,7 @@ def dump_metadata(self) -> Path:
def dump(self) -> List[Path]:
"""Serialize contents and dump them to disk."""
paths = []
with request_provides(self.request, IExportImportBlobsMarker):
with request_provides(self.request, IExportImportRequestMarker):
for obj in self.all_objects():
path = self.dump_one(obj)
if path:
Expand Down
4 changes: 2 additions & 2 deletions src/plone/exportimport/importers/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from plone.exportimport import logger
from plone.exportimport import settings
from plone.exportimport import types
from plone.exportimport.interfaces import IExportImportBlobsMarker
from plone.exportimport.interfaces import IExportImportRequestMarker
from plone.exportimport.utils import content as content_utils
from plone.exportimport.utils import request_provides
from typing import Callable
Expand Down Expand Up @@ -93,7 +93,7 @@ def construct(self, item: dict) -> DexterityContent:
def do_import(self) -> str:
objs = []
modified = set()
with request_provides(self.request, IExportImportBlobsMarker):
with request_provides(self.request, IExportImportRequestMarker):
for index, item in enumerate(self.all_objects(), start=1):
obj = self.construct(item)
obj_path = "/".join(obj.getPhysicalPath())
Expand Down
2 changes: 1 addition & 1 deletion src/plone/exportimport/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from zope.interface import Interface


class IExportImportBlobsMarker(Interface):
class IExportImportRequestMarker(Interface):
"""A marker interface to override default serializers."""


Expand Down
10 changes: 5 additions & 5 deletions src/plone/exportimport/serializers/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from plone.exportimport import logger
from plone.exportimport import settings
from plone.exportimport import types
from plone.exportimport.interfaces import IExportImportBlobsMarker
from plone.exportimport.interfaces import IExportImportRequestMarker
from plone.exportimport.utils import content as content_utils
from plone.exportimport.utils import path as path_utils
from plone.namedfile.interfaces import INamedBlobFileField
Expand All @@ -19,7 +19,7 @@
from zope.interface import implementer


@adapter(INamedBlobFileField, IDexterityContent, IExportImportBlobsMarker)
@adapter(INamedBlobFileField, IDexterityContent, IExportImportRequestMarker)
@implementer(IFieldSerializer)
class ExportImportFileFieldSerializer(DefaultFieldSerializer):
def __call__(self):
Expand All @@ -37,13 +37,13 @@ def __call__(self):
return json_compatible(result)


@adapter(INamedFileField, IDexterityContent, IExportImportBlobsMarker)
@adapter(INamedFileField, IDexterityContent, IExportImportRequestMarker)
@implementer(IFieldSerializer)
class ExportImportSimpleFileFieldSerializer(ExportImportFileFieldSerializer):
"""Same as above but less specific field interface"""


@adapter(INamedBlobImageField, IDexterityContent, IExportImportBlobsMarker)
@adapter(INamedBlobImageField, IDexterityContent, IExportImportRequestMarker)
@implementer(IFieldSerializer)
class ExportImportImageFieldSerializer(DefaultFieldSerializer):
def __call__(self):
Expand All @@ -65,7 +65,7 @@ def __call__(self):
return json_compatible(result)


@adapter(INamedImageField, IDexterityContent, IExportImportBlobsMarker)
@adapter(INamedImageField, IDexterityContent, IExportImportRequestMarker)
@implementer(IFieldSerializer)
class ExportImportSimpleImageFieldSerializer(ExportImportImageFieldSerializer):
"""Same as above but less specific field interface"""
Expand Down
15 changes: 15 additions & 0 deletions src/plone/exportimport/serializers/blocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from plone.exportimport.interfaces import IExportImportRequestMarker
from plone.restapi.behaviors import IBlocks
from plone.restapi.interfaces import IFieldSerializer
from plone.restapi.serializer.dxfields import DefaultFieldSerializer
from plone.schema import IJSONField
from zope.component import adapter
from zope.interface import implementer


@adapter(IJSONField, IBlocks, IExportImportRequestMarker)
@implementer(IFieldSerializer)
class ExportImportBlocksSerializer(DefaultFieldSerializer):
"""We skip the subscribers that serialize the blocks for the frontend.
We only need the raw data.
"""
2 changes: 1 addition & 1 deletion src/plone/exportimport/serializers/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<adapter factory=".blob.ExportImportImageFieldSerializer" />
<adapter factory=".blob.ExportImportSimpleFileFieldSerializer" />
<adapter factory=".blob.ExportImportSimpleImageFieldSerializer" />

<adapter factory=".blocks.ExportImportBlocksSerializer" />
</configure>

0 comments on commit 1070049

Please sign in to comment.