From 5075e5a8e52558545b763304cd0ffdc73102cfb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20L=C3=B6fgren?= <viclo211@student.liu.se> Date: Thu, 29 Apr 2021 09:47:35 +0200 Subject: [PATCH] Add correcting instructions to question --- server/app/apis/questions.py | 2 ++ server/app/core/rich_schemas.py | 1 + server/app/core/schemas.py | 1 + server/app/database/controller/add.py | 4 ++-- server/app/database/models.py | 4 +++- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/app/apis/questions.py b/server/app/apis/questions.py index b14849d2..94df2a36 100644 --- a/server/app/apis/questions.py +++ b/server/app/apis/questions.py @@ -14,11 +14,13 @@ question_parser_add = reqparse.RequestParser() question_parser_add.add_argument("name", type=str, default=None, location="json") question_parser_add.add_argument("total_score", type=int, default=None, location="json") question_parser_add.add_argument("type_id", type=int, required=True, location="json") +question_parser_add.add_argument("correcting_instructions", type=str, default=None, location="json") question_parser_edit = reqparse.RequestParser() question_parser_edit.add_argument("name", type=str, default=sentinel, location="json") question_parser_edit.add_argument("total_score", type=int, default=sentinel, location="json") question_parser_edit.add_argument("type_id", type=int, default=sentinel, location="json") +question_parser_edit.add_argument("correcting_instructions", type=str, default=sentinel, location="json") @api.route("/questions") diff --git a/server/app/core/rich_schemas.py b/server/app/core/rich_schemas.py index 7d883584..60f7ac30 100644 --- a/server/app/core/rich_schemas.py +++ b/server/app/core/rich_schemas.py @@ -25,6 +25,7 @@ class QuestionSchemaRich(RichSchema): total_score = ma.auto_field() slide_id = ma.auto_field() type_id = ma.auto_field() + correcting_instructions = ma.auto_field() alternatives = fields.Nested(schemas.QuestionAlternativeSchema, many=True) diff --git a/server/app/core/schemas.py b/server/app/core/schemas.py index 73ac21cb..a2e81c25 100644 --- a/server/app/core/schemas.py +++ b/server/app/core/schemas.py @@ -63,6 +63,7 @@ class QuestionSchema(BaseSchema): total_score = ma.auto_field() type_id = ma.auto_field() slide_id = ma.auto_field() + correcting_instructions = ma.auto_field() class QuestionAnswerSchema(BaseSchema): diff --git a/server/app/database/controller/add.py b/server/app/database/controller/add.py index 6c5ea14b..128a3398 100644 --- a/server/app/database/controller/add.py +++ b/server/app/database/controller/add.py @@ -244,12 +244,12 @@ def user(email, password, role_id, city_id, name=None): return db_add(User(email, password, role_id, city_id, name)) -def question(name, total_score, type_id, slide_id): +def question(name, total_score, type_id, slide_id, correcting_instructions=None): """ Adds a question to the specified slide using the provided arguments. """ - return db_add(Question(name, total_score, type_id, slide_id)) + return db_add(Question(name, total_score, type_id, slide_id, correcting_instructions)) def question_alternative(text, value, question_id): diff --git a/server/app/database/models.py b/server/app/database/models.py index d4e177b0..4bb95967 100644 --- a/server/app/database/models.py +++ b/server/app/database/models.py @@ -154,15 +154,17 @@ class Question(db.Model): total_score = db.Column(db.Integer, nullable=False, default=1) type_id = db.Column(db.Integer, db.ForeignKey("question_type.id"), nullable=False) slide_id = db.Column(db.Integer, db.ForeignKey("slide.id"), nullable=False) + correcting_instructions = db.Column(db.Text, nullable=True, default=None) question_answers = db.relationship("QuestionAnswer", backref="question") alternatives = db.relationship("QuestionAlternative", backref="question") - def __init__(self, name, total_score, type_id, slide_id): + def __init__(self, name, total_score, type_id, slide_id, correcting_instructions): self.name = name self.total_score = total_score self.type_id = type_id self.slide_id = slide_id + self.correcting_instructions = correcting_instructions class QuestionAlternative(db.Model): -- GitLab