From 0ab7f6eecb1ca4b2b2066dd6a1a599bd14e1ae02 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Thu, 25 Jan 2024 16:15:13 +0100 Subject: [PATCH] Fix booking_type encoding --- CHANGES.rst | 2 +- .../restapi/services/bookable_list/get.py | 3 ++- .../plone/ioprenoto/vocabularies/tipologies.py | 18 ++++++++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 73d911b..e96efdb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,7 +7,7 @@ Changelog - Fix: term values must be unique in booking_type vocabulary [mamico] -- Workaround per booking_type con caratteri encodati due volte +- Fix booking_type encoding [mamico] 1.2.1 (2023-12-19) diff --git a/src/design/plone/ioprenoto/restapi/services/bookable_list/get.py b/src/design/plone/ioprenoto/restapi/services/bookable_list/get.py index 4625ff1..e252a40 100644 --- a/src/design/plone/ioprenoto/restapi/services/bookable_list/get.py +++ b/src/design/plone/ioprenoto/restapi/services/bookable_list/get.py @@ -5,6 +5,7 @@ from plone.restapi.serializer.converters import json_compatible from plone.restapi.services import Service from urllib.parse import urlencode +from urllib.parse import unquote from zc.relation.interfaces import ICatalog from zope.component import getMultiAdapter from zope.component import getUtility @@ -106,7 +107,7 @@ class BookableUOList(BookableList): def booking_type_check(self, prenotazioni_folder, booking_type): if not booking_type: return True - tocheck = [booking_type] + tocheck = [booking_type, unquote(booking_type)] # XXX: per qualche problema di doppio encoding arrivano dal frontend delle # stringhe con caratteri in hex, questo codice serve a gestire quelle # casistiche. Una volta fissato sul frontend può essere tolto. diff --git a/src/design/plone/ioprenoto/vocabularies/tipologies.py b/src/design/plone/ioprenoto/vocabularies/tipologies.py index 0418c01..47fe997 100644 --- a/src/design/plone/ioprenoto/vocabularies/tipologies.py +++ b/src/design/plone/ioprenoto/vocabularies/tipologies.py @@ -1,19 +1,29 @@ # -*- 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 urllib.parse import quote 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 SimpleTerm from zope.schema.vocabulary import SimpleVocabulary @implementer(IVocabularyFactory) -class PrenotazioneTypesVocabulary(Base): +class PrenotazioneTypesVocabulary(object): + def booking_type2term(self, booking_type): + """return a vocabulary tern with this""" + name = booking_type.title + duration = booking_type.duration + token = quote(name) + if not duration: + title = name + else: + title = f"{name} ({duration} min)" + return SimpleTerm(token, token=token, title=title) + def __call__(self, context): """ Return all the tipologies defined in the PrenotazioniFolder related to a Service