aboutsummaryrefslogtreecommitdiffstats
path: root/backend/models/form.py
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2020-12-02 14:14:57 +0200
committerGravatar ks129 <[email protected]>2020-12-02 14:14:57 +0200
commit16552df4c5862004f63a8d8a7c0f8e0dd16f8a0e (patch)
tree91f5342d4314759149bb48fb1db6cbf1d44c729e /backend/models/form.py
parentMove 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/form.py')
-rw-r--r--backend/models/form.py6
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