Skip to content

Commit

Permalink
booking_type vocabulary for Service (#32)
Browse files Browse the repository at this point in the history
* booking type voc

* booking type voc changes

* test

---------

Co-authored-by: Andrea Cecchi <[email protected]>
  • Loading branch information
mamico and cekk committed Dec 19, 2023
1 parent bade8f9 commit 0f5f4ea
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 4 deletions.
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
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Changelog
------------------

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


1.2.0 (2023-11-20)
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()

0 comments on commit 0f5f4ea

Please sign in to comment.