Skip to content

Instantly share code, notes, and snippets.

@harveyslash
Created August 9, 2017 19:34
Show Gist options
  • Save harveyslash/cca693f6af9a451117de2ed1d961d645 to your computer and use it in GitHub Desktop.
Save harveyslash/cca693f6af9a451117de2ed1d961d645 to your computer and use it in GitHub Desktop.
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