aboutsummaryrefslogtreecommitdiffstats
path: root/backend/models/question.py
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2020-12-02 13:13:10 +0200
committerGravatar ks129 <[email protected]>2020-12-02 13:13:10 +0200
commita47c49900c291f5d6f13411c780da8fbe2133718 (patch)
treeb4a4260654132f4bd74e115b9d54aba2df1f61ca /backend/models/question.py
parentFix Question circular import and use cls instead self for validators (diff)
Use cls instead self for Question model validators
Diffstat (limited to 'backend/models/question.py')
-rw-r--r--backend/models/question.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/backend/models/question.py b/backend/models/question.py
index 2324a47..22565fd 100644
--- a/backend/models/question.py
+++ b/backend/models/question.py
@@ -14,7 +14,7 @@ class Question(BaseModel):
data: t.Dict[str, t.Any]
@validator("type", pre=True)
- def validate_question_type(self, value: str) -> t.Optional[str]:
+ def validate_question_type(cls, value: str) -> t.Optional[str]:
"""Checks if question type in currently allowed types list."""
value = value.lower()
if value not in QUESTION_TYPES:
@@ -27,19 +27,19 @@ class Question(BaseModel):
@validator("data")
def validate_question_data(
- self,
+ cls,
value: t.Dict[str, t.Any]
) -> t.Optional[t.Dict[str, t.Any]]:
"""Check does required data exists for question type and remove other data."""
# When question type don't need data, don't add anything to keep DB clean.
- if self.type not in REQUIRED_QUESTION_TYPE_DATA:
+ if cls.type not in REQUIRED_QUESTION_TYPE_DATA:
return {}
# Required keys (and values) will be stored to here
# to remove all unnecessary stuff
result = {}
- for key, data_type in REQUIRED_QUESTION_TYPE_DATA[self.type].items():
+ for key, data_type in REQUIRED_QUESTION_TYPE_DATA[cls.type].items():
if key not in value:
raise ValueError(f"Required question data key '{key}' not provided.")