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 successfuly 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) #20:13 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('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='Acount', image_file=image_file, form=form)
def account(): #set the image file we want to pass to the template image_file = url_for('static',filename='profile_imgs/' + current_user.image_file) #instance of the UpdateAccountForm that exist in forms.py and parsing through render_template as a variable form = UpdateAccountForm() if form.validate_on_submit(): '''if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image_file= picture_file''' #fetching username and email from db current_user.username = form.username.data current_user.email = form.email.data #commit to database 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 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: current_user.image = save_image(form.image.data) 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('account')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email file_image = url_for('static', filename=f'pictures/{current_user.image}') return render_template('account.html', title='Acount', form=form, file_image=file_image)
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('Info Updated!', 'success') return redirect(url_for('account')) elif request.method == 'GET': form.username.data = current_user.username #this is done to pollute the field with current username & password 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: #form.picture will just return the input type that it is expecting. it doesn't show if there actually is any data in there. So, we need to do 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": # Until the request is POST (button click), there will be the information displayed 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(): #nous devons importer dabord updateaccount pour faire cette demarche fromflasklogin.... form = UpdateAccountForm() if form.validate_on_submit(): # si notre form est valide alors on peut faire des changements if form.picture.data: # pour sil ya une photo upload # picture_file = save_picture(form.picture.data) # save our picture current_user.image_file = picture_file current_user.username = form.username.data # le nouvel user sera envoyer a nos base de donnnees current_user.email = form.email.data db.session.commit() # ici nous confirmons notre changement flash('Your account has been updated!', 'success') return redirect(url_for('account')) # apres cela sa nous remets sur notre page account et on peut revoir sa elif request.method == 'GET': # Get alors on peut populate sur nos data directement dans la Db comme le chn es drct #Get nous prenonsles informations depuis notre base de donnnees form.username.data = current_user.username form.email.data = current_user.email image_file = url_for('static', filename='profile_pics/' + current_user.image_file) #image of our account #where users will put the imagefile return render_template('account.html', title='Account', image_file=image_file, form=form)
def account(): page = request.args.get('page', 1, type=int) posts = Post.query.order_by(Post.date_posted.desc()).paginate(page=page, per_page=3) 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') 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, posts = posts, user = current_user)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.image.data: picture = save_image(form.image.data) current_user.profile_picture = picture current_user.username = form.username.data current_user.email = form.email.data current_user.bio = form.bio.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.bio.data = current_user.bio profile_pic = url_for( "static", filename=f"profile_pics/{current_user.profile_picture}") return render_template("account.html", title="Account", profile_pic=profile_pic, form=form)
def update_info(): form = UpdateAccountForm() image_file = url_for('static', filename='profile_pics/' + current_user.image_file) if form.validate_on_submit(): #checking if profile picture is updated if form.picture.data: picture_fn = save_picture(form.picture.data) current_user.image_file = picture_fn #update the user info in database current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Account info 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_info.html', title='update info', form=form, image_file=image_file)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): current_user.username = form.username.data current_user.email = form.email.data current_user.school = form.school.data current_user.college = form.college.data current_user.company1 = form.company1.data current_user.company2 = form.company2.data db.session.commit() flash('Account Details Updated!','success') return redirect(url_for('account')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email form.school.data = current_user.school form.college.data = current_user.college form.company1.data = current_user.company1 form.company2.data = current_user.company2 return render_template('account.html', title='Account', form=form, lat=float(get_coordinates()[0:7]), lon=float(get_coordinates()[7:]))
def account(): page = request.args.get('page', 1, type=int) last_donation = Donation.query.order_by(Donation.id.desc()).first() pastor = Pastor.query.order_by(Pastor.id.desc()).first() church = Church.query.order_by(Church.id.desc()).first() sermon = Sermon.query.order_by(Sermon.id.desc()).first() quote = Quote.query.order_by(Quote.id.desc()).first() sermons = Sermon.query.order_by(Sermon.id.desc()).paginate(page=page, per_page=6) upevents = UpEvent.query.order_by(UpEvent.id.desc()).paginate(page=page, per_page=6) donations = Donation.query.order_by(Donation.id.desc()).paginate( page=page, per_page=4) p_program = Past_P.query.order_by(Past_P.id.desc()).paginate(page=page, per_page=4) post = Post.query.order_by(Post.id.desc()).first() posts = Post.query.order_by(Post.id.desc()).paginate(page=page, per_page=6) upevent = UpEvent.query.order_by(UpEvent.id.desc()).first() per_t = (last_donation.received / last_donation.target) * 100 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('main/account.html', title='Account', image_file=image_file, form=form, posts=posts)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture( form.picture.data ) # pictured data from form is passed into the save function current_user.image_file = picture_file #the file name is returned and equated to current user image current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash(f"Your Account has been Updated Successfully", '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_file = save_picture(form.picture.data) if current_user.image_file != "default.jpg": delete_old_picture(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() 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(): print(form.picture.data) if form.picture.data: profile_pic = save_picture(form.picture.data) print(profile_pic) current_user.image_file = profile_pic current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Details updated successfully', '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)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): # Validation & setting the picture-path if form.picture.data: pic_file = save_picture(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('Your Account has been updated!', 'info') # Due to post-get-redirect pattern 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_pix/' + 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(): # check if there is any profile picture. if form.picture.data: # set the profile picture. # save picture() is the function picture_file = save_picture(form.picture.data) current_user.image_file = picture_file # As the data is entered into form So that's why its form.username.data 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': # Populate the fields with the current_user data 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: #set user's profile Picture picture_file = save_picture(form.picture.data) current_user.image_file = picture_file # will update account info current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Your Account has been Updated!', 'sucess') return redirect(url_for('account')) elif request.method == 'GET': # checks if updated info already belongs to another user 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(): account_update_form = UpdateAccountForm() # Logic for updating user info once the update account form is submitted if account_update_form.validate_on_submit(): # Checking if there is any picture data, if there is we update the # existing profile picture data if account_update_form.picture.data: picture_file = save_picture(account_update_form.picture.data) current_user.image_file = picture_file current_user.username = account_update_form.username.data current_user.email = account_update_form.email.data db.session.commit() flash('Your account has been updated!', 'success') return redirect(url_for('account')) elif request.method == 'GET': account_update_form.username.data = current_user.username account_update_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=account_update_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') 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) # cek profile picturenya ada atau tidak if os.path.exists('flaskblog' + image_file): pass else: # kalo gaada prof pic, set ke default current_user.image_file = 'default.jpg' db.session.commit() 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 current_user.name = form.name.data current_user.creditcard = form.creditcard.data current_user.expdate = form.expdate.data current_user.cvc = form.cvc.data current_user.bill_address = form.bill_address.data current_user.bill_zip = form.bill_zip.data db.session.commit() flash('Your account has been updated!', 'success') return redirect(url_for('account')) elif request.method == 'GET': try: form.username.data = current_user.username form.email.data = current_user.email form.name.data = current_user.name form.creditcard.data = current_user.creditcard form.expdate.data = current_user.expdate form.cvc.data = current_user.cvc form.bill_address.data = current_user.bill_address form.bill_zip.data = current_user.bill_zip except: 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: # set user profile picture picture_file = save_picture(form.picture.data) current_user.image_file = picture_file #image_file is in model varaible 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') ) #redirect or [email protected]("/act falls into another post request, 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: # First, delete existing profile picture if not default if current_user.image_file != "default.jpg": os.remove( os.path.join(app.root_path, "static/profile_pics", current_user.image_file)) current_user.image_file = save_picture(form.picture.data) 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(): if form.picture.data: picture_file = save_picture(form.picture.data) current_user.img_file = picture_file db.session.commit() current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Malumotlaringiz uzgartrildi sucsseeeessss ', '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', form=form, m=m, m1=m1, m2=m2, m3=m3, y=y)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: # if update image 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') # post - get - redirect form # if we render_template, it reloads without saving 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', # directory filename='profile_pics/' + current_user.image_file) return render_template('account.html', title='Account', image_file=image_file, form=form)
def acc_edit(): form = UpdateAccountForm() if form.validate_on_submit(): print(form.picture.data) if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image_file = picture_file print(current_user.image_file) print(current_user.image_file) print(current_user.image_file) print(current_user.image_file) print(current_user.image_file) print(current_user.image_file) print(current_user.image_file) print(current_user.image_file) current_user.password = form.password.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.password.data = current_user.password form.email.data = current_user.email return render_template("acc-update.html", form=form)
def account(): form = UpdateAccountForm() # validating and then updating the databse with new form data 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')) # if the page is normaly accessed then existing user data is shown 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('account')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email page = 1 posts = Post.query.filter_by(author=current_user)\ .order_by(Post.date_posted.desc())\ .paginate(page=page, per_page=5) comments = Comment.query.filter_by(creator=current_user)\ .order_by(Comment.date_posted.desc())\ .paginate(page=page, per_page=5) user = User.query.filter_by(username=current_user.username).first_or_404() if posts.total == 0: last_post = False else: last_post = True 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, comments=comments, posts=posts, user=user, last_post=last_post)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data, 125)['picture_fn'] current_user.image_file = picture_file current_user.username = form.username.data current_user.email = form.email.data db.session.commit() logging.info("Account updated for User " + str(current_user.username) + \ ' at ' + strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ' from ' + request.remote_addr) 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 logging.info("Account info requested for " + str(current_user.username) + \ ' at ' + strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ' from ' + request.remote_addr) 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)
output_size = (125, 125) i = Image.open(form_picture) i.thumbnail(output_size) i.save(picture_path) >>>>>>> aa9492e81b5ecb5377d0ca16eabb874b549f10f1 return picture_fn @app.route("/account", methods=['GET', 'POST']) @login_required def account(): <<<<<<< HEAD form = UpdationForm() ======= form = UpdateAccountForm() >>>>>>> aa9492e81b5ecb5377d0ca16eabb874b549f10f1 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='Account',