def account(): form = UpdateAccountForm() if request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email form.brief_info.data = current_user.brief_info if form.validate_on_submit(): # Strip() function down here ensures that NO whitespace will be prepended or appended to the fields's value is_info_changed = (current_user.username != form.username.data.strip() or current_user.email.strip() != form.email.data or current_user.brief_info != form.brief_info.data.strip() or form.img.data) if is_info_changed: current_user.username = form.username.data.strip() current_user.email = form.email.data.strip().lower() current_user.brief_info = form.brief_info.data.strip() if form.img.data: current_user.img_file = save_picture(form.img.data) clean_old_pictures() db.session.commit() flash('Account information has been updated successfully!', 'success') else: flash('Nothing was updated, hence, nothing changed!', 'info') return redirect(url_for('account')) return render_template('account.html', page_title='Account', img_file_src=get_img_src(), form=form)
def update_account(): image_file = url_for('static', filename='profile_pics/' + current_user.image_file) form = UpdateAccountForm() if form.validate_on_submit(): # check if user already have account if form.picture.data: pic_path = os.path.join(app.root_path, 'static/profile_pics/', current_user.image_file) try: os.remove(pic_path) except: pass picture_fn = save_picture(form.picture.data) current_user.image_file = picture_fn current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash(f'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 return render_template('update_account.html', title='update_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 if form.image_file.data: image_file = save_image_file(form.image_file.data) current_user.image_file = image_file db.session.commit() flash('Your account has been updated.', 'success') return redirect(url_for('account')) 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: # saving the picture from form field picture_file = save_picture(form.picture.data) # passing image to current user ()image file is a attribute below current_user.image_file = picture_file # Committing new changes current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Your account has been updated!', 'success') # here after making changes we are redirecting the page to get an updated response from server # i.e we are sending GET request to the server if we reload it using render_temp we will send POST req # which is not good return redirect(url_for('account')) elif request.method == 'GET': #retrieving new changes 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', category='success') # 'success' is boostrap return redirect( url_for('account')) # This is needed to avoid POST again # Show current data in form elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email image_file = os.path.split(current_user.image_file)[-1] image_file = os.path.join('static', 'profile_pics', 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: pic_file = save_pic(form.picture.data) current_user.image_file = pic_file current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Account updated Successfully', 'success') 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(): 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=current_user.image) return render_template('account.html', title='Accoont', 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('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='My 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(f'Your account has been updated', 'success') # Second arg is bootstrap category class 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(): if form.picture.data: picture_file = save_picture(form.picture.data) old_picture_path = os.path.join(app.root_path, 'static/profile_pics', current_user.image_file) current_user.image_file = picture_file current_user.username = form.username.data current_user.email = form.email.data db.session.commit() if os.path.isfile(old_picture_path): os.remove(old_picture_path) 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(): if form.picture.data: picture_name = save_picture(form.picture.data) current_user.image_file = picture_name current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Account details have 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='images/' + current_user.image_file) return render_template( 'account.html', title="Account", image_file=image_file, form=form ) #user name is bind directly to html uing current_user module
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: filename = save_picture(form.picture.data) current_user.image_file = filename current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash("Account Updated Successfully", "success") return redirect("account") elif request.method == "GET": form.username.data = current_user.username form.email.data = current_user.email image_file = url_for("static", filename=f"profile_pic/{current_user.image_file}") return render_template("account.html", image_file=image_file, form=form)
def account(): form = UpdateAccountForm() image_file = url_for("static", filename="profile_pics/" + current_user.image_file) if form.validate_on_submit(): # Check if there is any picture data since this isn't a required field 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("Account Updated!!!", "success") 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", current_user=current_user, image_file=image_file, title="Account", form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: pic_fn = save_picture(form.picture.data) current_user.image_file = pic_fn current_user.username = form.username.data current_user.email = form.email.data current_user.aboutme = form.aboutme.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 form.aboutme.data = current_user.aboutme image_file = url_for('static', filename='profile_pics/' + current_user.image_file) # user = User.query.filter_by(username=).first_or_404() return render_template('account.html', title="Account", image_file=image_file, form=form)