-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add serializer/deserializer for controlpanel
- Loading branch information
Showing
8 changed files
with
98 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
Empty file.
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:cache="http://namespaces.zope.org/cache" | ||
xmlns:plone="http://namespaces.plone.org/plone" | ||
xmlns:zcml="http://namespaces.zope.org/zcml" | ||
> | ||
|
||
<adapter factory=".controlpanel.IoSanitaControlpanelDeserializeFromJson" /> | ||
|
||
</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,32 @@ | ||
from plone.restapi.deserializer import json_body | ||
from plone.restapi.deserializer.controlpanels import ControlpanelDeserializeFromJson | ||
from plone.restapi.interfaces import IDeserializeFromJson | ||
from zope.component import adapter | ||
from zope.interface import implementer | ||
from iosanita.policy.interfaces import IIoSanitaSettingsControlpanel | ||
|
||
|
||
@implementer(IDeserializeFromJson) | ||
@adapter(IIoSanitaSettingsControlpanel) | ||
class IoSanitaControlpanelDeserializeFromJson(ControlpanelDeserializeFromJson): | ||
def __call__(self): | ||
""" | ||
Convert json data into a string | ||
""" | ||
super().__call__() | ||
|
||
req = json_body(self.controlpanel.request) | ||
proxy = self.registry.forInterface(self.schema, prefix=self.schema_prefix) | ||
|
||
search_sections = req.get("search_sections", []) | ||
for section in search_sections: | ||
# simplify stored data | ||
for item in section.get("items", []): | ||
fixed_urls = [ | ||
{"UID": x.get("UID", "")} | ||
for x in item.get("linkUrl", []) | ||
if x.get("UID", "") | ||
] | ||
item["linkUrl"] = fixed_urls | ||
|
||
setattr(proxy, "search_sections", search_sections) |
Empty file.
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:cache="http://namespaces.zope.org/cache" | ||
xmlns:plone="http://namespaces.plone.org/plone" | ||
xmlns:zcml="http://namespaces.zope.org/zcml" | ||
> | ||
|
||
<adapter factory=".controlpanel.IoSanitaControlpanelSerializeToJson" /> | ||
|
||
</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,39 @@ | ||
from plone.restapi.serializer.controlpanels import ControlpanelSerializeToJson | ||
from plone.restapi.interfaces import ISerializeToJson | ||
from zope.component import adapter | ||
from zope.interface import implementer | ||
from iosanita.policy.interfaces import IIoSanitaSettingsControlpanel | ||
from plone import api | ||
from plone.restapi.interfaces import ISerializeToJsonSummary | ||
from zope.component import getMultiAdapter | ||
|
||
import json | ||
|
||
|
||
@implementer(ISerializeToJson) | ||
@adapter(IIoSanitaSettingsControlpanel) | ||
class IoSanitaControlpanelSerializeToJson(ControlpanelSerializeToJson): | ||
def __call__(self): | ||
""" | ||
Convert json data into a string | ||
""" | ||
json_data = super().__call__() | ||
search_sections = json.loads(json_data["data"].get("search_sections", "{}")) | ||
|
||
for section in search_sections: | ||
# expand stored data | ||
for item in section.get("items", []): | ||
expanded_links = [] | ||
for link_url in item.get("linkUrl", []): | ||
section = api.content.get(UID=link_url.get("UID", "")) | ||
if not section: | ||
continue | ||
item_infos = getMultiAdapter( | ||
(section, self.request), | ||
ISerializeToJsonSummary, | ||
)() | ||
expanded_links.append(item_infos) | ||
item["linkUrl"] = expanded_links | ||
|
||
json_data["data"]["search_sections"] = json.dumps(search_sections) | ||
return json_data |
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