Created
August 9, 2017 19:34
-
-
Save harveyslash/cca693f6af9a451117de2ed1d961d645 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
if request.method == 'POST': | |
json = request.get_json() | |
question = db.session.query(Question).filter_by(id=question_id).first() | |
if question.type == 'TITA': | |
question_attempt = QuestionAttempt(section_attempt_id=section_attempt_id, | |
question_id=question_id, | |
tita_choice=json['tita_choice']) | |
else: | |
question_attempt = QuestionAttempt(section_attempt_id=section_attempt_id, | |
question_id=question_id, | |
choice_id=json['choice_id'], | |
attempt_status='submitted') | |
db.session.add(question_attempt) | |
db.session.commit() | |
return jsonify({'success': True}) | |
elif request.method == 'DELETE': | |
t = QuestionAttempt.__table__ | |
db.session.execute(t.delete().where( | |
t.c.question_id == question_id and t.c.section_attempt_id == section_attempt_id) | |
) | |
db.session.commit() | |
return jsonify({'success': True}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment