Exemplo n.º 1
0
def edit_profile():
    """
    Fills out a form to change your different settings of your profile

    Return:
        Returns them to edit profile page again after filling out info
    """
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.country = form.country.data
        current_user.city = form.city.data
        current_user.date_of_birth = form.date_of_birth.data
        current_user.sex = form.sex.data
        current_user.weight = form.weight.data
        current_user.height = form.height.data
        current_user.workouts_per_week = form.workouts_per_week.data
        current_user.goal = form.goal.data
        current_user.activity_level = form.activity_level.data
        db.session.commit()
        flash('Your changes have been saved!')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.country.data = current_user.country
        form.city.data = current_user.city
        form.date_of_birth.data = current_user.date_of_birth
        form.sex.data = current_user.sex
        form.weight.data = current_user.weight
        form.height.data = current_user.height
        form.workouts_per_week.data = current_user.workouts_per_week
        form.goal.data = current_user.goal
        form.activity_level.data = current_user.activity_level
    return render_template('edit_profile.html', title='Edit Profile',
                           form=form)
Exemplo n.º 2
0
def edit():
    form = EditProfileForm(current_user.username)
    user = Users.query.filter_by(username=current_user.username).first()
    form.position.choices = [(g.id, g.position) for g in Positions.query.all()]
    if request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
        if current_user.first_name != None:
            form.first_name.data = current_user.first_name
        if current_user.last_name != None:
            form.last_name.data = current_user.last_name
        if current_user.patronym != None:
            form.patronym.data = current_user.patronym

    elif form.validate_on_submit():
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.position_id = form.position.data
        current_user.first_name = form.first_name.data
        current_user.last_name = form.last_name.data
        current_user.patronym = form.patronym.data
        db.session.commit()
        flash('Данные успешно сохранены')
        return redirect(url_for('edit'))
    return render_template('edit.html', form=form)
Exemplo n.º 3
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Ваши изменения сохранены')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me

    return render_template('edit_profile.html', title='Редактирование профиля', form=form)        
Exemplo n.º 4
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Your changes have been saved')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)