mirror of
https://github.com/Xevion/runnerspace.git
synced 2025-12-06 23:16:13 -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()
|
||||
form = EditProfileForm(request.form)
|
||||
|
||||
if request.method == 'POST':
|
||||
if form.validate():
|
||||
if current_user.is_admin or current_user == user:
|
||||
user.about_me = form.about_me.data
|
||||
user.name = form.name.data
|
||||
# Check that a form was submitted
|
||||
if form.validate_on_submit():
|
||||
# Check that the user submitting the form is allowed to do this
|
||||
if current_user.is_admin or current_user == user:
|
||||
user.about_me = form.about_me.data
|
||||
user.name = form.name.data
|
||||
|
||||
db.session.commit()
|
||||
return redirect(url_for('main.view_user', username=username))
|
||||
db.session.commit()
|
||||
return redirect(url_for('main.view_user', username=username))
|
||||
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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user