-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checkpoint - With BlocksObjectWidget
- Loading branch information
Showing
7 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from kitconcept.intranet.interfaces import IBrowserLayer | ||
from plone.restapi.behaviors import IBlocks | ||
from plone.restapi.blocks import iter_block_transform_handlers | ||
from plone.restapi.blocks import visit_blocks | ||
from plone.restapi.deserializer.dxfields import DefaultFieldDeserializer | ||
from plone.restapi.interfaces import IBlockFieldDeserializationTransformer | ||
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, IBrowserLayer) | ||
class BlocksJSONFieldDeserializer(DefaultFieldDeserializer): | ||
def __call__(self, value): | ||
value = super().__call__(value) | ||
|
||
if "blocks" in value: | ||
blocksValue = value["blocks"] | ||
else: | ||
blocksValue = value | ||
|
||
if self.field.getName() == "blocks" or "blocks" in value: | ||
for block in visit_blocks(self.context, blocksValue): | ||
new_block = block.copy() | ||
for handler in iter_block_transform_handlers( | ||
self.context, block, IBlockFieldDeserializationTransformer | ||
): | ||
new_block = handler(new_block) | ||
block.clear() | ||
block.update(new_block) | ||
return value |
10 changes: 10 additions & 0 deletions
10
backend/src/kitconcept/intranet/deserializers/configure.zcml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:i18n="http://namespaces.zope.org/i18n" | ||
xmlns:plone="http://namespaces.plone.org/plone" | ||
i18n_domain="kitconcept.intranet" | ||
> | ||
|
||
<adapter factory=".blocks.BlocksJSONFieldDeserializer" /> | ||
|
||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from kitconcept.intranet.interfaces import IBrowserLayer | ||
from plone.restapi.behaviors import IBlocks | ||
from plone.restapi.blocks import iter_block_transform_handlers | ||
from plone.restapi.blocks import visit_blocks | ||
from plone.restapi.interfaces import IBlockFieldSerializationTransformer | ||
from plone.restapi.interfaces import IFieldSerializer | ||
from plone.restapi.serializer.converters import json_compatible | ||
from plone.restapi.serializer.dxfields import DefaultFieldSerializer | ||
from plone.schema import IJSONField | ||
from zope.component import adapter | ||
from zope.interface import implementer | ||
|
||
import copy | ||
|
||
|
||
@adapter(IJSONField, IBlocks, IBrowserLayer) | ||
@implementer(IFieldSerializer) | ||
class BlocksJSONFieldSerializer(DefaultFieldSerializer): | ||
def __call__(self): | ||
value = copy.deepcopy(self.get_value()) | ||
|
||
if "blocks" in value: | ||
blocksValue = value["blocks"] | ||
else: | ||
blocksValue = value | ||
|
||
if self.field.getName() == "blocks" or "blocks" in value: | ||
for block in visit_blocks(self.context, blocksValue): | ||
new_block = block.copy() | ||
for handler in iter_block_transform_handlers( | ||
self.context, block, IBlockFieldSerializationTransformer | ||
): | ||
new_block = handler(new_block) | ||
block.clear() | ||
block.update(new_block) | ||
return json_compatible(value) |
10 changes: 10 additions & 0 deletions
10
backend/src/kitconcept/intranet/serializers/configure.zcml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:i18n="http://namespaces.zope.org/i18n" | ||
xmlns:plone="http://namespaces.plone.org/plone" | ||
i18n_domain="kitconcept.intranet" | ||
> | ||
|
||
<adapter factory=".blocks.BlocksJSONFieldSerializer" /> | ||
|
||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters