예제 #1
0
def profile():
    text = db_queries.get_page_content('profile')
    if request.method == 'POST':
        #if the submit button was hit, loads the information into the form
        form = ProfileForm(request.form)
        if form.validate():
            #sends the user to the profile/edit profile page with updated information
            # if is_profile_changed(form):
            #     #user profile has been changed, update the database
            db_posts.update_profile(form, current_user.primary_email)
            text = db_queries.get_page_content('profile')
            profile = db_queries.get_profile(current_user.primary_email)
            return render_template("my_profile.html", text=text, profile=profile, form=form, leftProfileContent=profile)
        else:
            profile = db_queries.get_profile(current_user.primary_email)
            return render_template("my_profile.html", text=text, profile=profile, form=form, leftProfileContent=profile)

    #sends the user to the profile/edit profile page for GET methods
    profile = db_queries.get_profile(current_user.primary_email)
    form = ProfileForm(obj=profile)
    return render_template("my_profile.html", text=text, profile=profile, form=form, leftProfileContent=profile)
예제 #2
0
def add_exercise_statistic(primary_email, exercise_id, time, memory, passed):
    #create or modify a profiles statistic on a particular exercise
    profile_id = db_queries.get_profile(primary_email).profile_id
    statistic = db_queries.get_exercise_statistic(profile_id, exercise_id)
    if statistic:
        #update statistic db entry
        statistic.attempts += 1
        statistic.time = time
        statistic.memory = memory
        statistic.passed = passed
        db.session.commit()
    else:
        #create new statistic db entry
        statistic = models.Statistics(profile_id, exercise_id, time, memory, passed)
        statistic.attempts = 1
        db.session.add(statistic)
        db.session.commit()
예제 #3
0
def add_exercise_statistic(primary_email, exercise_id, time, memory, passed):
    #create or modify a profiles statistic on a particular exercise
    profile_id = db_queries.get_profile(primary_email).profile_id
    statistic = db_queries.get_exercise_statistic(profile_id, exercise_id)
    if statistic:
        #update statistic db entry
        statistic.attempts += 1
        statistic.time = time
        statistic.memory = memory
        statistic.passed = passed
        db.session.commit()
    else:
        #create new statistic db entry
        statistic = models.Statistics(profile_id, exercise_id, time, memory,
                                      passed)
        statistic.attempts = 1
        db.session.add(statistic)
        db.session.commit()
예제 #4
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)