-
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 new expander that expose settings
- Loading branch information
Showing
9 changed files
with
82 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 @@ | ||
JSON_FIELDS = ["search_sections", "quick_search_sections", "contatti_testata"] |
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
Empty file.
26 changes: 26 additions & 0 deletions
26
src/iosanita/policy/restapi/services/iosanita_settings/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,26 @@ | ||
<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" | ||
> | ||
|
||
<plone:service | ||
method="GET" | ||
factory=".get.IoSanitaSettingsGet" | ||
for="zope.interface.Interface" | ||
permission="zope2.View" | ||
name="@iosanita-settings-data" | ||
/> | ||
|
||
<adapter | ||
factory=".get.IoSanitaSettings" | ||
name="iosanita-settings-data" | ||
/> | ||
|
||
<cache:ruleset | ||
for=".get.IoSanitaSettingsGet" | ||
ruleset="plone.content.dynamic" | ||
/> | ||
|
||
</configure> |
48 changes: 48 additions & 0 deletions
48
src/iosanita/policy/restapi/services/iosanita_settings/get.py
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,48 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone.restapi.interfaces import IExpandableElement | ||
from plone.restapi.services import Service | ||
from zope.component import adapter | ||
from iosanita.policy.interfaces import IIoSanitaSettings | ||
from plone import api | ||
from zope.interface import implementer | ||
from zope.interface import Interface | ||
|
||
import json | ||
|
||
|
||
@implementer(IExpandableElement) | ||
@adapter(Interface, Interface) | ||
class IoSanitaSettings(object): | ||
def __init__(self, context, request): | ||
self.context = context | ||
self.request = request | ||
|
||
def __call__(self, expand=False): | ||
""" | ||
Bypass expand variable: it's always expanded because we always need this data. | ||
""" | ||
result = { | ||
"iosanita-settings": { | ||
"@id": f"{self.context.absolute_url()}/@iosanita-settings-data" | ||
} | ||
} | ||
|
||
contatti_testata = ( | ||
api.portal.get_registry_record( | ||
"contatti_testata", interface=IIoSanitaSettings | ||
) | ||
or "" | ||
) | ||
if contatti_testata: | ||
contatti_testata = json.loads(contatti_testata) | ||
else: | ||
contatti_testata = None | ||
result["iosanita-settings"]["contatti_testata"] = contatti_testata | ||
|
||
return result | ||
|
||
|
||
class IoSanitaSettingsGet(Service): | ||
def reply(self): | ||
data = IoSanitaSettings(self.context, self.request) | ||
return data()["iosanita-settings"] |
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