-
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 serializer/deserializer for controlpanel * remove unused field and rename field in settings * code cleanup
- Loading branch information
Showing
4 changed files
with
9 additions
and
61 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
46 changes: 3 additions & 43 deletions
46
src/iosanita/policy/restapi/services/search_filters/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 |
---|---|---|
@@ -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 "[]") |
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