aboutsummaryrefslogtreecommitdiffstats
path: root/backend/models/form.py
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2024-07-09 18:56:25 +0100
committerGravatar Chris Lovering <[email protected]>2024-07-09 19:01:28 +0100
commitae2d6ccac9d3c4d5181347e016660216212b3035 (patch)
treef58690867087ca26c45670d34d100a83e2233c47 /backend/models/form.py
parentDocument timezone field in SCHEMA.md (diff)
Move unittest filtering to the Form.dict() function
Diffstat (limited to 'backend/models/form.py')
-rw-r--r--backend/models/form.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/backend/models/form.py b/backend/models/form.py
index 3db267e..739464e 100644
--- a/backend/models/form.py
+++ b/backend/models/form.py
@@ -94,17 +94,19 @@ class Form(BaseModel):
def dict(self, admin: bool = True, **kwargs) -> dict[str, t.Any]: # noqa: FBT001, FBT002
"""Wrapper for original function to exclude private data for public access."""
data = super().dict(**kwargs)
+ if admin:
+ return data
returned_data = {}
- if not admin:
- for field in PUBLIC_FIELDS:
- fetch_field = "_id" if field == "id" and kwargs.get("by_alias") else field
-
- returned_data[field] = data[fetch_field]
- else:
- returned_data = data
+ for field in PUBLIC_FIELDS:
+ fetch_field = "_id" if field == "id" and kwargs.get("by_alias") else field
+ returned_data[field] = data[fetch_field]
+ # Replace the unittest data section of code questions with the number of test cases.
+ for question in returned_data["questions"]:
+ if question["type"] == "code" and question["data"]["unittests"] is not None:
+ question["data"]["unittests"]["tests"] = len(question["data"]["unittests"]["tests"])
return returned_data