def user_profile_page(): form = UserProfileForm(request.form, current_user) if request.method == 'POST' and form.validate(): form.populate_obj(current_user) db.session.commit() return redirect(url_for('home_page')) return render_template('users/user_profile_page.html', form=form)
def user_profile_page(): # Initialize form form = UserProfileForm(request.form, current_user) # Process valid POST if request.method == 'POST' and form.validate(): # Copy form fields to user_profile fields form.populate_obj(current_user) # Save user_profile db.session.commit() # Redirect to home page return redirect(url_for('home_page')) # Process GET or invalid POST return render_template('users/user_profile_page.html', form=form)
def user_profile(): form = UserProfileForm() if form.is_submitted(): user = User.query.filter_by(id=session.get('user_id')).first() user.fullname = form.fullname.data user.address = form.address.data user.phone_number = form.phone_number.data db.session.commit() g.user = user form.email.data = g.user.email form.username.data = g.user.username form.fullname.data = g.user.fullname form.address.data = g.user.address form.phone_number.data = g.user.phone_number #form.birthdate.data = g.user.birthdate return render_template("users/user_profile.html", form=form)
def profile(): user = User.query.get(current_user.id) if request.method == 'GET': form = UserProfileForm(obj=user) initialise_profile_form(form) if request.method == 'POST': form = UserProfileForm() initialise_profile_form(form) form.mobile_phone.data = form.mobile_phone.data.strip() form.email.data = form.email.data.strip() if form.validate_on_submit(): all_ok = True if form.mobile_phone.data.strip() != "": duplicate_phone_user = User.query.filter( and_(User.mobile_phone == form.mobile_phone.data, User.id != current_user.id))\ .first() if duplicate_phone_user is not None: flash_message = "That phone number is already used by another user." all_ok = False if form.email.data.strip() is not None: duplicate_email_user = User.query.filter( and_(User.email == form.email.data, User.id != current_user.id))\ .first() if duplicate_email_user is not None: flash_message = "That e-mail is already used by another user." all_ok = False if all_ok: form.populate_obj(user) db.session.commit() flash('You profile has been saved.', 'info') if user.login_count == 1: message_id = create_welcome_message(current_user.id) return redirect( url_for('messages.view_messages', message_type=1, id=current_user.id)) return render_template('profile.html', form=form) flash(flash_message, 'error') return render_template('profile.html', form=form)