Skip to content

Commit

Permalink
Expanditems (#65)
Browse files Browse the repository at this point in the history
* `search_sections` in IDesignPloneSettings has a new filed in each section:
  `expandItems` that is a boolean to decide if the items of the section should
  be expanded or not (default is True).
* `search_sections` in IDesignPloneSettings has a new filed in each section:
  `expandItems` that is a boolean to decide if the items of the section should
  be expanded or not (default is True).
* fix
  • Loading branch information
mamico committed Sep 3, 2024
1 parent d73b153 commit f6760ed
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ Changelog
5.0.10 (unreleased)
-------------------

- `search_sections` in IDesignPloneSettings has a new filed in each section:
`expandItems` that is a boolean to decide if the items of the section should
be expanded or not (default is True).
[mamico]
- Add a profile to limit addables on site root
[lucabel]


5.0.9 (2024-04-12)
------------------

Expand Down
29 changes: 19 additions & 10 deletions src/design/plone/policy/restapi/search_filters/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,25 @@ def reply(self):
(section, self.request),
ISerializeToJsonSummary,
)()
children = section.listFolderContents(
contentFilter={"portal_type": utils.getUserFriendlyTypes()}
)
item_infos["items"] = [
getMultiAdapter(
(x, self.request),
ISerializeToJsonSummary,
)()
for x in children
]
if section_settings.get("expandItems", True):
children = section.listFolderContents(
contentFilter={"portal_type": utils.getUserFriendlyTypes()}
)
item_infos["items"] = [
getMultiAdapter(
(x, self.request),
ISerializeToJsonSummary,
)()
for x in children
]
else:
# do not expand childrens, the only item is the section/container itself
item_infos["items"] = [
getMultiAdapter(
(section, self.request),
ISerializeToJsonSummary,
)()
]
item_infos["title"] = section_settings.get("title", "")
items.append(item_infos)
if items:
Expand Down
27 changes: 26 additions & 1 deletion src/design/plone/policy/tests/test_search_filters_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from Products.CMFPlone.interfaces import ISearchSchema
from transaction import commit
from zope.component import getUtility

from design.plone.contenttypes.controlpanels.settings import IDesignPloneSettings
import json
import unittest


Expand Down Expand Up @@ -126,3 +127,27 @@ def test_endpoint_do_not_return_contents_that_are_not_searchable(self):

self.assertEqual("Amministrazione", amministrazione["title"])
self.assertEqual(7, len(amministrazione["items"]))

def test_not_expand_items(self):
# first section has 7 children
response = self.api_session.get("/@search-filters").json()
self.assertEqual(len(response["sections"][0]["items"][0]["items"]), 7)
self.assertEqual(len(response["sections"][0]["items"][1]["items"]), 15)

# change expandItems to False for the first section
settings = json.loads(
api.portal.get_registry_record(
"search_sections", interface=IDesignPloneSettings
)
)
settings[0]["items"][0]["expandItems"] = False
api.portal.set_registry_record(
"search_sections", json.dumps(settings), interface=IDesignPloneSettings
)
commit()

response = self.api_session.get("/@search-filters").json()
# first item now has only 1 child
self.assertEqual(len(response["sections"][0]["items"][0]["items"]), 1)
# second item still has 15 children
self.assertEqual(len(response["sections"][0]["items"][1]["items"]), 15)

0 comments on commit f6760ed

Please sign in to comment.