예제 #1
0
def index():
    form = SubmissionForm()
    if request.method == 'POST':
        selectedValue = request.form.get('operator')
        new_num1 = request.form['number']
        new_num2 = request.form['number2']
        if form.validate() == False:
            return redirect(url_for('result', selectedValue="error"))
        else:
            response = make_response(
                redirect(url_for('result', selectedValue=selectedValue)))
            response.set_cookie('num1', new_num1)
            response.set_cookie('num2', new_num2)
            return response

    elif request.method == 'GET':
        return render_template('index.html', title='Home', form=form)
예제 #2
0
def saveEditSubmission(submission_id, course_id, item_id, redirect_option):
    """process submission form"""
    form = SubmissionForm(request.form)
    submission = {}
    if request.method == 'POST' and form.validate():
        submission['submitted'] = request.form['sub_time']
        submission['grade'] = request.form['grade']
        db_conn = db_pool.getconn()
        cursor = db_conn.cursor()
        cursor.execute(
            f"UPDATE submission SET grade = %s, submitted = %s "
            f"WHERE submission_id = %s; ",
            (submission['grade'],
             submission['submitted'],
             submission_id))
        db_conn.commit()
        cursor.close()
        db_pool.putconn(db_conn)

    if redirect_option == "student":
        return redirect(
            url_for(
                'student',
                student_id=item_id,
                course_id=course_id))
    elif redirect_option == "assignment":
        return redirect(
            url_for(
                'assignment',
                assignment_id=item_id,
                course_id=course_id))
    else:
        return redirect(
            url_for(
                'view_course',
                course_id=course_id))