Exemplo n.º 1
0
def auth_add():
    form = AuthFrom()
    if form.validate_on_submit():
        data = form.data
        auth = Auth(name=data["name"], url=data["url"])
        db.session.add(auth)
        db.session.commit()
        flash("添加权限成功!", "ok")
        redirect(url_for("admin.auth_add"))
    return render_template("admin/auth_add.html", form=form)
Exemplo n.º 2
0
def auth_edit(id=None):
    form = AuthFrom()
    auth = Auth.query.get_or_404(id)
    if form.validate_on_submit():
        data = form.data
        auth.url = data["url"]
        auth.name = data["name"]
        db.session.add(auth)
        db.session.commit()  # 提交事务
        flash("修改权限成功!", "ok")
        redirect(url_for("admin.auth_edit", id=id))
    return render_template("admin/auth_edit.html", form=form, auth=auth)
Exemplo n.º 3
0
def auth_list(page=None):
    form = AuthFrom()
    data = form.data
    if page is None:
        page = 1
    page_data = Auth.query.order_by(Auth.addtime.desc()).paginate(page=page,
                                                                  per_page=10)
    if form.validate_on_submit():
        if form.submit.data:
            auth_add(data)
    return render_template("admin/auth_list.html",
                           page_data=page_data,
                           form=form)
Exemplo n.º 4
0
def auth_add():
    form = AuthFrom()
    if form.validate_on_submit():
        data = form.data
        if Auth.query.filter_by(url=data['url']).count() == 1:
            flash('权限链接地址已存在!', category='err')
            return redirect(url_for('admin.auth_add'))
        if Auth.query.filter_by(name=data['name']).count() == 1:
            flash('权限名称已存在!', category='err')
            return redirect(url_for('admin.auth_add'))
        auth = Auth(name=data["name"], url=data["url"])
        db.session.add(auth)
        db.session.commit()
        flash("添加权限成功!", "ok")
        oplog = Oplog(admin_id=session["admin_id"],
                      ip=request.remote_addr,
                      reason="添加权限%s" % data['name'])
        db.session.add(oplog)
        db.session.commit()
    return render_template("admin/auth_add.html", form=form)
Exemplo n.º 5
0
def auth_edit(id=None):
    form = AuthFrom()
    auth = Auth.query.get_or_404(id)
    if form.validate_on_submit():
        data = form.data
        if Auth.query.filter_by(url=data['url']).count() == 1:
            flash('权限链接地址已存在!', category='err')
            return redirect(url_for('admin.auth_edit', id=id))
        if Auth.query.filter_by(name=data['name']).count() == 1:
            flash('权限名称已存在!', category='err')
            return redirect(url_for('admin.auth_edit', id=id))
        auth.url = data['url']
        auth.name = data["name"]
        db.session.add(auth)
        db.session.commit()
        flash("修改权限成功!", "ok")
        oplog = Oplog(admin_id=session["admin_id"],
                      ip=request.remote_addr,
                      reason="修改权限%s" % data['name'])
        db.session.add(oplog)
        db.session.commit()
        return redirect(url_for('admin.auth_list', page=1))
    return render_template("admin/auth_edit.html", form=form, auth=auth)