From cb63d09faf638d977aa42e6c6ae66e99f094b17c Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Fri, 20 Sep 2024 15:15:13 +0200 Subject: [PATCH] remove unused field and rename field in settings --- src/iosanita/policy/interfaces.py | 21 ++------ src/iosanita/policy/restapi/configure.zcml | 2 - .../policy/restapi/deserializer/__init__.py | 0 .../restapi/deserializer/configure.zcml | 10 ---- .../restapi/deserializer/controlpanel.py | 32 ------------ .../policy/restapi/serializer/__init__.py | 0 .../policy/restapi/serializer/configure.zcml | 10 ---- .../policy/restapi/serializer/controlpanel.py | 39 --------------- .../restapi/services/search_filters/get.py | 50 ++----------------- 9 files changed, 7 insertions(+), 157 deletions(-) delete mode 100644 src/iosanita/policy/restapi/deserializer/__init__.py delete mode 100644 src/iosanita/policy/restapi/deserializer/configure.zcml delete mode 100644 src/iosanita/policy/restapi/deserializer/controlpanel.py delete mode 100644 src/iosanita/policy/restapi/serializer/__init__.py delete mode 100644 src/iosanita/policy/restapi/serializer/configure.zcml delete mode 100644 src/iosanita/policy/restapi/serializer/controlpanel.py diff --git a/src/iosanita/policy/interfaces.py b/src/iosanita/policy/interfaces.py index a083340..00e0b06 100644 --- a/src/iosanita/policy/interfaces.py +++ b/src/iosanita/policy/interfaces.py @@ -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=_( diff --git a/src/iosanita/policy/restapi/configure.zcml b/src/iosanita/policy/restapi/configure.zcml index 9735c60..99c772b 100644 --- a/src/iosanita/policy/restapi/configure.zcml +++ b/src/iosanita/policy/restapi/configure.zcml @@ -4,8 +4,6 @@ > - - diff --git a/src/iosanita/policy/restapi/deserializer/__init__.py b/src/iosanita/policy/restapi/deserializer/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/iosanita/policy/restapi/deserializer/configure.zcml b/src/iosanita/policy/restapi/deserializer/configure.zcml deleted file mode 100644 index 0940dda..0000000 --- a/src/iosanita/policy/restapi/deserializer/configure.zcml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - diff --git a/src/iosanita/policy/restapi/deserializer/controlpanel.py b/src/iosanita/policy/restapi/deserializer/controlpanel.py deleted file mode 100644 index a8c1d5f..0000000 --- a/src/iosanita/policy/restapi/deserializer/controlpanel.py +++ /dev/null @@ -1,32 +0,0 @@ -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) diff --git a/src/iosanita/policy/restapi/serializer/__init__.py b/src/iosanita/policy/restapi/serializer/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/iosanita/policy/restapi/serializer/configure.zcml b/src/iosanita/policy/restapi/serializer/configure.zcml deleted file mode 100644 index b8f1092..0000000 --- a/src/iosanita/policy/restapi/serializer/configure.zcml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - diff --git a/src/iosanita/policy/restapi/serializer/controlpanel.py b/src/iosanita/policy/restapi/serializer/controlpanel.py deleted file mode 100644 index 0f6be1c..0000000 --- a/src/iosanita/policy/restapi/serializer/controlpanel.py +++ /dev/null @@ -1,39 +0,0 @@ -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 diff --git a/src/iosanita/policy/restapi/services/search_filters/get.py b/src/iosanita/policy/restapi/services/search_filters/get.py index b8dbb02..204f163 100644 --- a/src/iosanita/policy/restapi/services/search_filters/get.py +++ b/src/iosanita/policy/restapi/services/search_filters/get.py @@ -1,10 +1,7 @@ # -*- 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 @@ -12,55 +9,14 @@ 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 []: - if isinstance(uid, dict): - uid = uid.get("UID", "") - if not uid: - continue - 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 "[]")