Пример #1
0
def get_ranking():
    if not ModuleAPI.can_read('challenge'):
        abort(403)

    ranking = ChallengeAPI.get_ranking()

    return jsonify(ranking=[user.serialize for user in ranking])
Пример #2
0
def view_list():
    challenge = Challenge()
    form = init_form(ChallengeForm, obj=challenge)

    can_write = role_service.user_has_role(current_user, Roles.CHALLENGE_WRITE)

    challenges = ChallengeAPI.fetch_all_challenges_user(
        current_user.id, include_not_open=can_write)

    approved_challenges = \
        ChallengeAPI.fetch_all_approved_challenges_user(current_user.id)
    user_points = ChallengeAPI.get_points(current_user.id)
    if user_points is None:
        user_points = 0

    ranking = ChallengeAPI.get_ranking()

    ranking_place = 0
    last_score = -1
    for r in ranking:
        if last_score == -1 or last_score > r.points:
            ranking_place += 1
            last_score = r.points

        r.place = ranking_place

    challenge_description = ChallengeAPI.get_challenge_description()

    return render_template('challenge/dashboard.htm', challenges=challenges,
                           user_points=user_points, ranking=ranking,
                           approved_challenges=approved_challenges, form=form,
                           challenge_description=challenge_description,
                           can_write=can_write)
Пример #3
0
def view_list(page=1):
    if not ModuleAPI.can_read('challenge') or current_user.is_anonymous:
        return abort(403)

    print((app.config['SQLALCHEMY_DATABASE_URI']))

    challenge = Challenge()
    form = ChallengeForm(request.form, challenge)

    challenges = ChallengeAPI.fetch_all_challenges_user(current_user.id)
    approved_challenges = \
        ChallengeAPI.fetch_all_approved_challenges_user(current_user.id)
    user_points = ChallengeAPI.get_points(current_user.id)
    ranking = ChallengeAPI.get_ranking()

    challenge_description = ChallengeAPI.get_challenge_description()

    return render_template('challenge/dashboard.htm', challenges=challenges,
                           user_points=user_points, ranking=ranking,
                           approved_challenges=approved_challenges, form=form,
                           challenge_description=challenge_description)
Пример #4
0
def get_ranking():
    ranking = ChallengeAPI.get_ranking()

    return jsonify(ranking=[user.serialize for user in ranking])