Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@bandi-search-filters: if called on a specific folder returns only ti… #61

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
4.0.7 (unreleased)
------------------

- Nothing changed yet.
- @bandi-search-filters: if called on a specific folder returns only tipologies and subjects of bandi inside that folder.
[daniele]


4.0.6 (2023-09-08)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
name="@bandi-search-filters"
/>

<plone:service
method="GET"
factory=".get.BandiSearchFiltersGet"
for="plone.app.contenttypes.interfaces.IFolder"
permission="zope2.View"
name="@bandi-search-filters"
/>

<cache:ruleset
for=".get.BandiSearchFiltersGet"
ruleset="plone.content.dynamic"
Expand Down
50 changes: 45 additions & 5 deletions src/design/plone/policy/restapi/bandi_search_filters/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from plone.restapi.services import Service
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse
from redturtle.bandi.vocabularies import TipologiaBandoVocabularyFactory


@implementer(IPublishTraverse)
Expand All @@ -11,19 +12,58 @@ def reply(self):
"""
Return possible values based also on current user permissions
"""
subjects = []
pc = api.portal.get_tool(name="portal_catalog")
for subject in pc.uniqueValuesFor("Subject_bando"):
res = api.content.find(Subject_bando=subject)
if res:
subjects.append({"UID": subject, "title": subject})
voc_tipologie = TipologiaBandoVocabularyFactory(self.context)

tipologie = []
subjects = []
offices = []

bandi_folder = None

if self.context.portal_type == "Folder":
bandi_folder = self.context

if bandi_folder:
bandi_folder_path = "/".join(bandi_folder.getPhysicalPath())
query = {"portal_type": ["Bando"], "path": bandi_folder_path}
brains = pc(query)

for brain in brains:
bando = brain.getObject()
found = [x for x in tipologie if x["UID"] == bando.tipologia_bando]

if not found:
tipologie.append(
{
"UID": bando.tipologia_bando,
"title": voc_tipologie.getTerm(bando.tipologia_bando).title,
}
)
for sub in bando.subject:
found = [x for x in subjects if x["UID"] == sub]
if not found:
subjects.append({"UID": sub, "title": sub})

else:
for subject in pc.uniqueValuesFor("Subject_bando"):
res = api.content.find(Subject_bando=subject)
if res:
subjects.append({"UID": subject, "title": subject})

for item in voc_tipologie.by_token:
tipologie.append(
{"UID": item, "title": voc_tipologie.getTerm(item).title}
)

office_uids = pc.uniqueValuesFor("ufficio_responsabile_bando")
offices = [{"UID": x.UID, "title": x.Title} for x in pc(UID=office_uids)]

subjects.sort(key=lambda x: x["title"])
offices.sort(key=lambda x: x["title"])
tipologie.sort(key=lambda x: x["title"])
return {
"subjects": subjects,
"offices": offices,
"tipologie": tipologie,
}
2 changes: 1 addition & 1 deletion src/design/plone/policy/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def to_2010(context):
settings.custom_attributes = settings.custom_attributes + ["data-element"]


def to_2022(context): # noqa
def to_2022(context): # noqa
for brain in api.portal.get_tool("portal_catalog")():
item = aq_base(brain.getObject())

Expand Down
Loading