aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2020-12-13 15:29:26 +0200
committerGravatar ks129 <[email protected]>2020-12-13 15:29:26 +0200
commit5948acaba542b8a1347c4c039635ad4a8066d2d8 (patch)
treeae279ead1e6f259e30c01261730e69b73805316e
parentMerge pull request #18 from python-discord/ks123/form-name-description (diff)
Add custom dict method in form to return sometimes only public fields
-rw-r--r--backend/models/form.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/backend/models/form.py b/backend/models/form.py
index 8d7fe9b..6b3c8bb 100644
--- a/backend/models/form.py
+++ b/backend/models/form.py
@@ -5,6 +5,8 @@ from pydantic import BaseModel, Field, validator
from backend.constants import FormFeatures
from .question import Question
+PUBLIC_FIELDS = ["id", "features", "questions", "name", "description"]
+
class Form(BaseModel):
"""Schema model for form."""
@@ -31,3 +33,12 @@ class Form(BaseModel):
raise ValueError("COLLECT_EMAIL feature require REQUIRES_LOGIN feature.")
return value
+
+ def dict(self, admin: bool = True, **kwargs: t.Dict) -> t.Dict[str, t.Any]:
+ """Wrapper for original function to exclude private data for public access."""
+ data = super().dict(**kwargs)
+
+ if admin:
+ return data
+
+ return {field: data[field] for field in PUBLIC_FIELDS}