Beispiel #1
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
    return render_template('edit_profile.html', title='Edit Profile', form=form)
def edit_profile(request):
    if request.method == 'POST':
        form = EditProfileForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return redirect('/profile')
    else:
        form = EditProfileForm(instance=request.user)
        args = {'form': form}
        return render(request, 'accounts/edit_profile.html', args)
Beispiel #3
0
def edit_profile(id=None):
    session['url'] = 'edit_profile'
    form = EditProfileForm()
    user = current_user
    id = id or request.args.get("id")
    if id:
        if current_user.id != id and not current_user.is_admin():
            flash("you don't have the permission to edit this profile")
            return redirect(url_for('find_by_user', id=id))
        user = user = User.query.filter_by(id=id).first()

    if request.method == 'GET':
        form.center_name.data = user.center_name
        form.email.data = user.email
        form.center_website.data = user.center_website
        form.center_description.data = user.center_description

    if form.validate_on_submit():
        print(user)
        f = form.center_photo.data
        if f:
            filename = secure_filename(f.filename)
            f.save(os.path.join(app.config['USER_PHOTO_UPLOAD_PATH'],
                                filename))
            user.center_photo_path = filename

        user.email = form.email.data
        user.center_website = form.center_website.data
        user.center_name = form.center_name.data
        user.center_description = form.center_description.data

        db.session.commit()

        return redirect(url_for('find_by_user', id=user.id))

    return render_template('edit_profile.html', form=form)