Skip to content

Commit

Permalink
Support single value in require_one_of_values
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiltsov-max committed Oct 3, 2024
1 parent 0123148 commit 5aed21e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cvat/apps/engine/field_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ def require_field(data: dict[str, Any], key: str) -> None:


def require_one_of_values(data: dict[str, Any], key: str, values: Sequence[Any]) -> None:
assert values

if data[key] not in values:
raise serializers.ValidationError(
'"{}" must be one of {}'.format(key, ", ".join(f"{k}" for k in values))
)
if len(values) == 1:
raise serializers.ValidationError(
'The "{}" field must be {}'.format(key, ", ".join(f"{k}" for k in values))
)
else:
raise serializers.ValidationError(
'The "{}" field must be one of {}'.format(key, ", ".join(f"{k}" for k in values))
)


def validate_percent(value: float) -> float:
Expand Down

0 comments on commit 5aed21e

Please sign in to comment.