예제 #1
0
def display_exercise(ex_id=None):
    if request.method == 'POST':
        profile = db_queries.get_profile(current_user.primary_email)
        user_id = profile.user_id
        file = request.files['file']
        if file:
            data = file.read()
            exercise = db_queries.get_exercise(ex_id)
            return render_template("exercise.html", exercise=exercise, data=data)
        else:
            text = request.form['code_editor']
            if text:
                filename = str(ex_id) + "-" + str(user_id) + ".cpp"
                file_handling.save(text, filename)
                session['fn'] = filename
                return redirect(url_for('display_results', ex_id=ex_id))
    exercise = db_queries.get_exercise(ex_id)
    exercise_list = db_queries.get_exercise_list()
    return render_template("exercise.html", exercise=exercise, leftPanelContent=exercise_list)
예제 #2
0
def db_edit_exercise(ex_id=None):
    msg = request.args.get('msg')
    if USER_PERMISSIONS is 'admin':
        form = forms.DBExerciseUploadForm(request.form)
        if request.method == 'GET':
            pre_data = db_queries.get_exercise(ex_id)
            form.title.data = pre_data.title
            form.category.data = pre_data.category
            form.difficulty.data = pre_data.difficulty
            form.content.data = pre_data.content
            return render_template('/admin/admin_exercise_edit.html', form=form, msg=msg)
        else:
            # update the db with the new results
            exercise = models.Exercises(form.title.data, form.difficulty.data, form.category.data, form.content.data)
            db_posts.add_exercise(exercise)
            return redirect(url_for('db_edit_exercise', ex_id=ex_id, msg='Exercise Updated'))
    return render_template(BAD_HTML)
예제 #3
0
def db_edit_exercise(ex_id=None):
    msg = request.args.get('msg')
    if USER_PERMISSIONS is 'admin':
        form = forms.DBExerciseUploadForm(request.form)
        if request.method == 'GET':
            pre_data = db_queries.get_exercise(ex_id)
            form.title.data = pre_data.title
            form.category.data = pre_data.category
            form.difficulty.data = pre_data.difficulty
            form.content.data = pre_data.content
            return render_template('/admin/admin_exercise_edit.html',
                                   form=form,
                                   msg=msg)
        else:
            # update the db with the new results
            exercise = models.Exercises(form.title.data, form.difficulty.data,
                                        form.category.data, form.content.data)
            db_posts.add_exercise(exercise)
            return redirect(
                url_for('db_edit_exercise',
                        ex_id=ex_id,
                        msg='Exercise Updated'))
    return render_template(BAD_HTML)