Skip to content

Commit

Permalink
add new expander that expose settings
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Sep 13, 2024
1 parent 00351d7 commit c4e73b6
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"redturtle.bandi",
"collective.volto.subsites",
"redturtle.voltoplugin.editablefooter",
"collective.volto.subfooter",
],
extras_require={
"test": [
Expand Down
1 change: 1 addition & 0 deletions src/iosanita/policy/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<dependency>profile-redturtle.bandi:default</dependency>
<dependency>profile-collective.volto.subsites:default</dependency>
<dependency>profile-redturtle.voltoplugin.editablefooter:default</dependency>
<dependency>profile-collective.volto.subfooter:default</dependency>
</dependencies>
</metadata>
1 change: 1 addition & 0 deletions src/iosanita/policy/restapi/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JSON_FIELDS = ["search_sections", "quick_search_sections", "contatti_testata"]
1 change: 1 addition & 0 deletions src/iosanita/policy/restapi/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<include package="plone.restapi" />
<include package=".services" />


<!-- enable controlpanel on plone.restapi -->
<adapter
factory=".controlpanel.IoSanitaSettingsControlpanel"
Expand Down
2 changes: 2 additions & 0 deletions src/iosanita/policy/restapi/services/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<include package=".search_tassonomie" />
<include package=".search_filters" />
<include package=".iosanita_settings" />



</configure>
Empty file.
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 src/iosanita/policy/restapi/services/iosanita_settings/get.py
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"]
2 changes: 2 additions & 0 deletions src/iosanita/policy/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import souper.plone
import collective.volto.dropdownmenu
import collective.volto.socialsettings
import collective.volto.subfooter


class TestLayer(ContentTypesTestLayer):
Expand All @@ -28,6 +29,7 @@ def setUpZope(self, app, configurationContext):
self.loadZCML(package=collective.volto.slimheader)
self.loadZCML(package=collective.volto.dropdownmenu)
self.loadZCML(package=collective.volto.socialsettings)
self.loadZCML(package=collective.volto.subfooter)
self.loadZCML(package=iosanita.policy, context=configurationContext)

xmlconfig.file(
Expand Down

0 comments on commit c4e73b6

Please sign in to comment.