Beispiel #1
0
    def new_submission(course_id, test_id, question_id):
        q = Question.query.filter_by(id=question_id).first()
        sub = q.get_user_submission(current_user.id)
        if not sub:  # if no existing submission exists
            sub = Submission()
            sub.user_id = current_user.id
            sub.test_id = test_id
            sub.question_id = question_id

        form = QuestionSubmissionForm()
        if form.validate_on_submit():
            if q.question_type == 1:
                sub.output_sub = form.output_answer.data
            elif q.question_type == 2:
                sub.mcq_sub = form.mcq_answer.data
            elif q.question_type == 3:
                sub.code_sub = repr(form.code_answer.data)[1:-1]

            db.session.add(sub)
            db.session.commit()

        return redirect(
            url_for('take_test', course_id=course_id, test_id=test_id))