-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #654 from ubc/allow-comparison-of-instructor-answers
Allow comparison of instructor answers
- Loading branch information
Showing
24 changed files
with
668 additions
and
160 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
alembic/versions/2561c39ac4d9_allow_instructor_answers_to_be_included_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Allow instructor answers to be included in comparisons | ||
Revision ID: 2561c39ac4d9 | ||
Revises: f6145781f130 | ||
Create Date: 2017-12-06 21:07:23.219244 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '2561c39ac4d9' | ||
down_revision = 'f6145781f130' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.sql import text | ||
|
||
from compair.models import convention | ||
|
||
def upgrade(): | ||
# add a new "comparable" column. default as true | ||
with op.batch_alter_table('answer', naming_convention=convention) as batch_op: | ||
batch_op.add_column(sa.Column('comparable', sa.Integer(), nullable=False, default='1', server_default='1')) | ||
|
||
# Patch existing answers from instructors and TAs as non-comparable. | ||
# Note that existing answers from sys admin are considered comparable (i.e. no need to patch). | ||
# sqlite doesn't support in-clause with multiple columns... | ||
# update = text( | ||
# "UPDATE answer SET comparable = 0 " | ||
# "WHERE (assignment_id, user_id) IN ( " | ||
# " SELECT a.id, uc.user_id " | ||
# " FROM user_course uc " | ||
# " JOIN assignment a " | ||
# " ON a.course_id = uc.course_id " | ||
# " WHERE uc.course_role IN ('Instructor', 'Teaching Assistant'))" | ||
# ) | ||
# ... use a potentially slower query | ||
update = text( | ||
"UPDATE answer SET comparable = 0 " | ||
"WHERE EXISTS ( " | ||
" SELECT 1 " | ||
" FROM user_course " | ||
" JOIN assignment " | ||
" ON assignment.course_id = user_course.course_id " | ||
" WHERE " | ||
" assignment.id = answer.assignment_id " | ||
" AND user_course.user_id = answer.user_id " | ||
" AND user_course.course_role IN ('Instructor', 'Teaching Assistant'))" | ||
) | ||
op.get_bind().execute(update) | ||
|
||
def downgrade(): | ||
with op.batch_alter_table('answer', naming_convention=convention) as batch_op: | ||
batch_op.drop_column('comparable') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.