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 the choice widget #304

Merged
merged 2 commits into from
Jan 23, 2025
Merged
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
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
Loading