mirror of
https://github.com/Xevion/runnerspace.git
synced 2025-12-07 05:16:22 -06:00
Fix profile editing form not coming pre-populated with data
Not sure why Form.populate_obj() wasn't working - looking at the source and the description as well as relevant StackOverflow answers, that method would apparently work just fine. Looking again, Form.process() was recommended instead. Also, I finally changed PyCharm to show me proper commit message standards - so, be happy that things will look nice now. :)
This commit is contained in:
17
routes.py
17
routes.py
@@ -73,17 +73,18 @@ def edit_user(username: str):
|
|||||||
user = db.session.query(User).filter_by(username=username).first_or_404()
|
user = db.session.query(User).filter_by(username=username).first_or_404()
|
||||||
form = EditProfileForm(request.form)
|
form = EditProfileForm(request.form)
|
||||||
|
|
||||||
if request.method == 'POST':
|
# Check that a form was submitted
|
||||||
if form.validate():
|
if form.validate_on_submit():
|
||||||
if current_user.is_admin or current_user == user:
|
# Check that the user submitting the form is allowed to do this
|
||||||
user.about_me = form.about_me.data
|
if current_user.is_admin or current_user == user:
|
||||||
user.name = form.name.data
|
user.about_me = form.about_me.data
|
||||||
|
user.name = form.name.data
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(url_for('main.view_user', username=username))
|
return redirect(url_for('main.view_user', username=username))
|
||||||
return render_template('pages/user_edit.html', form=form)
|
return render_template('pages/user_edit.html', form=form)
|
||||||
|
|
||||||
form.populate_obj(user)
|
form.process(obj=user)
|
||||||
return render_template('pages/user_edit.html', form=form)
|
return render_template('pages/user_edit.html', form=form)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user