Skip to content

Commit

Permalink
Fix settings (#3)
Browse files Browse the repository at this point in the history
* add serializer/deserializer for controlpanel

* remove unused field and rename field in settings

* code cleanup
  • Loading branch information
cekk authored Sep 20, 2024
1 parent ffad43c commit 548149d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 61 deletions.
21 changes: 4 additions & 17 deletions src/iosanita/policy/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,16 @@ class IIoSanitaSettings(Interface):
value_type=TextLine(),
)

search_sections = SourceText(
title=_("search_sections_label", default="Sezioni ricerca"),
quick_search = SourceText(
title=_("quick_search_label", default="Scorcatoie di ricerca"),
description=_(
"search_sections_help",
default="Inserire una lista di sezioni per la ricerca.",
"quick_search_help",
default="Inserire una lista di scorciatoie per la ricerca.",
),
default="",
required=False,
)

show_modified_default = Bool(
title=_("show_modified_default_label", default="Mostra la data di modifica"),
description=_(
"show_modified_default_help",
default="Questo è il valore di default per decidere se mostrare "
"o meno la data di modifica nei contenuti che hanno la behavior "
"abilitata. E' poi possibile sovrascrivere il default nei singoli "
'contenuti (nel tab "Impostazioni").',
),
default=True,
required=False,
)

show_dynamic_folders_in_footer = Bool(
title=_("show_dynamic_folders_in_footer_label", default="Footer dinamico"),
description=_(
Expand Down
1 change: 1 addition & 0 deletions src/iosanita/policy/restapi/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<include package=".services" />



<!-- enable controlpanel on plone.restapi -->
<adapter
factory=".controlpanel.IoSanitaSettingsControlpanel"
Expand Down
46 changes: 3 additions & 43 deletions src/iosanita/policy/restapi/services/search_filters/get.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,22 @@
# -*- coding: utf-8 -*-
from AccessControl.unauthorized import Unauthorized
from iosanita.policy.interfaces import IIoSanitaSettings
from plone import api
from plone.restapi.interfaces import ISerializeToJsonSummary
from plone.restapi.services import Service
from zope.component import getMultiAdapter

import json


class SearchFiltersGET(Service):
def reply(self):
return {
"sections": self.get_section_data(field_id="search_sections"),
"quick_search": self.get_data_from_registry(field_id="quick_search"),
}

def get_section_data(self, field_id):
def get_data_from_registry(self, field_id):
try:
values = api.portal.get_registry_record(
field_id, interface=IIoSanitaSettings, default="[]"
)
except KeyError:
return []
utils = api.portal.get_tool(name="plone_utils")

sections = []
for setting in json.loads(values or "[]"):
items = []
for section_settings in setting.get("items") or []:
for uid in section_settings.get("linkUrl") or []:
try:
section = api.content.get(UID=uid)
except Unauthorized:
# private folder
continue
if not section:
continue
item_infos = getMultiAdapter(
(section, self.request),
ISerializeToJsonSummary,
)()
children = section.listFolderContents(
contentFilter={"portal_type": utils.getUserFriendlyTypes()}
)
item_infos["items"] = [
getMultiAdapter(
(x, self.request),
ISerializeToJsonSummary,
)()
for x in children
]
item_infos["title"] = section_settings.get("title", "")
items.append(item_infos)
if items:
sections.append(
{
"rootPath": setting.get("rootPath", ""),
"items": items,
}
)
return sections
return json.loads(values or "[]")
2 changes: 1 addition & 1 deletion src/iosanita/policy/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import collective.feedback
import collective.volto.dropdownmenu
import collective.volto.enhancedlinks
import collective.volto.formsupport
import collective.volto.slimheader
import collective.volto.socialsettings
import collective.volto.subfooter
import iosanita.contenttypes
import iosanita.policy
import plone.app.caching
import souper.plone
import collective.volto.formsupport


class TestLayer(ContentTypesTestLayer):
Expand Down

0 comments on commit 548149d

Please sign in to comment.