Esempio n. 1
0
def user_add():
    form = UserForm()
    if form.validate_on_submit():
        try:
            user = User(form.username.data, form.password.data,
                        form.is_valid.data)
            db.session.add(user)
            db.session.commit()
            flash("成功添加管理员!")
            return redirect(url_for('.user_index'))
        except:
            flash("添加管理员失败!", category="error")

    return render_template('/admin/user/add.html', form=form)
Esempio n. 2
0
def user_edit(pk):
    user = User.query.get(pk)
    if user is None:
        return redirect(url_for('.user_index'))
    form = UserForm(obj=user)
    if form.validate_on_submit():
        try:
            user.username = form.username.data
            user.passwd = generate_password_hash(form.password.data)
            user.is_valid = form.is_valid.data
            db.session.add(user)
            db.session.commit()
            flash("管理员编辑成功!")
            return redirect(url_for('.user_index'))
        except:
            flash("管理员编辑失败!", category="error")

    return render_template('/admin/user/edit.html', form=form)
Esempio n. 3
0
def user_add():
    form = UserForm()

    # 美化版打印 pprint
    # pprint.pprint(form.username.__dict__)

    # 判断表单验证是否通过
    if form.validate_on_submit():
        # print(form.username.data)
        try:
            user = User(form.username.data, form.password.data,
                        form.is_valid.data)

            # print(form.is_valid.data)
            db.session.add(user)
            db.session.commit()
            flash("成功添加管理员!")
            return redirect(url_for(".user_index"))
        except:
            flash("添加管理员失败!", category="error")
    return render_template("admin/user/add.html", form=form)