Skip to content
Snippets Groups Projects
Commit 3ad2ab41 authored by Ruben Young On's avatar Ruben Young On
Browse files

Changed migrations, changed API since put now no longer requires a...

Changed migrations, changed API since put now no longer requires a feedback_id, changed exams API, changed database script
parent 74899114
No related branches found
No related tags found
1 merge request!12Fix relation between MultipleChoiceOption and FeedbackOption
Pipeline #17708 passed
This commit is part of merge request !12. Comments created here will be created in the context of that merge request.
...@@ -21,11 +21,9 @@ def upgrade(): ...@@ -21,11 +21,9 @@ def upgrade():
op.create_table('mc_option', op.create_table('mc_option',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('label', sa.String(), nullable=True), sa.Column('label', sa.String(), nullable=True),
sa.Column('problem_id', sa.Integer(), nullable=False),
sa.Column('feedback_id', sa.Integer(), nullable=False), sa.Column('feedback_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['feedback_id'], ['feedback_option.id'], ), sa.ForeignKeyConstraint(['feedback_id'], ['feedback_option.id'], ),
sa.ForeignKeyConstraint(['id'], ['widget.id'], ), sa.ForeignKeyConstraint(['id'], ['widget.id'], ),
sa.ForeignKeyConstraint(['problem_id'], ['problem.id'], ),
sa.PrimaryKeyConstraint('id') sa.PrimaryKeyConstraint('id')
) )
# ### end Alembic commands ### # ### end Alembic commands ###
......
...@@ -157,15 +157,14 @@ class Exams(Resource): ...@@ -157,15 +157,14 @@ class Exams(Resource):
'graded': any([sol.graded_by is not None for sol in prob.solutions]), 'graded': any([sol.graded_by is not None for sol in prob.solutions]),
'mc_options': [ 'mc_options': [
{ {
'id': mc_option.id, 'id': mc_option.id,
'label': mc_option.label, 'label': mc_option.label,
'problem_id': mc_option.problem_id, 'feedback_id': mc_option.feedback_id,
'feedback_id': mc_option.feedback_id, 'widget': {
'widget': { 'name': mc_option.name,
'name': mc_option.name, 'x': mc_option.x,
'x': mc_option.x, 'y': mc_option.y
'y': mc_option.y }
}
} for mc_option in prob.mc_options } for mc_option in prob.mc_options
] ]
} for prob in exam.problems # Sorted by prob.id } for prob in exam.problems # Sorted by prob.id
......
...@@ -60,7 +60,6 @@ class MultipleChoice(Resource): ...@@ -60,7 +60,6 @@ class MultipleChoice(Resource):
y = args['y'] y = args['y']
label = args['label'] label = args['label']
problem_id = args['problem_id'] problem_id = args['problem_id']
feedback_id = args['feedback_id']
# TODO: Set type here or add to request? # TODO: Set type here or add to request?
mc_type = 'mcq_widget' mc_type = 'mcq_widget'
...@@ -73,7 +72,7 @@ class MultipleChoice(Resource): ...@@ -73,7 +72,7 @@ class MultipleChoice(Resource):
# Insert new entry into the database # Insert new entry into the database
mc_entry = MultipleChoiceOption() 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.add(mc_entry)
db.session.commit() db.session.commit()
...@@ -88,7 +87,7 @@ class MultipleChoice(Resource): ...@@ -88,7 +87,7 @@ class MultipleChoice(Resource):
if not mc_entry: if not mc_entry:
return dict(status=404, message=f"Multiple choice question with id {id} does not exist"), 404 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() db.session.commit()
return dict(status=200, message=f'Multiple choice question with id {id} updated'), 200 return dict(status=200, message=f'Multiple choice question with id {id} updated'), 200
......
...@@ -103,7 +103,7 @@ class Problem(db.Model): ...@@ -103,7 +103,7 @@ class Problem(db.Model):
@hybrid_property @hybrid_property
def mc_options(self): 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): class FeedbackOption(db.Model):
...@@ -114,7 +114,7 @@ class FeedbackOption(db.Model): ...@@ -114,7 +114,7 @@ class FeedbackOption(db.Model):
text = Column(Text, nullable=False) text = Column(Text, nullable=False)
description = Column(Text, nullable=True) description = Column(Text, nullable=True)
score = Column(Integer, 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 # Table for many to many relationship of FeedbackOption and Solution
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment