-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
booking_type vocabulary for Service (#32)
* booking type voc * booking type voc changes * test --------- Co-authored-by: Andrea Cecchi <[email protected]>
- Loading branch information
Showing
8 changed files
with
81 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[settings] | ||
profile=plone |
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
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
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.
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 |
---|---|---|
@@ -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> |
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 |
---|---|---|
@@ -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() |