def running_10_km():
    session_data = Session()
    check_profile_verified(session_data)
    db_query = Queries()
    position = db_query.get_position_best_run(current_user.id, Competition.Run10km)
    return render_template("running.html", title="Running-10", distance='10km',
                           position=ordinal(position), session_data=session_data)
def integrations():
    db_query = Queries()
    session_data = Session()
    check_profile_verified(session_data)
    favorite_activities = db_query.get_user_favorite_activity(current_user.id)
    return render_template("integrations.html", title='Integrations', session_data=session_data,
                           favorite_activities=favorite_activities)
def faq():
    if current_user.is_authenticated:
        session_data = Session()
        check_profile_verified(session_data)
        return render_template("faq.html", title="Frequently Asked Questions", session_data=session_data)
    else:
        return render_template("faq_public.html", title="Frequently Asked Questions")
def cycling():
    session_data = Session()
    check_profile_verified(session_data)
    db_query = Queries()
    total_distance = db_query.get_total_distance_by_user_on_bike(current_user.id)
    position = db_query.get_position_total_distance_on_bike(current_user.id)
    return render_template("cycling.html", title="Cycling",
                           total_distance=total_distance, position=ordinal(position),
                           session_data=session_data)
def home():
    session_data = Session()
    db_query = Queries(credit=True)
    add_activity_form = AddActivityForm()
    if add_activity_form.validate_on_submit():
        filename = secure_filename(add_activity_form.file.data.filename)
        path = os.path.join(__file__, os.pardir)
        add_activity_form.file.data.save(os.path.join(
            os.path.abspath(path), current_app.config['UPLOAD_FILE_DIR'], filename))

        if add_activity_form.activity.data == ActivityType.Ride.name:
            a_type = ActivityType.Ride
        elif add_activity_form.activity.data == ActivityType.Run.name:
            a_type = ActivityType.Run
        else:
            a_type = ActivityType.Walk

        activity = current_app.config['PROCESSOR'].process_input_data(filename)
        current_app.config['PROCESSOR'].landing_cleanup(filename)
        distance = activity[0]
        seconds = activity[1].total_seconds()
        start_time = activity[2]

        if distance == 0:
            session_data.warning('Activity of zero distance ignored.')
        elif start_time is None:
            if a_type == ActivityType.Run:
                a_type = ActivityType.Walk
            start_time = datetime.datetime.now().replace(microsecond=0)
            full_time = datetime.time()
            avg_time = datetime.time()
            new_activity = Activity(datetime=start_time, distance=distance, duration=full_time,
                                    average_duration_per_km=avg_time, type=a_type)
            db_query.save_new_user_activities(current_user.id, new_activity)
            session_data.info(str(a_type) + ' activity of ' + str(distance) + ' km added.')
        else:
            avg_seconds = round(seconds / distance)
            full_time = (datetime.datetime(2000, 1, 1, 0) + datetime.timedelta(seconds=seconds)).time()
            avg_time = (datetime.datetime(2000, 1, 1, 0) + datetime.timedelta(seconds=avg_seconds)).time()
            new_activity = Activity(datetime=start_time, distance=distance, duration=full_time,
                                    average_duration_per_km=avg_time, type=a_type)
            db_query.save_new_user_activities(current_user.id, new_activity)
            session_data.info(str(a_type) + ' activity of ' + str(distance) + ' km added.')

        return redirect(url_for('main.home'))

    check_profile_verified(session_data)
    total_foot = db_query.get_total_distance_by_user_on_foot(current_user.id) or 0
    total_bike = db_query.get_total_distance_by_user_on_bike(current_user.id) or 0
    total_credit = None
    if current_user.type == UserType.Student:
        total_credit = round(total_foot + total_bike / 2, 2)

    return render_template("personal_dashboard.html", title='Home', form=add_activity_form,
                           total_foot=total_foot, total_bike=total_bike, total_credit=total_credit,
                           season=db_query.SEASON_COMPETITION, season_credit=db_query.SEASON_CREDIT,
                           session_data=session_data)
