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

Fix: urlencode/quote booking_type vocab terms #174

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog
2.8.5 (unreleased)
------------------

- Fix: urlencode/quote booking_type vocab terms
[mamico]

- isort with plone profile
[mamico]

Expand Down
6 changes: 4 additions & 2 deletions src/redturtle/prenotazioni/tests/test_vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def test_booking_types(self):
IVocabularyFactory, name="redturtle.prenotazioni.booking_types"
)
self.assertEqual(
set(factory(self.portal).by_token.keys()), {"Type A", "Type B", "Type C"}
set(factory(self.portal).by_token.keys()),
{"Type%20A", "Type%20B", "Type%20C"},
)
self.assertEqual(
set(factory(self.folder_prenotazioni).by_token.keys()), {"Type A", "Type B"}
set(factory(self.folder_prenotazioni).by_token.keys()),
{"Type%20A", "Type%20B"},
)
34 changes: 18 additions & 16 deletions src/redturtle/prenotazioni/vocabularies/tipologies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from plone import api
from Products.CMFPlone.interfaces.siteroot import IPloneSiteRoot
from redturtle.prenotazioni.utils.get_prenotazioni_folder import getPrenotazioniFolder
from urllib.parse import quote
from zope.interface import implementer
from zope.schema.interfaces import IVocabularyFactory
from zope.schema.vocabulary import SimpleTerm
Expand All @@ -14,39 +15,40 @@ 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(name, token=name, title=title)
return SimpleTerm(token, token=token, title=title)

def get_terms(self, context):
"""The vocabulary terms"""
prenotazioni_folder = getPrenotazioniFolder(context)

return [
self.booking_type2term(booking_type)
for booking_type in prenotazioni_folder
and prenotazioni_folder.get_booking_types()
or []
]
terms = []
for booking_type in prenotazioni_folder.get_booking_types():
term = self.booking_type2term(booking_type)
if term.value not in [t.value for t in terms]:
terms.append(term)
return terms

def __call__(self, context):
"""
Return all the tipologies defined in the PrenotazioniFolder
"""
if IPloneSiteRoot.providedBy(context):
catalog = api.portal.get_tool("portal_catalog")
return SimpleVocabulary(
[
self.booking_type2term(brain.getObject())
for brain in catalog(
portal_type="PrenotazioneType", sort_by="sortable_title"
)
]
)
terms = []
for brain in catalog(
portal_type="PrenotazioneType", sort_by="sortable_title"
):
booking_type = brain.getObject()
term = self.booking_type2term(booking_type)
if term.value not in [t.value for t in terms]:
terms.append(term)
return SimpleVocabulary(terms)
else:
return SimpleVocabulary(self.get_terms(context))

Expand Down
Loading