コード例 #1
0
def modify_user():
    form = EditUserForm(request.form)

    if form.validate_on_submit():
        user = User.query.filter_by(id=form.id.data).first()

        if not user:
            flash('User does not exist.', 'error')

            return redirect(url_for("main_page_module.all_users"))

        else:
            user.name = form.name.data
            user.email = form.email.data
            if form.password.data != "":
                user.set_password(form.password.data)

            db.session.commit()

        flash('User successfully Eddited!', 'success')

        return redirect(
            url_for("main_page_module.view_user",
                    user_id=form.id.data,
                    form=form))

    flash('Invalid data.', 'error')

    return redirect(url_for("main_page_module.all_users"))
コード例 #2
0
def view_user(user_id):
    user = User.query.filter_by(id=user_id).first()

    if not user:
        flash('User does not exist.', 'error')

        return redirect(url_for("main_page_module.all_users"))

    form = EditUserForm()
    form.process(obj=user)

    return render_template("main_page_module/admin/view_user.html",
                           form=form,
                           user=user)