def user_info(user_id): user1 = User.query.filter_by(id=user_id).first() form = UpdateAccountForm() ''' if current_user then it can see the form if not current_user then only observe + after I've changed url_for('users.user_info', user=user.id) rather than user=user aforewriiten stuff started working ''' if form.validate_on_submit(): if form.pic.data: pic_file = save_pic(form.pic.data) current_user.image_file = pic_file current_user.username = form.username.data current_user.email = form.email.data current_user.country = form.country.data db.session.commit() flash('You has altered you account!', 'primary') return redirect(url_for('users.account')) elif request.method == 'GET': # if we don't send data + if we simply open page form.username.data = user1.username form.email.data = user1.email form.country.data = user1.country return render_template('user_info.html', title='User info', user=user1, 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 db.session.commit() flash('Your account has been updated', 'success') return redirect(url_for('main.account')) elif request.method == 'GET': form.username.data = current_user.username 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_url = save_picture(form.picture.data) current_user.image_file = picture_url current_user.username = form.username.data current_user.email = form.email.data current_user.save() 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 return render_template("users/account.html", title="Account", form=form)
def account(): update_form = UpdateAccountForm() if update_form.validate_on_submit(): if update_form.profile_pic.data: profile_pic = save_profile_pic(update_form.profile_pic.data) current_user.profile_pic = profile_pic current_user.username = update_form.username.data current_user.save() return redirect(url_for("users.account")) elif request.method == "GET": update_form.username.data = current_user.username profile_pic = url_for("static", filename="profile_pics/" + current_user.profile_pic) return render_template("users/account.html", title="Account", profile_pic=profile_pic, form=update_form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: file_name = save_picture(form.picture.data) current_user.image = file_name current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash("Your account has been updated", category="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=f"profile_pics/{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.save() flash(f'Your Account 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_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')) #to avoid the post get redirect pattern 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('Updated Success', '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.picture.data: PictureFile = SavePicture(form.picture.data) current_user.ImageFile = PictureFile 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 ImageFile = url_for('static', filename='ProfilePics/' + current_user.ImageFile) return render_template('account.html', title='Account', ImageFile=ImageFile, form=form)
def account(): form = UpdateAccountForm() # if the user wants to update account info 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') # don't use render_template here, so the browser doesn't submit the form twice return redirect(url_for('users.account')) # if user just navigates to account page 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.profileImage.data: imageFile = saveProfileImage(form.profileImage.data) current_user.imageFile = imageFile current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash("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 imageFile = url_for("static", filename="pictures/" + current_user.imageFile) return render_template('account.html', title="Account Profile", imageFile=imageFile, form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: current_user.image_file = save_picture(form.picture.data) # add() the database automatically 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': # displays current username in the forms 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.pic.data: pic_file = save_pic(form.pic.data) current_user.image_file = pic_file current_user.username = form.username.data current_user.email = form.email.data current_user.country = form.country.data db.session.commit() flash('Your acc now is altered!', 'warning') return redirect(url_for('users.account')) elif request.method == 'GET': # if we don't send data + if we simply open page form.username.data = current_user.username form.email.data = current_user.email form.country.data = current_user.country image_file = url_for('static', filename='pics/' + current_user.image_file) return render_template('account.html', title='Account', form=form, image_file=image_file)
def profile(): form = UpdateAccountForm() if form.validate_on_submit(): form_picture = form.picture.data if form_picture: picture_file = save_profile_picture(form_picture) if picture_file: current_user.profile_image = picture_file # else: USING FORM VALIDATE ON SUBMIT, so else with flash is not required # flash("Unsupported file type. Please upload .JPG or .PNG") # return redirect(url_for('users.profile')) if form.password.data and form.confirm_password.data: if form.password.data == form.confirm_password.data: hashed_pw = bcrypt.generate_password_hash(form.password.data) current_user.password = hashed_pw else: flash("Passwords don't match", 'error') return redirect(url_for('users.profile')) current_user.username = form.username.data #current user is derived from usermixin class in models, from loginmanager current_user.email = form.email.data db.session.commit() flash('Your account has been updated!', 'success') return redirect(url_for('users.profile')) elif request.method == 'GET': #adds the current users email and username on the form field form.username.data = current_user.username form.email.data = current_user.email profile_image = url_for('static', filename='profile_pics/' + current_user.profile_image) page = request.args.get( 'page', 1, type=int) #get page query '?page=xx' from the url bar user = User.query.filter_by(username=current_user.username).first() posts = Post.query.filter_by(author=user).order_by( Post.date_posted.desc()).paginate(per_page=15, page=page) return render_template('profile.html', title='Account', profile_image=profile_image, form=form, posts=posts)
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 # update users name and email current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Account has been updated!', 'success') return redirect(url_for('users.account')) elif request.method == 'GET': # populate the form with current username and email 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('users/account.html', title='Account', image_file=image_file, form=form)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: old_picture = current_user.image_file picture_file = save_picture(form.picture.data) current_user.image_file = picture_file #delete the old picture from the file system if is different than default if old_picture != 'default.jpg': old_picture_path = os.path.join(users.root_path, 'static/profile_pics', old_picture) try: os.remove(old_picture_path) except: pass 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_pics/' + current_user.image_file) return render_template('account.html', title='Account', image_file=image_file, form=form)