diff options
| author | 2020-12-02 14:14:57 +0200 | |
|---|---|---|
| committer | 2020-12-02 14:14:57 +0200 | |
| commit | 16552df4c5862004f63a8d8a7c0f8e0dd16f8a0e (patch) | |
| tree | 91f5342d4314759149bb48fb1db6cbf1d44c729e /backend/models | |
| parent | Move MongoDB output to Form model and after convert it to dictionary (diff) | |
Fix form features validation and allow passing ID as id not _id
Diffstat (limited to 'backend/models')
| -rw-r--r-- | backend/models/form.py | 6 | 
1 files changed, 5 insertions, 1 deletions
| diff --git a/backend/models/form.py b/backend/models/form.py index 79d1d54..a8c5f92 100644 --- a/backend/models/form.py +++ b/backend/models/form.py @@ -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(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 | 
