Skip to content

Commit

Permalink
Merge pull request #20 from bdjilka/callable_in_validate_question_sel…
Browse files Browse the repository at this point in the history
…ectmany

Add callable value for validation of selectmany question
  • Loading branch information
ffaraone authored Sep 8, 2022
2 parents 487bd02 + afa7c82 commit 4a62f6b
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions interrogatio/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@ def _validate_question(q): # noqa: CCR001
values = q['values']
if values:
if not isinstance(values, (list, tuple)):
raise InvalidQuestionError(
'Choices must be a list or tuple of tuples.',
)
first_value = values[0]
if not isinstance(first_value, (list, tuple)):
raise InvalidQuestionError(
'Choices must be a list or tuple of tuples.',
)
if len(first_value) != 2:
raise InvalidQuestionError(
'Every choice must be a tuple (value, label).',
)
if not callable(values):
raise InvalidQuestionError(
'Choices must be a list, tuple of tuples or callable.',
)
else:
first_value = values[0]
if not isinstance(first_value, (list, tuple)):
raise InvalidQuestionError(
'Choices must be a list or tuple of tuples.',
)
if len(first_value) != 2:
raise InvalidQuestionError(
'Every choice must be a tuple (value, label).',
)

if 'validators' in q:
if not isinstance(q['validators'], (list, tuple)):
Expand Down

0 comments on commit 4a62f6b

Please sign in to comment.