def role(uid): usr = User.query.filter_by(id=uid).first() if usr is not None: form = RoleChangeForm(request.form) form.role.choices = [(r.name, r.description) for r in Role] if form.validate_on_submit(): # Update role usr.role = Role.from_string(form.role.data) g.db.commit() return redirect(url_for('.users')) form.role.data = usr.role.name return {'form': form, 'view_user': usr} abort(404)
def role(uid): usr = User.query.filter_by(id=uid).first() if usr is not None: form = RoleChangeForm(request.form) form.role.choices = [(r.name, r.description) for r in Role] if form.validate_on_submit(): # Update role usr.role = Role.from_string(form.role.data) g.db.commit() return redirect(url_for('.users')) form.role.data = usr.role.name return { 'form': form, 'view_user': usr } abort(404)
def role(uid): """ View and change user's role. :param uid: id of the user :type uid: int :return: role form and user view if valid response, appropriate error otherwise :rtype: dynamic """ usr = User.query.filter_by(id=uid).first() if usr is not None: form = RoleChangeForm(request.form) form.role.choices = [(r.name, r.description) for r in Role] if form.validate_on_submit(): usr.role = Role.from_string(form.role.data) g.db.commit() return redirect(url_for('.users')) form.role.data = usr.role.name return {'form': form, 'view_user': usr} g.log.debug(f'user with id: {uid} not found!') abort(404)