def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: random_hex = secrets.token_hex(8) _, f_ext = os.path.splitext(form.picture.data.filename) picture_fn = random_hex + f_ext picture_path = os.path.join(app.root_path, 'static/profile_pics', picture_fn) output_size = (125, 125) i = Image.open(form.picture.data) i.thumbnail(output_size) i.save(picture_path) current_user.picture = picture_fn 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('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.delete.data: #user = User.query.filter(current_user) posts = Posts.query.filter_by(user_id=current_user.id).all() flights = Flights.query.filter_by(user_id=current_user.id).all() accommodation = Accommodation.query.filter_by( user_id=current_user.id).all() activities = Activities.query.filter_by(user_id=current_user.id).all() for i in posts: db.session.delete(i) for i in flights: db.session.delete(i) for i in accommodation: db.session.delete(i) for i in activities: db.session.delete(i) db.session.delete(current_user) db.session.commit() logout_user() return redirect(url_for('register')) if form.validate_on_submit(): 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() return redirect(url_for('account')) elif request.method == 'GET': form.first_name.data = current_user.first_name form.last_name.data = current_user.last_name 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.delete.data: user_id = Users.query.filter_by(id=current_user.id).first() db.session.delete(user_id) review_id = Reviews.query.filter_by(user_id=None) for deleted in review_id: db.session.delete(deleted) db.session.commit() return redirect (url_for('home')) elif form.update.data: 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() return redirect(url_for('home')) elif request.method == 'GET': form.first_name.data = current_user.first_name form.last_name.data = current_user.last_name form.email.data = current_user.email postData = Reviews.query.filter_by(user_id=current_user.id).all() downloaded = Users.query.filter_by(id=current_user.id).first() downloadedpic = downloaded.photo #BUCKET_NAME = 'qpwoei-qpwoei' #KEY = '/tmp/About.png' #s3 = boto3.resource('s3') #download = s3.Bucket(BUCKET_NAME).download_file(KEY, '/tmp/File.png') return render_template('account.html', title='Account', form=form, downloadedpic=downloadedpic, account=postData)
def account(): form = UpdateAccountForm( ) #within the function, the form that is to be used is the UpdateAccountForm if form.validate_on_submit( ): #following block of code allows the user to enter new details to be updated current_user.first_name = form.first_name.data.capitalize() current_user.last_name = form.last_name.data.capitalize() current_user.email = form.email.data current_user.soc_name = form.SocietyName.data db.session.commit() #commits and saves the changes to the database return redirect(url_for('account')) elif request.method == 'GET': #GET request displays the current users details in the text boxes form.first_name.data = current_user.first_name form.last_name.data = current_user.last_name form.email.data = current_user.email lists = Society.query.filter_by(uni_id=current_user.uni_id).all( ) #Queries the database to present results in a dropdown format of all univeristy societies for the current user names = [] for i in range(int(len(lists))): temp = [lists[i].SocietyName, lists[i].SocietyName] names.append( temp ) #This method adds a the previous item (name) to the existing list of society names form.SocietyName.choices = names return render_template('account.html', title='Account', form=form, creator=current_user)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.delete.data: user_id = Users.query.filter_by(id=current_user.id).first() db.session.delete(user_id) review_id = Reviews.query.filter_by(user_id=None) for deleted in review_id: db.session.delete(deleted) db.session.commit() return redirect(url_for('home')) elif form.update.data: 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() return redirect(url_for('home')) elif request.method == 'GET': form.first_name.data = current_user.first_name form.last_name.data = current_user.last_name form.email.data = current_user.email postData = Reviews.query.filter_by(user_id=current_user.id).all() return render_template('account.html', title='Account', form=form, account=postData)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): current_user.username = form.username.data current_user.email = form.email.data db.session.commit() 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 myaccount(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_pictureUser(form.picture.data) current_user.userPic = picture_file current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Your account information was updated successfully!', 'success') return redirect(url_for('myaccount')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email return render_template('myAccount.html', title='My Account', form=form)
def account(): form = UpdateAccountForm() #import the form #if the form submitted fine if form.validate_on_submit(): 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() return redirect(url_for('home')) #else return the existing User's informations elif request.method == 'GET': form.first_name.data = current_user.first_name form.last_name.data = current_user.last_name form.email.data = current_user.email return render_template('account.html', title='Account', form=form)
def account(): form = UpdateAccountForm() update_fields = [form.first_name, form.last_name, form.email] if form.validate_on_submit(): 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() elif request.method == 'GET': form.first_name.data = current_user.first_name form.last_name.data = current_user.last_name form.email.data = current_user.email return render_template('account.html', title='Account', form=form, fields=update_fields)
def account(): form = UpdateAccountForm() posts = Posts.query.filter_by(user_id=current_user.id).all() if form.validate_on_submit(): 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() return redirect(url_for('account')) elif request.method == 'GET': form.first_name.data = current_user.first_name form.last_name.data = current_user.last_name form.email.data = current_user.email return render_template('account.html', title='Account', form=form, posts=posts)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): current_user.first_name = form.first_name.data current_user.last_name = form.last_name.data current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('You have successfully updated your details!') return redirect(url_for('account')) elif request.method == 'GET': form.first_name.data = current_user.first_name form.last_name.data = current_user.last_name form.username.data = current_user.username 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 succesfuly updated.', 'success') return redirect(url_for('account')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email avatar_img = url_for('static', filename='profile_pics/' + current_user.avatar_img) return render_template("account.html", title='Profile', avatar_img=avatar_img, 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='Account', image_file=image_file, form=form)
def account(): #Gets the form and it is passed on to the account html form = UpdateAccountForm() #Ensures that the entries as valid and commits them if form.validate_on_submit(): current_user.first_name = form.first_name.data current_user.last_name = form.last_name.data current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('You have successfully updated your details!') return redirect(url_for('account')) elif request.method == 'GET': form.first_name.data = current_user.first_name form.last_name.data = current_user.last_name form.username.data = current_user.username return render_template('account.html', title='Account', form=form)
def account(): form = UpdateAccountForm() if form.delete.data: temp = Users.query.filter_by(id=current_user.id).first() temp2 = Teams.query.filter_by(user_id=current_user.id).all() if temp2: for i in temp2: db.session.delete(i) db.session.delete(temp) db.session.commit() return redirect(url_for('register')) if form.validate_on_submit(): 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() return redirect(url_for('account')) elif request.method == 'GET': form.first_name.data = current_user.first_name form.last_name.data = current_user.last_name form.email.data = current_user.email return render_template('account.html', title='Account', form=form)
def account(): form = UpdateAccountForm() favou = Favou.query.filter_by(id=current_user.id).all() products = [] for favourite in favou: product = Products.query.filter_by( productcode=favourite.productcode).first() products.append(product) if form.validate_on_submit(): 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() return redirect(url_for('account')) elif request.method == 'GET': form.first_name.data = current_user.first_name form.last_name.data = current_user.last_name form.email.data = current_user.email return render_template('account.html', title='Account', form=form, products=products)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): current_user.first_name = form.first_name.data.capitalize() current_user.last_name = form.last_name.data.capitalize() current_user.email = form.email.data current_user.soc_name = form.SocietyName.data db.session.commit() return redirect(url_for('account')) elif request.method == 'GET': form.first_name.data = current_user.first_name form.last_name.data = current_user.last_name form.email.data = current_user.email lists = Society.query.filter_by(uni_id=current_user.uni_id).all() names = [] for i in range(int(len(lists))): temp = [lists[i].SocietyName, lists[i].SocietyName] names.append(temp) form.SocietyName.choices = names return render_template('account.html', title='Account', form=form, creator=current_user)
def preferences(): '''Update profile information''' form = UpdateAccountForm() if form.validate_on_submit(): if form.profile_picture.data: profile_image = save_profile_picture(form.profile_picture.data) current_user.image_file = profile_image current_user.username = form.username.data current_user.email = form.email.data current_user.location = form.location.data db.session.commit() db.session.remove() flash('Account updated successfully.', 'success') return redirect(url_for('auth.profile', _external=True)) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email form.location.data = current_user.location profile_image = url_for('static', filename='images/{}'.format( current_user.image_file)) return render_template('auth/preferences.html', image_file=profile_image, form=form)
def preferences(): '''Update profile information''' form = UpdateAccountForm() if form.validate_on_submit(): if form.profile_picture.data: pass # profile_image = save_profile_picture(form.profile_picture.data) # current_user.image_file = profile_image current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Account updated successfully.', 'success') return redirect(url_for('admin.profile')) elif request.method == 'GET': # Populate username and email upon page load. form.username.data = current_user.username form.email.data = current_user.email profile_image = url_for('static', filename='images/{}'.format( current_user.image_file)) return render_template('admin/preferences.html', image_file=profile_image, form=form)
def account(): """Using the UpdateAccountForm this pulls data from the Users table and applys this to the fields on screen. This data can then be changed and updated.""" form = UpdateAccountForm() if form.validate_on_submit(): 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() return redirect(url_for('account')) elif request.method == 'GET': form.first_name = current_user.first_name form.last_name = current_user.last_name form.email = current_user.email return render_template('account.html', title='Account Page', form=form)