From 3ad2ab4196c6793eac3e7c024bbb2b169a52948c Mon Sep 17 00:00:00 2001 From: Ruben Young On <r.d.youngon@student.tudelft.nl> Date: Sat, 18 May 2019 15:37:38 +0200 Subject: [PATCH] Changed migrations, changed API since put now no longer requires a feedback_id, changed exams API, changed database script --- migrations/versions/b46a2994605b_.py | 2 -- zesje/api/exams.py | 17 ++++++++--------- zesje/api/mult_choice.py | 5 ++--- zesje/database.py | 4 ++-- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/migrations/versions/b46a2994605b_.py b/migrations/versions/b46a2994605b_.py index eb7b34e7..0c7e7404 100644 --- a/migrations/versions/b46a2994605b_.py +++ b/migrations/versions/b46a2994605b_.py @@ -21,11 +21,9 @@ def upgrade(): op.create_table('mc_option', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('label', sa.String(), nullable=True), - sa.Column('problem_id', sa.Integer(), nullable=False), sa.Column('feedback_id', sa.Integer(), nullable=False), sa.ForeignKeyConstraint(['feedback_id'], ['feedback_option.id'], ), sa.ForeignKeyConstraint(['id'], ['widget.id'], ), - sa.ForeignKeyConstraint(['problem_id'], ['problem.id'], ), sa.PrimaryKeyConstraint('id') ) # ### end Alembic commands ### diff --git a/zesje/api/exams.py b/zesje/api/exams.py index e2f6eea2..bccbeeca 100644 --- a/zesje/api/exams.py +++ b/zesje/api/exams.py @@ -157,15 +157,14 @@ class Exams(Resource): 'graded': any([sol.graded_by is not None for sol in prob.solutions]), 'mc_options': [ { - 'id': mc_option.id, - 'label': mc_option.label, - 'problem_id': mc_option.problem_id, - 'feedback_id': mc_option.feedback_id, - 'widget': { - 'name': mc_option.name, - 'x': mc_option.x, - 'y': mc_option.y - } + 'id': mc_option.id, + 'label': mc_option.label, + 'feedback_id': mc_option.feedback_id, + 'widget': { + 'name': mc_option.name, + 'x': mc_option.x, + 'y': mc_option.y + } } for mc_option in prob.mc_options ] } for prob in exam.problems # Sorted by prob.id diff --git a/zesje/api/mult_choice.py b/zesje/api/mult_choice.py index b2f2f4a6..a8d0817c 100644 --- a/zesje/api/mult_choice.py +++ b/zesje/api/mult_choice.py @@ -60,7 +60,6 @@ class MultipleChoice(Resource): y = args['y'] label = args['label'] problem_id = args['problem_id'] - feedback_id = args['feedback_id'] # TODO: Set type here or add to request? mc_type = 'mcq_widget' @@ -73,7 +72,7 @@ class MultipleChoice(Resource): # Insert new entry into the database mc_entry = MultipleChoiceOption() - set_mc_data(mc_entry, name, x, y, mc_type, feedback_id, label) + set_mc_data(mc_entry, name, x, y, mc_type, new_feedback_option.id, label) db.session.add(mc_entry) db.session.commit() @@ -88,7 +87,7 @@ class MultipleChoice(Resource): if not mc_entry: return dict(status=404, message=f"Multiple choice question with id {id} does not exist"), 404 - set_mc_data(mc_entry, name, x, y, mc_type, feedback_id, label) + set_mc_data(mc_entry, name, x, y, mc_type, label) db.session.commit() return dict(status=200, message=f'Multiple choice question with id {id} updated'), 200 diff --git a/zesje/database.py b/zesje/database.py index 157eb9b4..16f005ab 100644 --- a/zesje/database.py +++ b/zesje/database.py @@ -103,7 +103,7 @@ class Problem(db.Model): @hybrid_property def mc_options(self): - return [mc_option for mc_option in self.feedback_options] + return [feedback_option.mc_option for feedback_option in self.feedback_options if feedback_option.mc_option] class FeedbackOption(db.Model): @@ -114,7 +114,7 @@ class FeedbackOption(db.Model): text = Column(Text, nullable=False) description = Column(Text, nullable=True) score = Column(Integer, nullable=True) - mc_option = db.relationship('MultipleChoiceOption', backref='feedback', lazy=True) + mc_option = db.relationship('MultipleChoiceOption', backref='feedback', uselist=False, lazy=True) # Table for many to many relationship of FeedbackOption and Solution -- GitLab