Skip to content

Commit

Permalink
Merge pull request #304 from euphorie/fix-choice-widget
Browse files Browse the repository at this point in the history
Fix the choice widget
  • Loading branch information
ale-rt authored Jan 23, 2025
2 parents 1253fd9 + 3606ff1 commit 4b06ad2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
11.0.0 (unreleased)
-------------------

- Prevent the choice widget to throw the error:
``TypeError: object of type 'CatalogSource' has no len()``
[ale-rt]

- Require Python 3.11 and 3.12 as Euphorie does
[ale-rt]

Expand Down
7 changes: 6 additions & 1 deletion src/osha/oira/nuplone/widget.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4b06ad2

Please sign in to comment.