def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: file_name = save_profile_pic(form.picture.data) current_user.image_file = file_name db.session.commit() current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Your account has been updated!', 'success') return redirect(url_for('account')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email if current_user.image_file: profile_pic = url_for('static', filename='profile_pics/' + current_user.image_file) else: profile_pic = url_for('static', filename='profile_pics/default.jpg') return render_template('account.html', title="Account", profile_pic=profile_pic, form=form)
def account(): #Creating an instance form=UpdateAccountForm() #validate_on_submit() checks whether the is ready for either GET or POST request or both if form.validate_on_submit(): if form.picture.data: #getting the filename picture_file=save_picture(form.picture.data) current_user.image_file=picture_file #Changing and commiting the current user variable with the entered value current_user.username=form.username.data current_user.email=form.email.data db.session.commit() #A message displayed on success flash('Your Account has been updated !!!','success') #redirecting to the account page . Redirecting is done here to avoid Confirm Resubmission pop up message return redirect(url_for('account')) #To display the current username and email elif request.method =='GET': form.username.data=current_user.username form.email.data=current_user.email image_file=url_for('static',filename='img/'+current_user.image_file) return render_template('account.html',image_file=image_file,form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data) old_picture = current_user.image_file old_picture_path = os.path.join(app.root_path, 'static/profile_pics', old_picture) if os.path.exists(old_picture_path): os.remove(old_picture_path) else: print("The file does not exist " + old_picture) current_user.image_file = picture_file current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Your account has been updated!', 'success') return redirect(url_for('account')) 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', image_file=image_file, form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('your account is updated', 'primary') return redirect(url_for('account')) elif request.method == 'GET': form.username.data == current_user.username form.email.data == current_user.email return render_template('account.html', title='Account', form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image_file = picture_file current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Your Account is Updated', 'success') return redirect(url_for('account')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email image_file = url_for('static', filename = 'profile/' + current_user.image_file) return render_template('account.html', title='Account', image_file = image_file, form = form)
def account(): form=UpdateAccountForm() if form.validate_on_submit(): if form.image.data: photo=save_photo(form.image.data) current_user.image=photo current_user.username=form.username.data current_user.email=form.email.data db.session.commit() flash('Successfully Updated','success') return redirect(url_for('index')) elif request.method=='GET': form.username.data=current_user.username form.email.data=current_user.email image=url_for('static',filename='img/'+current_user.image) return render_template('account.html',title='Account',image=image,form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image_file = picture_file current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash(f"Account updated", "success") return redirect(url_for("account")) 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", image_file=image_file, form=form, title="Account")
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.image_file.data: current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Your account information has been successfully updated.', 'success') # Post/Redirect/Get Pattern. Basically, after successfully posting a request, # refreshing the page would cause a resubmission of the same successful # post request unless we finish our submission with a redirect to a get request. return redirect(url_for('account')) # Pre-populate form with user's current username and email elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email image_file = url_for('static', filename=f'profile_images/{current_user.image_file}' ) return render_template('account.html', title='My Account', image_file=image_file, form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image_file = picture_file #current user e set korle sqlalchemy emnei database e update kore dibe current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Your account has been updated!', 'success') return redirect(url_for('account')) 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', image_file=image_file, form=form)
def account(): # form to update account form = UpdateAccountForm() # form to update photo if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image_file = picture_file current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Your account has been updated!', 'success') return redirect(url_for('account')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email # image location in static folder image_file = url_for('static', filename='photos/' + current_user.image_file) # render to account.html template, variable form, image_file return render_template('account.html', title='Account', image_file=image_file, form=form)