diff options
Diffstat (limited to 'backend/models/form.py')
-rw-r--r-- | backend/models/form.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/backend/models/form.py b/backend/models/form.py index d0f0a3c..a8c5f92 100644 --- a/backend/models/form.py +++ b/backend/models/form.py @@ -3,7 +3,7 @@ import typing as t from pydantic import BaseModel, Field, validator from backend.constants import FormFeatures -from backend.models import Question +from .question import Question class Form(BaseModel): @@ -13,12 +13,16 @@ class Form(BaseModel): features: t.List[str] questions: t.List[Question] + class Config: + allow_population_by_field_name = True + @validator("features") - def validate_features(self, value: t.List[str]) -> t.Optional[t.List[str]]: + def validate_features(cls, value: t.List[str]) -> t.Optional[t.List[str]]: """Validates is all features in allowed list.""" # Uppercase everything to avoid mixed case in DB value = [v.upper() for v in value] - if not all(v in FormFeatures.__members__.values() for v in value): + allowed_values = list(v.value for v in FormFeatures.__members__.values()) + if not all(v in allowed_values for v in value): raise ValueError("Form features list contains one or more invalid values.") if FormFeatures.COLLECT_EMAIL in value and FormFeatures.REQUIRES_LOGIN not in value: # noqa |