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

booking_type vocabulary for Service #32

Merged
merged 4 commits into from
Dec 19, 2023
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
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile=plone
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
1.2.1 (unreleased)
------------------

- booking_type vocabulary for Service
[mamico]
- Align tests with redturtle.prenotazioni > 2.2.5.
[cekk]

Expand Down
1 change: 1 addition & 0 deletions src/design/plone/ioprenoto/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<include package=".behaviors" />
<include package=".restapi" />
<include package=".upgrades" />
<include package=".vocabularies" />


<include file="permissions.zcml" />
Expand Down
11 changes: 7 additions & 4 deletions src/design/plone/ioprenoto/restapi/services/bookable_list/get.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-
from logging import getLogger
from urllib.parse import urlencode

from plone import api
from plone.restapi.interfaces import ISerializeToJsonSummary
from plone.restapi.serializer.converters import json_compatible
from plone.restapi.services import Service
from urllib.parse import urlencode
from zc.relation.interfaces import ICatalog
from zope.component import getMultiAdapter, getUtility
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.intid.interfaces import IIntIds


logger = getLogger(__name__)


Expand All @@ -28,7 +29,9 @@ def reply(self):
portal_url = api.portal.get().absolute_url()
query = {"portal_type": "Servizio", "sort_on": "sortable_title"}
for brain_service in api.content.find(**query):
# service = brain.getObject()
# XXX: get_uo_from_service_uid ha l'object, ma anzichè usarlo, si tira fuori lo UID
# e poi si cerca quell'UID nel catalog. Sicuarmente questo aiuta a escludere
# oggetti privati, ma sembra un passaggio inutilmente complicato (?)
for brain_uo in api.content.find(
UID=self.get_uo_from_service_uid(uid=brain_service.UID)
):
Expand Down
11 changes: 11 additions & 0 deletions src/design/plone/ioprenoto/utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-


def get_uo_from_service(service):
"""Dato lo UID di un servizio, restituisce le UO a cui è collegato
come canale fisico o unità organizzativa responsabile"""
canale_fisico = getattr(service, "canale_fisico", [])
if canale_fisico:
return [x.to_object for x in canale_fisico if x.to_object]
ufficio_responsabile = getattr(service, "ufficio_responsabile", [])
return [x.to_object for x in ufficio_responsabile if x.to_object]
Empty file.
11 changes: 11 additions & 0 deletions src/design/plone/ioprenoto/vocabularies/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<configure
xmlns="http://namespaces.zope.org/zope"
i18n_domain="redturtle.prenotazioni"
>

<utility
name="design.plone.ioprenoto.booking_types"
component=".tipologies.PrenotazioneTypesVocabularyFactory"
/>

</configure>
45 changes: 45 additions & 0 deletions src/design/plone/ioprenoto/vocabularies/tipologies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
from design.plone.ioprenoto.utilities import get_uo_from_service
from plone import api
from redturtle.prenotazioni.vocabularies.tipologies import (
PrenotazioneTypesVocabulary as Base,
)
from zc.relation.interfaces import ICatalog
from zope.component import getUtility
from zope.interface import implementer
from zope.intid.interfaces import IIntIds
from zope.schema.interfaces import IVocabularyFactory
from zope.schema.vocabulary import SimpleVocabulary


@implementer(IVocabularyFactory)
class PrenotazioneTypesVocabulary(Base):
def __call__(self, context):
"""
Return all the tipologies defined in the PrenotazioniFolder related to a Service
"""
terms = []
intids = getUtility(IIntIds)
catalog = getUtility(ICatalog)
for uo in get_uo_from_service(context) or []:
relations = catalog.findRelations(
{
"to_id": intids.getId(uo),
"from_attribute": "uffici_correlati",
}
)
for rel in relations:
prenotazioni_folder = rel.from_object
if prenotazioni_folder and api.user.has_permission(
"View", obj=prenotazioni_folder
):
terms.extend(
[
self.booking_type2term(booking_type)
for booking_type in prenotazioni_folder.get_booking_types()
]
)
return SimpleVocabulary(terms)


PrenotazioneTypesVocabularyFactory = PrenotazioneTypesVocabulary()
Loading