def account(): form = UpdateAccountForm() form_delete = DeleteAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image_file = picture_file current_user.first_name = form.first_name.data current_user.last_name = form.last_name.data current_user.email = form.email.data db.session.commit() flash('You account has been updated!', 'success') return redirect(url_for('users.account')) elif request.method == 'GET': form.first_name.data = current_user.first_name.title() form.last_name.data = current_user.last_name.title() form.email.data = current_user.email if form_delete.validate_on_submit(): User.query.filter_by(email=current_user.email).delete() db.session.commit() flash('You account has been deleted!', 'success') return redirect(url_for('users.logout')) 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, form_delete=form_delete)
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 # taking care updates in the db automatically with current_user and sqlalchemy db.session.commit() flash('Your account has been updated', 'success') # redirecting here to avoid reloading page with meanless get/post operations return redirect(url_for('users.account')) elif request.method == 'GET': # default value for username and email in the form 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(): 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('users.account')) elif request.method=='GET': form.username.data=current_user.username form.email.data=current_user.email image_file=url_for('static',filename='profile_pictures/' + 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.picture.data: # if new image/picture is provided picture_file = save_picture(form.picture.data) current_user.image_file = picture_file # returns the name and ext of the image 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('users.account')) elif request.method == 'GET': # populate the form fields with current field data form.username.data = current_user.username form.email.data = current_user.email # unless changed current_user.image_file = default.png (in our case). filename= pics/default.png as specified from the models.py file image_file = url_for('static', filename='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(): 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 successfully updated", "success") return redirect(url_for("users.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(): if form.profile_picture.data: new_profile_picture = upload_profile_picture( form.profile_picture.data) current_user.profile_picture = new_profile_picture 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('users.account')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email profile_picture = url_for('static', filename="profile_picture/" + current_user.profile_picture) return render_template("account.html", title="Account", profile_picture=profile_picture, form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form_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(message="Details have been Updated", category="success") redirect(url_for('users.account')) ## This elif signifies when the account section was visited, ## the current user's username and email would be auto populated elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email image_file = url_for(endpoint='static', filename='profile_pics/' + current_user.image_file) print(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.picture.data: if current_user.image_file != 'default.jpg': os.remove(users.root_path + '/static/profile/' + current_user.image_file) 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'Your account credentials have been updated!', 'success') return redirect(url_for('users.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() #form object created for UpdateAccountForm #form.username.data refers to the data in the form in the username part of the form. current_user.username refers to the username of the current user in the database 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 #we are changing the current user's username in the database to whatever they entered the new username to be in the form. current_user.email = form.email.data db.session.commit() #adding user to database flash('your account info has been updated', 'success') return redirect( url_for('users.account') ) #this line of code prevents the "post/get redirect pattern" from happening elif request.method == 'GET': form.username.data = current_user.username #filing in the username box in the form with the user's current username form.email.data = current_user.email image_file = url_for('static', filename='profile_pics/' + current_user.image_file) #user's profile picture return render_template( 'account.html', title='Account', image_file=image_file, form=form ) #form=form is how we pass the form object to the html page in which we want to display the form
def account(): # grab the update account form form = UpdateAccountForm() # check to make sure fields are valid and save to db # on loading the page, populate the fields with the current data if form.validate_on_submit(): # if there was a picture uploaded, call our save_picture function if form.picture.data: picture_fn = save_picture(form.picture.data) current_user.image = picture_fn current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Your account information has been updated!', 'success') return redirect(url_for('users.account')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email image = url_for('static', filename='headshots/' + current_user.image) return render_template("account.html", title="Account", image=image, form=form)