-
Notifications
You must be signed in to change notification settings - Fork 2
Added custom serializer for table variation #311
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
Merged
+71
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
59 changes: 59 additions & 0 deletions
59
src/design/plone/contenttypes/restapi/serializers/tablevariation.py
This file contains hidden or 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,59 @@ | ||
| from plone import api | ||
| from plone.restapi.behaviors import IBlocks | ||
| from plone.restapi.interfaces import IBlockFieldSerializationTransformer | ||
| from plone.restapi.types.utils import get_info_for_type | ||
| from zope.component import adapter | ||
| from zope.component import queryMultiAdapter | ||
| from zope.interface import implementer | ||
| from zope.publisher.interfaces.browser import IBrowserRequest | ||
|
|
||
| import logging | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @implementer(IBlockFieldSerializationTransformer) | ||
| @adapter(IBlocks, IBrowserRequest) | ||
| class SearchTableVariationBlockSerialize: | ||
| order = 100 | ||
| block_type = "search" | ||
| value_field = "listingBodyTemplate" | ||
|
|
||
| def __init__(self, context, request): | ||
| self.context = context | ||
| self.request = request | ||
|
|
||
| def _get_schema(self, portal_type): | ||
| dtool = queryMultiAdapter( | ||
| (api.portal.get(), self.request), name="dexterity-types" | ||
| ) | ||
| try: | ||
| dtype = dtool.publishTraverse(self.request, portal_type) | ||
| except KeyError: | ||
| logger.warning(f"KeyError: portal_type '{portal_type}' not found.") | ||
| return None | ||
| schema = get_info_for_type(dtype, self.request, portal_type) | ||
| return schema | ||
|
|
||
| def __call__(self, value): | ||
| schemas = {} | ||
| if value.get(self.value_field) == "table": | ||
| for col in value.get("columns") or []: | ||
| if not col.get("ct") or not col.get("field"): | ||
| continue | ||
| if col["ct"] not in schemas: | ||
| # get schema as plone.restapi /@types/Schema | ||
| schemas[col["ct"]] = self._get_schema(col["ct"]) | ||
| if not schemas[col["ct"]]: | ||
| continue | ||
| schema = schemas[col["ct"]] | ||
| if "properties" in schema and col["field"] in schema["properties"]: | ||
| # TODO: ma servono veramente tutte le info o solo una parte ? | ||
| col["field_properties"] = schema["properties"][col["field"]] | ||
| return value | ||
|
|
||
|
|
||
| class ListingTableVariationBlockSerialize(SearchTableVariationBlockSerialize): | ||
| block_type = "listing" | ||
| value_field = "variation" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.