def matfyz_challenges():
    db_query = Queries()
    checkpoints = db_query.get_challenge_parts_to_display()
    checkpoints_enriched = []
    order = 1
    for (dist, place) in checkpoints.items():
        checkpoints_enriched.append({'order': order, 'dist': dist, 'place': place})
        order = order + 1
    current_checkpoint = db_query.get_current_challenge_part()

    if current_user.is_authenticated:
        session_data = Session()
        check_profile_verified(session_data)
        return render_template("matfyz_challenges.html", title='Matfyz Challenges',
                               checkpoints=checkpoints_enriched, current_checkpoint=current_checkpoint,
                               session_data=session_data)
    else:
        return render_template("matfyz_challenges_public.html", title='Matfyz Challenges',
                               checkpoints=checkpoints_enriched, current_checkpoint=current_checkpoint)
Beispiel #7
0
def user_settings():
    session_data = mast.session.Session()
    update_profile_form = UpdateProfileForm(name='up')
    display_update_profile_form = 'none'
    change_password_form = ChangePasswordForm(name='chp')
    display_change_password_form = 'none'
    if request.method == 'POST':
        if request.form['submit'] == 'Update profile':
            update_profile_form = UpdateProfileForm(request.form)
            if update_profile_form.validate():
                current_user.complete_profile(
                    first_name=update_profile_form.first_name.data.strip(),
                    last_name=update_profile_form.last_name.data.strip(),
                    age=update_profile_form.age.data,
                    sex=update_profile_form.sex.data,
                    shirt_size=update_profile_form.shirt_size.data,
                    user_type=update_profile_form.user_type.data,
                    ukco=update_profile_form.ukco.data.strip(),
                    display_name=update_profile_form.display_name.data.strip(),
                    anonymous=update_profile_form.competing.data)

                if authenticate_via_sis(name=current_user.first_name,
                                        surname=current_user.last_name,
                                        login=None,
                                        uk_id=current_user.uk_id,
                                        is_employee=current_user.type.value):
                    current_user.verify()
                    session_data.info('Your profile has been been verified.')
                    return redirect(url_for('users.user_settings'))
                else:
                    session_data.warning(
                        'Your profile has not been been verified.<br />' +
                        'We will verify your profile in a few days if you are sure with your data.'
                    )

            else:
                # Keep the form visible if it contains errors
                display_update_profile_form = 'block'
        elif request.form['submit'] == 'Update password':
            change_password_form = ChangePasswordForm(request.form)
            if change_password_form.validate():
                hashed_password = bcr.generate_password_hash(
                    change_password_form.password.data).decode('UTF-8')
                current_user.change_password(hashed_password)
                session_data.info('Your password has been changed.')
                return redirect(url_for('users.user_settings'))
            else:
                # Keep the form visible if it contains errors
                display_change_password_form = 'block'

    # For GET and after POST method
    check_profile_verified(session_data)

    for key, data in update_profile_form.data.items():
        if key in ["first_name", "last_name", "display_name"]:
            update_profile_form[key].data = current_user.__getattr__(key) or ''

    update_profile_form.ukco.data = current_user.uk_id or ''
    update_profile_form.age.data = current_user.age.value if current_user.age else None
    update_profile_form.sex.data = current_user.sex.value if current_user.sex else None
    update_profile_form.shirt_size.data = current_user.shirt_size or None
    update_profile_form.user_type.data = current_user.type.value if current_user.type else None
    update_profile_form.competing.data = current_user.anonymous or None

    return render_template(
        "user_settings.html",
        title='User Settings',
        profile=current_user,
        update_profile_form=update_profile_form,
        display_update_profile_form=display_update_profile_form,
        change_password_form=change_password_form,
        display_change_password_form=display_change_password_form,
        session_data=session_data)
def about_competitions():
    session_data = Session()
    check_profile_verified(session_data)
    return render_template("about_competitions.html", title='About Competitions', session_data=session_data)