From bf09641de38f9a74243d6cc3d9a3d900e8afc6ab Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Thu, 25 Jan 2024 14:36:18 +0100 Subject: [PATCH 1/4] Fix: term values must be unique in booking_type vocabulary --- CHANGES.rst | 3 +- .../prenotazioni/vocabularies/tipologies.py | 30 +++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index ec16aff3..189de181 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,8 @@ Changelog 2.4.5 (unreleased) ------------------ -- Nothing changed yet. +- Fix: term values must be unique in booking_type vocabulary + [mamico] 2.4.4 (2024-01-25) diff --git a/src/redturtle/prenotazioni/vocabularies/tipologies.py b/src/redturtle/prenotazioni/vocabularies/tipologies.py index 54ecee64..27a4640e 100644 --- a/src/redturtle/prenotazioni/vocabularies/tipologies.py +++ b/src/redturtle/prenotazioni/vocabularies/tipologies.py @@ -26,13 +26,12 @@ def booking_type2term(self, booking_type): 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): """ @@ -40,14 +39,15 @@ def __call__(self, context): """ 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)) From c636fdc06961905f0d87d3f9701132dc8c0c39b4 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Thu, 25 Jan 2024 17:21:00 +0100 Subject: [PATCH 2/4] Fix: urlencode/quote booking_type vocab terms --- CHANGES.rst | 3 +++ src/redturtle/prenotazioni/tests/test_vocabularies.py | 4 ++-- src/redturtle/prenotazioni/vocabularies/tipologies.py | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 189de181..9db3d0a8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,9 @@ Changelog 2.4.5 (unreleased) ------------------ +- Fix: urlencode/quote booking_type vocab terms + [mamico[ + - Fix: term values must be unique in booking_type vocabulary [mamico] diff --git a/src/redturtle/prenotazioni/tests/test_vocabularies.py b/src/redturtle/prenotazioni/tests/test_vocabularies.py index c8818308..fd68eeaf 100644 --- a/src/redturtle/prenotazioni/tests/test_vocabularies.py +++ b/src/redturtle/prenotazioni/tests/test_vocabularies.py @@ -69,8 +69,8 @@ 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"} ) diff --git a/src/redturtle/prenotazioni/vocabularies/tipologies.py b/src/redturtle/prenotazioni/vocabularies/tipologies.py index 27a4640e..3e566020 100644 --- a/src/redturtle/prenotazioni/vocabularies/tipologies.py +++ b/src/redturtle/prenotazioni/vocabularies/tipologies.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from plone import api from Products.CMFPlone.interfaces.siteroot import IPloneSiteRoot +from urllib.parse import quote from zope.interface import implementer from zope.schema.interfaces import IVocabularyFactory from zope.schema.vocabulary import SimpleTerm @@ -15,13 +16,14 @@ 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""" From 0782442000490c26ca7294165d5e83be12a7ebba Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Tue, 21 Jan 2025 19:06:18 +0100 Subject: [PATCH 3/4] changelog --- CHANGES.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 89e9f4d1..e0b18083 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,9 +6,8 @@ Changelog ------------------ - Fix: urlencode/quote booking_type vocab terms - [mamico[ + [mamico] -- Fix: term values must be unique in booking_type vocabulary - isort with plone profile [mamico] From dcbb56364ba2c0d5583371f8545d9c69b3c50d57 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Tue, 21 Jan 2025 19:07:10 +0100 Subject: [PATCH 4/4] black --- src/redturtle/prenotazioni/tests/test_vocabularies.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/redturtle/prenotazioni/tests/test_vocabularies.py b/src/redturtle/prenotazioni/tests/test_vocabularies.py index 80f0f329..57a0739b 100644 --- a/src/redturtle/prenotazioni/tests/test_vocabularies.py +++ b/src/redturtle/prenotazioni/tests/test_vocabularies.py @@ -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%20A", "Type%20B", "Type%20C"} + set(factory(self.portal).by_token.keys()), + {"Type%20A", "Type%20B", "Type%20C"}, ) self.assertEqual( - set(factory(self.folder_prenotazioni).by_token.keys()), {"Type%20A", "Type%20B"} + set(factory(self.folder_prenotazioni).by_token.keys()), + {"Type%20A", "Type%20B"}, )