Skip to content

Commit

Permalink
add info additional info
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Oct 15, 2024
1 parent 008b1f3 commit dcd88f0
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/iosanita/policy/restapi/services/search_tassonomie/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.schema.interfaces import IVocabularyFactory

from collective.taxonomy import PATH_SEPARATOR
from collective.taxonomy.interfaces import ITaxonomy

ALLOWED_TAXONOMIES = ["parliamo_di", "a_chi_si_rivolge_tassonomia"]

Expand Down Expand Up @@ -79,6 +80,7 @@ def reply(self):

# add facets
results["facets"] = self.get_facets(query={index: query[index]})
results["infos"] = self.get_infos(index=index, value=value)
return results

def get_facets(self, query):
Expand All @@ -105,3 +107,23 @@ def get_facets(self, query):
portal_types_dict.append({"title": title, "token": ptype})
facets["portal_types"] = sorted(portal_types_dict, key=lambda x: x["title"])
return facets

def get_infos(self, index, value):

taxonomy = getUtility(ITaxonomy, name=f"collective.taxonomy.{index}")
taxonomy_voc = taxonomy.makeVocabulary(self.request.get("LANGUAGE"))

data = []
if not isinstance(value, list):
value = [value]
for key in value:
taxonomy_value = taxonomy_voc.inv_data.get(key, None)
if not taxonomy_value:
continue
if taxonomy_value.startswith(PATH_SEPARATOR):
taxonomy_value = taxonomy_value.replace(PATH_SEPARATOR, "", 1)

data.append(
{"title": taxonomy_value.split(PATH_SEPARATOR)[-1], "token": key}
)
return data

0 comments on commit dcd88f0

Please sign in to comment.