Skip to content

Commit

Permalink
Fix booking_type encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mamico committed Jan 25, 2024
1 parent e84f250 commit 0ab7f6e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 14 additions & 4 deletions src/design/plone/ioprenoto/vocabularies/tipologies.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 0ab7f6e

Please sign in to comment.