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) dri_id=current_user.id all_req = MyRequests.query.filter_by(Rdriverid=dri_id).all() print "testing-------" # print all_req[0].Ruserid print "done-------" as_driver= Drivers.query.filter_by(userid=dri_id).all() past_driver=[] coming_driver=[] for x in as_driver : datetime_object = datetime.strptime(x.Date, '%Y-%m-%d') print "object datetime" print datetime_object print "Aj ki date" print datetime.now() if datetime_object < datetime.now() : past_driver.append(x) print x.Date else : coming_driver.append(x) print "baad ki date ----" as_rider = Riders.query.filter_by(userid=dri_id).all() as_rider_details=[] for detail in as_rider : as_rider_details.append(Drivers.query.filter_by(BookingId=detail.BookingId).first()) past_rider=[] coming_rider=[] for x in as_rider_details : datetime_object = datetime.strptime(x.Date, '%Y-%m-%d') print "object datetime" print datetime_object print "Aj ki date" print datetime.now() if datetime_object < datetime.now() : past_rider.append(x) print x.Date else : coming_rider.append(x) print "baad ki date ----" return render_template('account.html', title='Account', image_file=image_file, form=form,all_req=all_req, past_driver=past_driver,coming_driver=coming_driver, past_rider=past_rider,coming_rider=coming_rider)
def account(): """ This is the view for updating the account information of the authenticated user """ form = UpdateAccountForm() # perform actions when the form is submitted if form.validate_on_submit(): # checking if the form contains a picture file if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image_file = picture_file # changing the current user details with the form 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')) # performs action if the form method is get elif request.method == 'GET': # setting the form data with the user data from the database 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, user=True) current_user.image_file = picture_file current_user.username = form.username.data current_user.email = form.email.data current_user.address = form.address.data current_user.state = form.state.data current_user.pincode = form.pincode.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 form.address.data = current_user.address form.state.data = current_user.state form.pincode.data = current_user.pincode if current_user.image_file[0] == 'C': image_file = url_for('static', filename='user_profile/' + 'defalt.png') else: image_file = url_for('static', filename='user_profile/' + current_user.image_file) return render_template('profile.html', title='Account', image_file=image_file, form=form)
def account(): form = UpdateAccountForm() for id in db1: b = db1.get(id) if (b['name'] == session['name']): break for id in db2: b1 = db2.get(id) if (b1['author'] == session['name']): break if form.validate_on_submit(): b['name'] = form.username.data b['email'] = form.email.data b['designation'] = form.designation.data b['phone'] = form.phone.data b['linkedin'] = form.linkedin.data b1['author'] = form.username.data db1.save(b) db2.save(b1) session['name'] = b['name'] session['email'] = b['email'] flash('Your account has been updated!', 'success') return redirect(url_for('account')) elif request.method == 'GET': form.username.data = b['name'] form.email.data = b['email'] form.designation.data = b['designation'] form.phone.data = b['phone'] form.linkedin.data = b['linkedin'] image_file = url_for('static', filename='profile.jpg') return render_template('account.html', title='Account', image_file=image_file, form=form)
def account(): form = UpdateAccountForm() cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor) if 'loggedin' not in session: return render_template('login.html', form=form) if form.validate_on_submit(): # cursor.execute('SELECT * FROM wt_user WHERE id = %s', [session['id']]) # print(accountMySQL2.format(form.age.data, form.gender.data, form.bodyweight.data, form.height.data, session['id'])) print(form.age.data, form.gender.data, form.bodyweight.data, form.height.data, session['id']) cursor.execute( accountMySQL2.format(form.age.data, form.gender.data, form.bodyweight.data, form.height.data, session['id'])) mysql.connection.commit() flash( "=====================Personal Information updated========================" ) return render_template('account.html', title='Account', form=form) cursor.execute(accountMySQL.format(session['id'])) account = cursor.fetchone() # Show the profile page with account info form.email.data = account['email'] form.firstname.data = account['first_name'] form.age.data = account['age'] form.gender.data = account['gender'] form.bodyweight.data = account['weight_pound'] form.height.data = account['height_cm'] cursor.execute(accountMySQL3.format(session['id'])) proteinAmount = cursor.fetchone() cursor.execute(accountMySQL4.format(session['id'])) workoutdates = cursor.fetchone() notification1 = False if proteinAmount is not None and workoutdates is not None: if workoutdates['CL'] >= 3: # Men: Lean body mass = (0.32810 × W) + (0.33929 × H) − 29.5336 # women: Lean body mass = (0.29569 × W) + (0.41813 × H) − 43.2933 if account['gender'] == "female": womenLeanbodymass = ( (0.32810 * account['weight_pound']) + (0.33929 * account['height_cm']) - 29.5336) * 1000 if (womenLeanbodymass * 2.2) > proteinAmount["PA"]: notification1 = True elif account['gender'] == "male": MenLeanbodymass = ( (0.29569 * account['weight_pound']) + (0.41813 * account['height_cm']) - 43.2933) * 1000 if (MenLeanbodymass * 2.2) > proteinAmount["PA"]: notification1 = True return render_template('account.html', title='Account', form=form, notification1=notification1)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): current_user.username = form.username.data db.session.commit() flash('Your account has been updated!', 'alert-success') return redirect(url_for('users.account')) elif request.method == 'GET': form.username.data = current_user.username return render_template('account/account.html', title='Account', form=form)
def profile(): form = UpdateAccountForm() if form.validate_on_submit(): session = db_session.create_session() if form.email.data != current_user.email: if session.query(User).filter( User.email == form.email.data).first(): flash('Этот email уже занят', 'danger') icons_file = url_for('static', filename='/images/profile_pics/' + current_user.image_file) logo = url_for('static', filename='images/logo.png') return render_template('profile.html', title='Профиль', icons_file=icons_file, form=form, logo=logo) if form.username.data != current_user.username: if session.query(User).filter( User.username == form.username.data).first(): flash('Это имя уже занято', 'danger') icons_file = url_for('static', filename='/images/profile_pics/' + current_user.image_file) logo = url_for('static', filename='images/logo.png') return render_template('profile.html', title='Профиль', icons_file=icons_file, form=form, logo=logo) if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image_file = picture_file current_user.name = form.name.data current_user.surname = form.surname.data current_user.username = form.username.data current_user.email = form.email.data session.add(current_user) session.commit() flash('Аккаунт успешно изменен', 'success') return redirect(url_for('profile')) elif request.method == 'GET': form.name.data = current_user.name form.surname.data = current_user.surname form.username.data = current_user.username form.email.data = current_user.email icons_file = url_for('static', filename='/images/profile_pics/' + current_user.image_file) logo = url_for('static', filename='images/logo.png') return render_template('profile.html', title='Профиль', icons_file=icons_file, form=form, logo=logo)
def account(): """ View function for the account screen. This page is where you can update account information. :return: HTML template or redirect """ form = UpdateAccountForm(grade=current_user.grade, state=current_user.state) if form.validate_on_submit(): update_account_handler(form) return redirect('/account') return render_template('account.html', form=form)
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.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(): post = Post(q1=form.q1.data, q2=form.q2.data, q3=form.q3.data, q4=form.q4.data, author=current_user) db.session.add(post) db.session.commit() return redirect(url_for('home')) return render_template('account.html', title='Account', form=form)
def account(): form = UpdateAccountForm() form1 = NewPostForm() if form.validate_on_submit(): 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', form=form, form1=form1)
def account(): form = UpdateAccountForm() db = current_app.config["db"] user_id = db.get_user_id(current_user.username) pp = url_for('static', filename='profile_pics/' + current_user.profile_pic) #image_file = url_for('static', filename='profile_pics/' + current_user.profile_pic) if form.validate_on_submit(): tmp = get_user(current_user.username) password = form.password.data if bcrypt.check_password_hash(tmp.password, password): temp = User(username=form.username.data,password=tmp.password,email=form.email.data, phone=form.password.data, profile_pic=current_user.profile_pic) if form.picture.data: picture_file = save_picture(form.picture.data) temp.profile_pic = picture_file if form.phone.data: temp.phone = form.phone.data db.update_user(temp,user_id) #flash('Your account has been update!', 'success') return redirect(url_for('account')) else: return ("Please enter correct password") elif request.method == 'GET': form.username.data = current_user.username form.password.data = current_user.password form.phone.data = current_user.phone form.email.data = current_user.email #######yukarısı update kısmı post_list = db.bring_users_post(current_user.username) posts = [] for item in post_list: #user,item,date #user = db.get_username_from_id(item[1]) user = current_user.username item_name = db.get_item_info(item[2])[2] item_description = db.get_item_info(item[2])[3] item_image = db.get_item_info(item[2])[4] image_file = url_for('static', filename='profile_pics/' + item_image) tempItem = Item(title=item_name,description=item_description,category="") tempItem.image = image_file date = item[3] temp = Post(tempItem,user,date) temp.key = item[0] #init key posts.append(temp) return render_template('account.html', posts=posts, form=form, img = pp)
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 login(): form = LoginForm() if 'loggedin' in session: form = UpdateAccountForm() cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor) cursor.execute(loginMySQL.format(session['id'])) account = cursor.fetchone() # Show the profile page with account info form.email.data = account['email'] form.firstname.data = account['first_name'] return render_template('account.html', title='Account', form=form) if form.validate_on_submit(): user_email = form.email.data user_password = form.password.data cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor) cursor.execute(loginMySQL2.format(user_email, user_password)) account = cursor.fetchone() print(account) if account: session['loggedin'] = True session['id'] = account['id'] session['first_name'] = account['first_name'] flash('Logged in successfully!') # return 'Logged in successfully!' return redirect(url_for('account')) return render_template('login.html', title='Login', form=form)
def account(): form = UpdateAccountForm() if request.method == "POST": if form.validate_on_submit(): hash = generate_password_hash(form.password.data) user = User.query.filter_by(username=current_user.username).first() user.password = hash current_app.db.session.commit() flash(f"Account password updated for user {current_user.username}", "success") return redirect(url_for("warden.warden_page")) flash("Password Change Failed. Something went wrong. Try Again.", "danger") return render_template("warden/account.html", title="Account", form=form, current_app=current_app)
def editprofile(): form = UpdateAccountForm() form2 = LocationForm() if form.validate_on_submit(): current_user.fname = form.fname.data current_user.lname = form.lname.data current_user.email = form.email.data current_user.phone = form.phone.data db.session.commit() flash(f'Personal Details Successfully Updated', 'success') return redirect(url_for('editprofile')) elif request.method == 'GET': form.fname.data = current_user.fname form.lname.data = current_user.lname form.email.data = current_user.email form.phone.data = current_user.phone image_file = url_for('static', filename='images/users/' + current_user.image_file) return render_template('Edit Profile.html', title='Account', image_file=image_file, form=form, form2=form2)
def account(): updform = UpdateAccountForm() db_session = db.getSession(engine) if updform.validate_on_submit(): #current_user.username = updform.username.data user = current_user user.username = updform.username.data user.email = updform.email.data db_session.add(user) db_session.commit() flash('Your account has been updated2!', 'success') return redirect(url_for('account')) elif request.method == 'GET': updform.username.data = current_user.username updform.email.data = current_user.email return render_template('account.html', title='Account', form=updform)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): username_already_in_db = User.query.filter_by( username=form.username.data).first() email_already_in_db = User.query.filter_by( email=form.email.data).first() if username_already_in_db or email_already_in_db: flash(f'Credentials already in use.', 'danger') return redirect(url_for('account')) else: update_username_email_on_user_table(form, current_user) 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(current_user.username) if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image = picture_file current_user.username = form.username.data current_user.email = form.email.data current_user.about_me = form.about_me.data db.session.commit() flash("Data successfully updated.", "success") return redirect(url_for('account')) elif request.method == "GET": form.username.data = current_user.username form.email.data = current_user.email form.about_me.data = current_user.about_me image_file = url_for('static', filename="profile_pics/" + current_user.image) return render_template("account.html", title="Account", image_file=image_file, form=form)
def account(): if not current_user.is_authenticated: return redirect(url_for('login')) form = UpdateAccountForm() # e1 = Event.query.filter(Event.title=='alpha').first() # print(e1.student) s1 = Student.query.filter( Student.username == current_user.username).first() events = s1.events.all() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image_file = picture_file db.session.commit() current_user.username = form.username.data current_user.phone = form.phone.data current_user.birthday = form.birthday.data current_user.gender = form.gender.data db.session.commit() flash('Your account has Updated', 'info') return redirect(url_for('account')) elif request.method == 'GET': s1 = Student.query.filter( Student.username == current_user.username).first() form.username.data = s1.username form.phone.data = s1.phone form.birthday.data = s1.birthday form.gender.data = s1.gender rands = sample(range(1, 6), 3) event_count = s1.events.count() rands.append(event_count) image_file = url_for('static', filename='images/' + current_user.image_file) return render_template('account.html', events=events, title='Account', form=form, image_file=image_file, sidebar=True, make=rands)
def update_account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data) update_picture = db.execute( "UPDATE user SET image_file = :image_file WHERE user_id = :user_id", user_id=int(session.get("user_id")), image_file=picture_file) # Update information in "user" table update_user = db.execute( "UPDATE user SET firstName = :firstname, lastName = :lastname, email = :email WHERE user_id = :user_id", user_id=int(session.get("user_id")), firstname=form.firstname.data, lastname=form.lastname.data, email=form.email.data) # flash message flash('Account info updated successfully!', 'success') else: flash("Sorry, we're unable to update your information.", 'danger') return redirect("/account_settings")
def account(): form = UpdateAccountForm() if form.validate_on_submit(): current_user.name = form.name.data current_user.password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') current_user.weight = form.weight.data current_user.city = form.city.data current_user.interest = form.interest.data current_user.languages = form.languages.data current_user.birthday = form.birthday.data db.session.commit() #'Your account has been updated!', 'success' return redirect(url_for('account')) elif request.method == 'GET': form.name.data = current_user.name form.password.data = current_user.password current_user.weight = form.weight.data current_user.city = form.city.data current_user.birthday = form.birthday.data #image_file = url_for('static', filename='profile_pics/' + current_user.image_file) # I couldnt use it return render_template('account.html', title='Account',form=form)
def profile(): formpage = UpdateAccountForm() if formpage.validate_on_submit(): if formpage.picture.data: # save profile picture picture_file = save_picture(formpage.picture.data) current_user.image_file = picture_file current_user.name = formpage.name.data current_user.email = formpage.email.data current_user.phone = formpage.phone.data db.session.commit() flash('Your account has been updated!', 'success') return redirect(url_for('profile')) elif request.method == 'GET': formpage.name.data = current_user.name formpage.email.data = current_user.email formpage.phone.data = current_user.phone image_file = url_for('static', filename='profile_pics/' + current_user.image_file) return render_template('profile.html', title='Profile', image_file=image_file, formpage=formpage)
def account(): form = UpdateAccountForm() if form.validate_on_submit(): if form.picture.data: picture_file = upload_picture(form.picture.data) current_user.image_file = picture_file current_user.email = form.email.data db.session.commit() flash('Your account has been updated', 'success') return redirect( url_for('account') ) # so the get request will superceed another post request???? elif request.method == 'GET': #form.username.data = current_user.username - taken out of form requirements form.email.data = current_user.email # https://www.youtube.com/watch?v=803Ei2Sq-Zs&list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH&index=7 image_file = S3_LOCATION + current_user.image_file return render_template( 'admin/account.html', title='Account', image_file=image_file, form=form) # form=form now form appears on account page
def account_info(): form = UpdateAccountForm() if form.validate_on_submit(): if form.profile_pic.data: profile_pic_file = save_picture(form.profile_pic.data, 125, 'profile_pics') current_user.profile_pic = profile_pic_file mongodb_query.profile_pic_update(current_user.username, current_user.profile_pic) # kostyl iz-za mongodb current_user.name = form.name.data current_user.surname = form.surname.data current_user.phone_number = form.phone_number.data if mongodb_query.user_update(current_user.username, current_user.name, current_user.surname, current_user.phone_number): flash('Your data has been updated!', 'success') return redirect(url_for('account_info')) else: flash('Something went wrong!', 'warning') return redirect(url_for('account_info')) elif request.method == 'GET': form.name.data = current_user.name form.surname.data = current_user.surname form.phone_number.data = current_user.phone_number avatar_img = url_for('static', filename='content/profile_pics/' + current_user.profile_pic) return render_template('account_info.html', title='Account info', 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.execute("UPDATE users SET username=:username WHERE id=:id", { "id": current_user.id, "username": current_user.username }) db.execute("UPDATE users SET email=:email WHERE id=:id", { "id": current_user.id, "email": current_user.email }) db.execute("UPDATE users SET image_file=:image_file WHERE id=:id", { "id": current_user.id, "image_file": current_user.image_file }) db.commit() flash('Your account has been updated!', category='success') return redirect(url_for('account'), code=302, Response=None) 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(): id = request.args['id'] db = DB() get_user = db.GetByID(id) form = UpdateAccountForm() if form.validate_on_submit(): db.UpdateAll(id, form.username.data, form.email.data, form.first_name.data, form.last_name.data, form.dob.data, form.address.data, form.city.data, form.state.data, form.phone_no.data) flash('Account Updated Successfully', 'success') return redirect(url_for('account', id=id)) elif request.method == 'GET': form.username.data = get_user[1] form.email.data = get_user[3] form.first_name.data = get_user[4] form.last_name.data = get_user[5] form.dob.data = get_user[6] form.address.data = get_user[7] form.city.data = get_user[8] form.state.data = get_user[9] form.phone_no.data = get_user[10] return render_template('account.html', title='Account', data=get_user, form=form)
def index(): form = UpdateAccountForm() session = db_session.create_session() characters = session.query(Сharacter).all() news = session.query(News).all() image = url_for('static', filename='images/') bg = url_for('static', filename='images/bg/site-background.jpg') mini = url_for('static', filename='images/mini_jett.png') return render_template('index.html', characters=characters, image=image, news=news, bg=bg, mini=mini, form=form)
def get_account(): # get current user_id current_user_id = int(session.get("user_id")) # Query 'user' database for all information of current user using lookup user = db.execute("SELECT * FROM user WHERE user_id = :user_id", user_id=current_user_id) image_file = url_for('static', filename='img/' + user[0]["image_file"]) # define form form_adex = AddExpenseForm() form_adin = AddIncomeForm() form_ingo = SetIncomeGoalsForm() form_bud = PlanBudgetsForm() form_pw = ResetPasswordForm() form_made = ManageDebtForm() form = UpdateAccountForm() form.firstname.data = user[0]["firstName"] form.lastname.data = user[0]["lastName"] form.email.data = user[0]["email"] """ PAYMENTS TOWARDS DEBT """ # query 'debts' table for category & description of all debts all_debts = db.execute( "SELECT debt_id, (category || ' (' || description || ')') AS choice_description FROM debts WHERE user_id = :user_id", user_id=current_user_id) form_adde = AddDebtPaymentForm() #passing group_list to the form form_adde.debt.choices = [(i['debt_id'], i['choice_description']) for i in all_debts] return render_template("account_settings.html", title='Account Settings', user=user, image_file=image_file, form=form, form_adex=form_adex, form_adin=form_adin, form_pw=form_pw, form_ingo=form_ingo, form_bud=form_bud, form_made=form_made, form_adde=form_adde)