From fc560933bcac8130243f53e75dcd4aed75f02405 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Fri, 15 Nov 2019 14:01:36 +0100 Subject: [PATCH] Change edit user form name --- app/admin/forms.py | 23 +++++++------------- app/admin/views.py | 21 ++++++++----------- app/templates/admin/edit_user.html.j2 | 30 +++++++++++++-------------- 3 files changed, 32 insertions(+), 42 deletions(-) diff --git a/app/admin/forms.py b/app/admin/forms.py index 0bd755dc..0eea3b94 100644 --- a/app/admin/forms.py +++ b/app/admin/forms.py @@ -5,29 +5,22 @@ from wtforms import (BooleanField, SelectField, StringField, SubmitField, from wtforms.validators import DataRequired, Email, Length, Regexp -class EditProfileAdminForm(FlaskForm): +class EditUserForm(FlaskForm): email = StringField('Email', validators=[DataRequired(), Length(1, 64), Email()]) - username = StringField( - 'Username', - validators=[ - DataRequired(), - Length(1, 64), - Regexp( - '^[A-Za-z][A-Za-z0-9_.]*$', - 0, - 'Usernames must have only letters, numbers, dots or ' - 'underscores' - ) - ] - ) + username = StringField('Username', + validators=[DataRequired(), Length(1, 64), + Regexp('^[A-Za-z][A-Za-z0-9_.]*$', 0, + 'Usernames must have only ' + 'letters, numbers, dots or ' + 'underscores')]) confirmed = BooleanField('Confirmed') role = SelectField('Role', coerce=int) name = StringField('Real name', validators=[Length(0, 64)]) submit = SubmitField('Update Profile') def __init__(self, user, *args, **kwargs): - super(EditProfileAdminForm, self).__init__(*args, **kwargs) + super(EditUserForm, self).__init__(*args, **kwargs) self.role.choices = [(role.id, role.name) for role in Role.query.order_by(Role.name).all()] self.user = user diff --git a/app/admin/views.py b/app/admin/views.py index 0f182c38..ea4936c6 100644 --- a/app/admin/views.py +++ b/app/admin/views.py @@ -6,7 +6,7 @@ from flask import current_app, flash, redirect, render_template, url_for from flask_login import login_required from threading import Thread from . import admin -from .forms import EditProfileAdminForm +from .forms import EditUserForm from .tables import AdminUserItem, AdminUserTable @@ -51,19 +51,16 @@ def delete_user(user_id): @admin_required def edit_user(user_id): user = User.query.get_or_404(user_id) - form = EditProfileAdminForm(user=user) - if form.validate_on_submit(): - user.email = form.email.data - user.username = form.username.data - user.confirmed = form.confirmed.data - user.role = Role.query.get(form.role.data) + edit_user_form = EditUserForm(user=user) + if edit_user_form.validate_on_submit(): + user.email = edit_user_form.email.data + user.username = edit_user_form.username.data + user.confirmed = edit_user_form.confirmed.data + user.role = Role.query.get(edit_user_form.role.data) db.session.add(user) db.session.commit() flash('The profile has been updated.') return redirect(url_for('admin.edit_user', user_id=user.id)) - form.email.data = user.email - form.username.data = user.username - form.confirmed.data = user.confirmed - form.role.data = user.role_id - return render_template('admin/edit_user.html.j2', form=form, + return render_template('admin/edit_user.html.j2', + edit_user_form=edit_user_form, title='Administration: Edit user', user=user) diff --git a/app/templates/admin/edit_user.html.j2 b/app/templates/admin/edit_user.html.j2 index 0686d310..055882a5 100644 --- a/app/templates/admin/edit_user.html.j2 +++ b/app/templates/admin/edit_user.html.j2 @@ -11,45 +11,45 @@
- {{ form.hidden_tag() }} + {{ edit_user_form.hidden_tag() }}
account_circle - {{ form.username() }} - {{ form.username.label }} - {% for error in form.username.errors %} + {{ edit_user_form.username() }} + {{ edit_user_form.username.label }} + {% for error in edit_user_form.username.errors %} {{ error }} {% endfor %}
mail - {{ form.email() }} - {{ form.email.label }} - {% for error in form.email.errors %} + {{ edit_user_form.email() }} + {{ edit_user_form.email.label }} + {% for error in edit_user_form.email.errors %} {{ error }} {% endfor %}
swap_vert - {{ form.role() }} - {{ form.role.label }} - {% for error in form.role.errors %} + {{ edit_user_form.role() }} + {{ edit_user_form.role.label }} + {% for error in edit_user_form.role.errors %} {{ error }} {% endfor %}
check -