mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 10:34:17 +00:00
Change edit user form name
This commit is contained in:
parent
5fd9711da9
commit
fc560933bc
@ -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
|
||||
|
@ -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)
|
||||
|
@ -11,45 +11,45 @@
|
||||
<div class="card">
|
||||
<form method="POST">
|
||||
<div class="card-content">
|
||||
{{ form.hidden_tag() }}
|
||||
{{ edit_user_form.hidden_tag() }}
|
||||
<div class="input-field ">
|
||||
<i class="material-icons prefix">account_circle</i>
|
||||
{{ 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 %}
|
||||
<span class="helper-text red-text">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">mail</i>
|
||||
{{ 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 %}
|
||||
<span class="helper-text red-text">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">swap_vert</i>
|
||||
{{ 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 %}
|
||||
<span class="helper-text red-text">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="switch">
|
||||
<i class="material-icons prefix">check</i>
|
||||
<label class="active" for="{{form.confirmed.name}}">
|
||||
<label class="active" for="{{ edit_user_form.confirmed.name }}">
|
||||
Confirmed status:
|
||||
Off
|
||||
{% if form.confirmed.data == True %}
|
||||
<input type="checkbox" id="{{ form.confirmed.name }}" name="{{ form.confirmed.name }}" checked="checked">
|
||||
{% if edit_user_form.confirmed.data == True %}
|
||||
<input type="checkbox" id="{{ edit_user_form.confirmed.name }}" name="{{ edit_user_form.confirmed.name }}" checked="checked">
|
||||
{% else %}
|
||||
<input type="checkbox" id="{{ form.confirmed.name }}" name="{{ form.confirmed.name }}">
|
||||
<input type="checkbox" id="{{ edit_user_form.confirmed.name }}" name="{{ edit_user_form.confirmed.name }}">
|
||||
{% endif %}
|
||||
<span class="lever"></span>
|
||||
On
|
||||
</label>
|
||||
{% for error in form.confirmed.errors %}
|
||||
{% for error in edit_user_form.confirmed.errors %}
|
||||
<span class="helper-text red-text">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user