From e25812f3e5c1d41ae4db6d4dbbc2994907123cde Mon Sep 17 00:00:00 2001 From: ale-rt Date: Mon, 20 Jan 2025 15:22:09 +0100 Subject: [PATCH] Fix the choice widget Prevent the choice widget to throw the error: ``` TypeError: object of type 'CatalogSource' has no len() ``` --- docs/changes.rst | 5 +++-- src/osha/oira/nuplone/widget.py | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 9b8344e9c..9367ac314 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -4,8 +4,9 @@ Changelog 10.1.1 (unreleased) ------------------- -- Nothing changed yet. - +- Prevent the choice widget to throw the error: + ``TypeError: object of type 'CatalogSource' has no len()`` + [ale-rt] 10.1.0 (2025-01-15) ------------------- diff --git a/src/osha/oira/nuplone/widget.py b/src/osha/oira/nuplone/widget.py index 85c1b6c2e..8987b5d44 100644 --- a/src/osha/oira/nuplone/widget.py +++ b/src/osha/oira/nuplone/widget.py @@ -1,6 +1,7 @@ from ..interfaces import IOSHAContentSkinLayer from .interfaces import ILargeTextAreaWidget from .interfaces import IOiRAFormLayer +from plone.app.vocabularies.catalog import CatalogSource from plonetheme.nuplone.z3cform.utils import getVocabulary from plonetheme.nuplone.z3cform.widget import SingleRadioWidget from z3c.form.browser.select import SelectWidget @@ -27,7 +28,11 @@ def ChoiceWidgetFactory(field, request): We increase min here """ vocabulary = getVocabulary(field) - if vocabulary is None or len(vocabulary) > 6: + if ( + vocabulary is None + or isinstance(vocabulary, CatalogSource) + or len(vocabulary) > 6 + ): widget = SelectWidget else: widget = SingleRadioWidget