def account(): form = UpdateUserForm() if form.validate_on_submit(): print(form) if form.picture.data: username = current_user.username pic = add_profile_pic(form.picture.data, username) current_user.profile_image = pic current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('User Account Updated') return redirect(url_for('users.account')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email profile_image = url_for('static', filename='profile_pics/' + current_user.profile_image) return render_template('account.html', profile_image=profile_image, form=form)
def account(): form = UpdateUserForm() if form.validate_on_submit(): # if a new picture is uploaded if form.picture.data: username = current_user.username # pic is the path of the saved image pic = add_profile_pic(form.picture.data, username) current_user.profile_image = pic current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Account information updated!') return redirect(url_for('users.account')) elif request.method == 'GET': # grabbing current info of they have not submitted yet form.username.data = current_user.username form.email.data = current_user.email profile_image = url_for('static', filename=('profile_pics/' + current_user.profile_image)) return render_template('account.html', profile_image=profile_image, form=form)
def account_update(): form = UpdateUserForm() if form.validate_on_submit(): if form.profile_picture.data: username = current_user.username picture = add_profile_picture(form.profile_picture.data, username) current_user.profile_image = picture current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Your account has been updated') return redirect(url_for('users.account_update')) elif request.method == "GET": form.username.data = current_user.username form.email.data = current_user.email profile_image = url_for('static', filename='profile_images/' + current_user.profile_image) return render_template('account.html', profile_image=profile_image, form=form)
def account(): form = UpdateUserForm() if form.validate_on_submit(): form.update_user() elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email image_file = url_for('static', filename='profile_pics/' + current_user.image_file) return render_template('account.html', title='Account', form=form, image_file=image_file)
def account(): form = UpdateUserForm() if form.validate_on_submit(): current_user.username = form.username.data flash('Username Updated!') db.session.commit() return redirect(url_for('user.account')) elif request.method == "GET": form.username.data = current_user.username elif request.method == "POST": pic_num = request.form["profile-img"] current_user.profile_image = current_user.profile_image[: -5] + pic_num + '.png' db.session.commit() form.username.data = current_user.username profile_image = url_for('static', filename='img/' + current_user.profile_image) if (current_user.is_authenticated): notifs = Notifications.query.filter_by( user_id=current_user.id).order_by(Notifications.date.desc()).all() else: notifs = [] return render_template('account.html', profile_image=profile_image, form=form, notifs=notifs)